# How would one go about streaming JSON stringified data by using `OpenAIStream` and `ReadableStream
Unanswered
Asiatic Lion posted this in #help-forum
Asiatic LionOP
## 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
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.
Attached below is the full buffer when parsing the text key.
### Option 1) I've started looking into FrontEnd streaming libraries such as:
1) [Clarinet](https://github.com/dscape/clarinet)
2) [Oboe](https://github.com/jimhigson/oboe.js/)
### Option 2) Starting to look into [Function Calls](https://platform.openai.com/docs/guides/gpt/function-calling) OpenAI API
- This could be the solution since I'm trying to stream structured data from the language mode.
---
### Reference Code
- You can reproduce by cloning the [Twitter Bio Generator Vercel Template](https://vercel.com/templates/next.js/twitter-bio) and changing the prompt to request JSON. If needed I can create a public repo and link to this discussion. ðŸ™
- [
Thanks for any advice and guidance. Would love to resolve and make a solution that helps others in the community. Cheers.
Here is the Vercel-Labs discussion for reference if this is a better place to continue the discussion. https://github.com/vercel-labs/ai/discussions/210
Streaming helps me resolve Vercel Timeout Code Limits that happen with regular Fetch Req/Resp.
## Goal
Create structured data streams of valid JSON. Ex.
{ id: "id1", name: "joe", location: "new york", age: 30 }---
## 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'}Attached below is the full buffer when parsing the text key.
### Option 1) I've started looking into FrontEnd streaming libraries such as:
1) [Clarinet](https://github.com/dscape/clarinet)
2) [Oboe](https://github.com/jimhigson/oboe.js/)
### Option 2) Starting to look into [Function Calls](https://platform.openai.com/docs/guides/gpt/function-calling) OpenAI API
- This could be the solution since I'm trying to stream structured data from the language mode.
---
### Reference Code
- You can reproduce by cloning the [Twitter Bio Generator Vercel Template](https://vercel.com/templates/next.js/twitter-bio) and changing the prompt to request JSON. If needed I can create a public repo and link to this discussion. ðŸ™
- [
OpenAIStream.ts](https://github.com/Nutlope/twitterbio/blob/main/utils/OpenAIStream.ts)Thanks for any advice and guidance. Would love to resolve and make a solution that helps others in the community. Cheers.
Here is the Vercel-Labs discussion for reference if this is a better place to continue the discussion. https://github.com/vercel-labs/ai/discussions/210
2 Replies
Asiatic LionOP
@Asiatic Lion ## **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.
{ id: "id1", name: "joe", location: "new york", age: 30 }
---
## **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'}`
Attached below is the full buffer when parsing the text key.
### Option 1) I've started looking into FrontEnd streaming libraries such as:
1) [Clarinet](https://github.com/dscape/clarinet)
2) [Oboe](https://github.com/jimhigson/oboe.js/)
### Option 2) Starting to look into [Function Calls](https://platform.openai.com/docs/guides/gpt/function-calling) OpenAI API
- This could be the solution since I'm trying to stream structured data from the language mode.
---
### **Reference Code**
- You can reproduce by cloning the [Twitter Bio Generator Vercel Template](https://vercel.com/templates/next.js/twitter-bio) and changing the prompt to request JSON. If needed I can create a public repo and link to this discussion. ðŸ™
- [`OpenAIStream.ts`](https://github.com/Nutlope/twitterbio/blob/main/utils/OpenAIStream.ts)
Thanks for any advice and guidance. Would love to resolve and make a solution that helps others in the community. Cheers.
Here is the Vercel-Labs discussion for reference if this is a better place to continue the discussion. https://github.com/vercel-labs/ai/discussions/210
European pilchard
I believe I may be trying to do something similar with function calls, I’m trying to get streaming to return a json that I can use to run a function. But I’m plagued with ReadableStream. prototype.pipeThrough cannot be used on a locked ReadableStream. I’m using openai-edge and vercel ai sdk