feat(streams): add http error handling for openai
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
OpenAIStreamfunction 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.okto 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. Ifres.bodyis not null, it asynchronously extracts and decodes the response body. -
Propagating Detailed Error Messages: The function uses
controller.errorto propagate a detailed error message, providing more context on the nature of the error encountered. -
Documentation Updates: Updated JSDoc comments for the
OpenAIStreamfunction 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.
⚠️ 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
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 @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!
@shuding Is this mergeable? I am getting a stream error whenever a try to use a model different than text-davinci-003.