-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding messages to useChat without streaming #415
Comments
Unsure if this fully fits your use case, but you could potentially use the setMessages() function from the Chat Helpers to update the local message state without triggering an API call to the server? However, depending on how you're handling your API endpoint the message may be sent/received by the server on the next request. Otherwise you could just handle your specific need when you render the local messages object out to the screen (checking for your flag and adding an additional message/piece of content in the UI) |
If you ever need to intercept the stream or send a direct message, you need to create a new stream to return. For example...
Even though streaming looks nice - development is absolutely more difficult. Parsing JSON on completion is much easier than trying to parse and manipulate streams.
|
In my chatbot, I'm using the
useChat
hook to display streaming messages.While this is how I want (stream) most of the time, I have a certain use-case of manipulating the openai response message before it gets sent to the frontend. In this scenario, I don't want the streaming, but direct adding of the message
It's a Next.js app. Here's my setup:
Frontend:
API (
/api/chat
)I'm returning the stream with
StreamingTextResponse(stream)
.In a certain use-case (like if
body
object contains a flag), how can I send a message to messages inuseChat()
directly without streaming it?The text was updated successfully, but these errors were encountered: