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

fix parse exception when sse stream returns incomplete data #80

Merged
merged 1 commit into from
Nov 22, 2023

Conversation

wliu6v
Copy link
Contributor

@wliu6v wliu6v commented Nov 22, 2023

I've noticed that the first response from SSE is sometimes incomplete, where it might split a single JSON object across two responses.

The first:
{"id":"chatcmpl-8NY6x7nqghZB9FgFciPtk5

The second:
azY6e6e","object":"chat.completion.chunk","created":1700623359,"model":"gpt-4-0613","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}

By catching a jsonDecode exception, we can identify this situation and attempt to concatenate the incomplete response with the next one to parse them together, which should solve the issue.

@codecov-commenter
Copy link

Codecov Report

Attention: 13 lines in your changes are missing coverage. Please review.

Comparison is base (a17b4fd) 83.87% compared to head (be02275) 83.87%.
Report is 1 commits behind head on main.

Files Patch % Lines
lib/src/client/openai_client.dart 13.33% 13 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #80   +/-   ##
=======================================
  Coverage   83.87%   83.87%           
=======================================
  Files          71       71           
  Lines        1048     1048           
=======================================
  Hits          879      879           
  Misses        169      169           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@redevrx redevrx merged commit 58ec1dc into redevrx:main Nov 22, 2023
1 check passed
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

Successfully merging this pull request may close these issues.

3 participants