ChatGPT icon indicating copy to clipboard operation
ChatGPT copied to clipboard

Response stream format may be wrong for some reason

Open dealdot opened this issue 2 months ago • 4 comments

4061712559594_ pic 4051712558833_ pic

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: 4071712560257_ pic

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:

4081712560404_ pic

dealdot avatar Apr 08 '24 07:04 dealdot

@dealdot Please use Postman to verify, as it will confirm if two pieces of data are provided within a single chunk.

PawanOsman avatar Apr 08 '24 07:04 PawanOsman

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

4121712576612_ pic

What is the possible issue may be here ? thanks

dealdot avatar Apr 08 '24 11:04 dealdot

try to use axios instead of fetch

PawanOsman avatar Apr 08 '24 16:04 PawanOsman

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"?

dealdot avatar Apr 09 '24 03:04 dealdot