openai-streams icon indicating copy to clipboard operation
openai-streams copied to clipboard

How to support `continue generating` response

Open shekharx opened this issue 2 years ago • 0 comments

I am using openai-stream library to build a chat application. We need support continue generating response feature like the one we have in ChatGPT. Looking at the code of the library I understand that OpenAIError is thrown when finish_reason is equal to length https://github.com/SpellcraftAI/openai-streams/blob/canary/src/lib/streaming/streams.ts#L80.

In my code I don't get handle to this error in the catch block. The console.error line is never called. The code looks like as shown below

try {
  const stream = await OpenAI("chat", {
    model: "gpt-3.5-turbo",
    messages: [
      {
        role: "system",
        content: DEFAULT_SYSTEM_PROMPT,
      },
      ...messagesToSend,
    ],
    max_tokens: 1000,
    temperature: DEFAULT_TEMPERATURE,
  });

  return new Response(stream);

} catch (e) {
  console.error("Error: ", e)
}

Can you guide me how to handle errors?

shekharx avatar Aug 02 '23 06:08 shekharx