Open AI Stream response has issue in chrome, it’s fetching the response at a single shot response

Raja Dileep Kumar 0 Reputation points
2024-06-17T13:39:45.9433333+00:00

try {

    setStreamLoading(true);

    setStreamComplete(false);

    fetch(API_URL, requestOptions)

        .then(response => {

            // eslint-disable-next-line no-undef

            const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();

            function read() {

                reader.read().then(({ done, value }) => {

                    if (done) {

                        console.log("Stream complete");

                        setStreamComplete(true)

                        return;

                    }

                    console.log(value, "asdsd")

                    if (value) {

                        setStreamChatResponse(value);

                    } else {

                        console.log('Error reading stream', value)

                    }

                    // Increment receivedResponses

                    read();

                }).catch(error => {

                    console.error("Error reading stream", error);

                    setStreamComplete(false)

                });

            }

            // Start reading response

            read();

        })

        .catch(error => {

            console.error("Fetch error", error);

            setStreamComplete(false)

        });

} catch (error) {

    console.error("Stream processing error:", error);

} finally {

    setStreamLoading(false);

    setStreamComplete(false);

}
Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
2,606 questions
{count} votes