ai icon indicating copy to clipboard operation
ai copied to clipboard

feat(streams): add http error handling for openai

Open 0x5844 opened this issue 2 years ago • 3 comments

This pull request addresses issue #144 and introduces an enhancement to the OpenAIStream function within the packages/core/streams/openai-stream.ts file. The enhancement entails the integration of conditional stream processing to manage non-2xx HTTP responses more efficiently, ensuring the synchronous nature of the function is maintained.

The key modifications in this pull request include:

  • Conditional Stream Processing: The OpenAIStream function now uses conditional stream processing based on the status code of the HTTP response. This enhances the function's capability to handle different response types with greater efficiency.

  • Evaluate Response Status: The function utilizes res.ok to determine if the response status code falls within the 2xx range, indicating a successful response.

  • Processing of Successful Responses: In the event of a successful response (2xx status code), the function continues with the standard stream processing.

  • Handling of Erroneous Responses: For non-2xx responses, the function creates a custom ReadableStream. If res.body is not null, it asynchronously extracts and decodes the response body.

  • Propagating Detailed Error Messages: The function uses controller.error to propagate a detailed error message, providing more context on the nature of the error encountered.

  • Documentation Updates: Updated JSDoc comments for the OpenAIStream function to reflect the new conditional stream processing approach, and provided additional information on its behavior and usage.

These modifications ensure that the OpenAIStream function remains synchronous while providing detailed and efficient error handling for non-2xx responses.

Please let me know if there are any additional changes or adjustments needed.

0x5844 avatar Jun 19 '23 14:06 0x5844

⚠️ No Changeset found

Latest commit: 3cf83b443765afa946cbc22f0531d853c44342c4

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

changeset-bot[bot] avatar Jun 19 '23 14:06 changeset-bot[bot]

Hey @sirlolcat just check in to see if you are able to make that change that applies this to all AIStreams? I can also do that part and get this shipped if you're busy! Asking because we're getting more issues regarding this.

shuding avatar Jun 22 '23 17:06 shuding

Hey @sirlolcat just check in to see if you are able to make that change that applies this to all AIStreams? I can also do that part and get this shipped if you're busy! Asking because we're getting more issues regarding this.

Hey there, my apologies for the late reply I got caught up in work. I'll address this today, you're more than welcome to proceed with it based on your POV. Let me know about it!

0x5844 avatar Jun 23 '23 07:06 0x5844

@shuding Is this mergeable? I am getting a stream error whenever a try to use a model different than text-davinci-003.

Christian-Schoenlein avatar Jun 28 '23 02:06 Christian-Schoenlein