-
-
Notifications
You must be signed in to change notification settings - Fork 334
Unify StreamError and OpenAIError #413
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
Unify StreamError and OpenAIError #413
Conversation
| /// Error on SSE streaming | ||
| #[error("stream failed: {0}")] | ||
| StreamError(String), | ||
| StreamError(StreamError), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Since you always map the inner eventsource error anyway, It would simplify the code quite a bit I think to wrap StreamError(EventSourceError) instead with #[from].
If I'm not mistaken, that would remove map_stream_error instead as we can use Into, remove the intermediate error, and avoid reading out the bytes of the response early.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't because we need to determine what OpenAIError is wrapped inside the EventSourceError::InvalidStatusCode and as a bonus we also map the EventSourceError::Transport to OpenAIError::Reqwest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't think this library should unwrap and match another library's error structure - please consider achieveing same outcome with OpenAIError::StreamError(EventSourceError) or better
* Unify StreamError and OpenAIError (#413) * unify StreamError and OpenAIError * format * clippy * use underlying reqwest_eventsource::Error * UnknownEvent * update exampels to test streaming errors * update responses-stream example --------- Co-authored-by: Tinco Andringa <[email protected]>
* Unify StreamError and OpenAIError (64bit#413) * unify StreamError and OpenAIError * format * clippy * use underlying reqwest_eventsource::Error * UnknownEvent * update exampels to test streaming errors * update responses-stream example --------- Co-authored-by: Tinco Andringa <[email protected]> (cherry picked from commit 494a4a6) # Conflicts: # async-openai-wasm/src/types/assistant_stream.rs # async-openai/src/client.rs # examples/chat-stream/src/main.rs # examples/completions-stream/src/main.rs # examples/function-call-stream/src/main.rs # examples/responses-stream/src/main.rs # examples/tool-call-stream/src/main.rs
The current StreamError implementation wraps whatever happens in a string, throwing away important underlying information. Specifically this prevents us from catching ContextLengthExceeded errors when streaming is enabled.
This PR rewrites the error handling so that the streaming and non-streaming implementations share the same error parsing code and both return OpenAIError's of which StreamError is now a stream specific subset.
Unfortunately this is a breaking change, any users that explicitly match on StreamError will have to be modified to accommodate the extra information that's now returned in the error.