ChatGPT
ChatGPT copied to clipboard
Response stream format may be wrong for some reason
When I using JSON.parse(chunk) it may throw error , when I debug I found that in some case, I got the following stream format:
This prints two json string in one chunk while others(mostly) just print one json string in one chunk, the latter format is what I want, as the image shows following:
@dealdot Please use Postman
to verify, as it will confirm if two pieces of data are provided within a single chunk.
Postman looks good, I use next.js for api query
const response = await fetch(`${process.env.BACKGROUND_API_BASE_URL}/api/chat-free`, {
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${(payload as any).token}`
},
method: "POST",
body: JSON.stringify(payload)
})
and then process:
const stream = new ReadableStream({
async start(controller) {
for await (const chunk of response.body as any) {
let decodeChunk = decoder.decode(chunk)
console.log('stream --:', decodeChunk)
controller.enqueue(encoder.encode(decodeChunk))
}
controller.close()
}
})
return stream
The log for decodeChunk looks like
What is the possible issue may be here ? thanks
try to use axios instead of fetch
Alright, I'll give it a shot. I'm curious, does the API Free Reverse Proxy support tracking? For instance, can it track using the conversation using request parameter like "parentMessageId"?