useChat / handleSubmit -> pass back data other than message? #328
Replies: 6 comments 12 replies
-
Hey @peepers-rick, we're actively working on supporting this use-case. You can accomplish this now by including your component data in the response headers or adding it to the stream with a custom delimiter (which is what we'll likely due for you in the future). https://markprompt.com/blog/hybrid-streaming-payloads has details |
Beta Was this translation helpful? Give feedback.
-
More working examples of handling links, content and images, and user feedback with functions and langchaim would be quite helpful. Parsing partial JSON and injecting additional data into streams is messy work. |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Hey! I've been trying to use |
Beta Was this translation helpful? Give feedback.
-
useChat / onResponse is failing when trying to access response headers sent by StreamingTextResponse. I'm able to get StreamingTextResponse to pass back headers no problem, but useChat (onResponse) and the code above by @karar-shah , specifically:
Isn't working. Console showing correct response headers. onResponse showing |
Beta Was this translation helpful? Give feedback.
-
@jadejamig I am little short on time try manually decoding the stream on the front end. Hopefully this will allow you to return more customized responses and based on the return response run stream decode or not run stream decode. 1. Quick solution:Return something in header and validate it before showing stream like: 2. If things are more complex:Then use custom code to decode the stream response and validate, may below code spark any idea for your scenario.
|
Beta Was this translation helpful? Give feedback.
-
Hi there,
I'm using the handleSubmit method from the useChat hook and then hitting my POST function at /api/chat, returning a StreamingTextResponse(OpenAIStream(gptResponse)). That seems to add to the messages array, which is great, but I want to pass along additional information that I can render in my app as well. I'd like to pass some JSON that I can render below the chat message as different content cards, similar to how a plugin on ChatGPT might render dynamic cards. It won't be part of the streaming response from the OpenAI API, so I need to be able to inject in onResponse or onFinish somehow?
Beta Was this translation helpful? Give feedback.
All reactions