Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception Handling for streamObject toTextStreamResponse #4617

Closed
DavidMelnychuk opened this issue Jan 31, 2025 · 1 comment
Closed

Exception Handling for streamObject toTextStreamResponse #4617

DavidMelnychuk opened this issue Jan 31, 2025 · 1 comment
Labels
ai/core enhancement New feature or request

Comments

@DavidMelnychuk
Copy link

Feature Description

Following the object generation docs, and setting up streamObject on a bun server:

  const context = await req.json();

  const model = azure('azure-gpt-4o-mini');
  const result = streamObject({
    model,
    schema: notificationSchema,
    prompt:
      `Generate 3 notifications for a messages app in this context:` + context,
  });

  return result.toTextStreamResponse();

If the stream encounters an error, then it throws an unhandledRejection and crashes the entire server. For example if it hits an API Call error like content filtering:

 error: unhandledRejection: The response was filtered due to the prompt triggering Azure OpenAI's content management policy. Please modify your prompt and retry.
AI_APICallError: The response was filtered due to the prompt triggering Azure OpenAI's content management policy. Please modify your prompt and retry.

Not sure if possible with streams, but better exception handling such that errors gets caught in a try/catch or we can provide an onError callback would be greatly appreciated.

Use Cases

No response

Additional context

No response

@DavidMelnychuk DavidMelnychuk added the enhancement New feature or request label Jan 31, 2025
@lgrammel
Copy link
Collaborator

Fixed by #4807

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ai/core enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants