Skip to content

Parse Structured Streaming Responses with Metadata in useChat #4466

Discussion options

You must be logged in to vote

Will the python server be streaming invalid json until complete? If so, you'll have a hard time displaying a real-time ui streaming the content to the user as parsing the json will fail until the end the json is valid. In that scenario onFinish would be the right method to hook into (onResponse triggers on the first response from the server not when the stream ends)

You could also memo-ize and map the messages array and call JSON.parse on prior to rendering the message list. Assuming the content streams in, the JSON.parse will fail until it's valid json, so you'll want to try/catch and display a loading

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by devevignesh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants