Streaming Structured JSON strings with OpenAIStream / ReadableStream #210
Unanswered
moisestech
asked this question in
Help
Replies: 1 comment
-
Here is a ⚛️ public repo to replicate the scenario. I think there may have been changes in the Twitter Bio Generator Vercel Template, the updated repo is using:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
How would one go about streaming JSON stringified data by using
OpenAIStream
andReadableStream
?Why Stream Structure Data?
Streaming helps me resolve Vercel Timeout Code Limits that happen with regular Fetch Req/Resp.
Goal
Create structured data streams of valid JSON. Ex.
Progress so far
It was been tricky since the data may not be valid JSON. Sometimes the model forgets to returns a
{
bracket for example.After testing many times it is inconsistenly not sending the first bracket in the first stream payload. Sending an empty text string, yet it is not missing any other parts of the JSON.
{chunkValue: 'data: {"text":""}\n\ndata: {"text":" "}\n\n'}
Here is the full buffer when parsing the text key
Option 1) I've started looking into FrontEnd streaming libraries such as:
Option 2) Starting to look into Function Calls OpenAI API
Reference Code
OpenAIStream.ts
Thanks for any advice and guidance. Would love to resolve and make a solution that helps others in the community. Cheers.
Beta Was this translation helpful? Give feedback.
All reactions