-
Notifications
You must be signed in to change notification settings - Fork 321
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
Correctly handle partial JSON at the end of a chunk #104
Conversation
From open pull request: MacPaw#104
Neat! 🔥 |
Kudos, SonarCloud Quality Gate passed!
|
@PallavAg, hi, I just moved json processing out, what do you think? |
It looks like this issue has started to happen again. Have noticed the intensity of this go up in the past 2-3 days. I'm using the latest version of OpenAI 0.2.5 which has this fix. But yet many of my chatsStream(query: query) queries are erroring out with this error
|
What
Streaming a response occasionally encounters the error
"The given data was not valid JSON."
Related Issues: #97 #103
Why
The end of a chunk can have an incomplete JSON.
The rest of the JSON will come through at the beginning of the next chunk.
Affected Areas
StreamingSession.swift
More Info
This change stores the last JSON from the chunk and appends it to the beginning of the next chunk.
A likely partial JSON is stored when:
ResultType
decoding failsAPIErrorResponse
decoding failsHaving an incomplete JSON at the end of a chunk is seemingly random - likely based on OpenAI server load etc.
A request that surfaces this issue more often than not is:
"Write 1 to 40 using bullet points"
Kudos to @jcmourey for suggesting the fix in #97