ai icon indicating copy to clipboard operation
ai copied to clipboard

render function error handling

Open steebchen opened this issue 2 months ago • 3 comments

Description

It looks like the render function doesn't support error handling. I tried wrapping the render function in a try/catch, but it doesn't catch any errors (specifically when an error is immediately returned, such as a context window length exceeded)/

Code example

I used this template: https://github.com/vercel/ai-chatbot

At this part:

return render({
  model: 'gpt-3.5-turbo',
  provider: openai,
  initial: <SpinnerMessage />,
  messages: [
    {
      role: 'system',
      content: `You are a helpful bot.`
    },
    ...aiState.get().messages.map((message: any) => ({
      role: message.role,
      content: message.content,
      name: message.name
    }))
  ]
})

This can result in this error being thrown

 ⨯ unhandledRejection: BadRequestError: 400 This model's maximum context length is 16385 tokens. However, your messages resulted in 21253 tokens. Please reduce the length of the messages.

and the UI just keeps showing this:

image

Additional context

No response

steebchen avatar Apr 15 '24 08:04 steebchen

Also experiencing this issue - would love some guidance here!

parthematics avatar Apr 15 '24 20:04 parthematics

Same, its obvious that the openAI library is throwing an error but there's no consistent way to catch it using this library it seems.

nateaxcell avatar Apr 16 '24 21:04 nateaxcell

Same here! Couldn't find any documentation on how this should be handled.

ghaemisr avatar Apr 16 '24 21:04 ghaemisr