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

OpenAI error payloads in the body may not get parsed fully during chat streaming #479

Open
atesgoral opened this issue May 14, 2024 · 0 comments

Comments

@atesgoral
Copy link
Contributor

atesgoral commented May 14, 2024

Describe the bug

With OpenAI chat streaming, if OpenAI returns an HTTP error (e.g. 400), the error handler optimistically tries to parse the first chunk it receives as the entire body. However, networks conditions or an intermediary like an OpenAI proxy may cause the response to be fragmented into different chunks.

The symptom is an error being raised with just the first chunk of the body. While this is not a very severe problem, since it happens during what's already an API call failure (that should ideally be rare), not collecting and parsing the full error would make it hard for application developers to figure out exactly what went wrong.

The issue is here, since #344:

raise_error.on_complete(env.merge(body: try_parse_json(chunk)))

To Reproduce

Hard to reproduce in vivo, unless you're running a special HTTP/TCP proxy that chunks the original TCP packets for you, or have poor network conditions, etc.

Minimal reproducible unit test: #480

-"error" => {"code"=>"test", "message"=>"Test error", "param"=>nil, "type"=>"test_error"},
+"{\"error\":{\"message\":\"Test error\",\"type\":\""

Expected behavior

The full response body is collected (chunks concatenated) and parsed as JSON.

@atesgoral atesgoral mentioned this issue May 14, 2024
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant