Buffer streamed chunks from stream-result endpoint#132
Merged
jakelazaroff merged 4 commits intomainfrom Mar 17, 2025
Merged
Conversation
rolyatmax
approved these changes
Mar 17, 2025
37d96d7 to
3b0ea50
Compare
d5cacab to
b65ff28
Compare
d672126 to
4d51dcc
Compare
4d51dcc to
8eb9ee2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I ran into an issue with the
stream-resultendpoint where a single JSON output or result can end up split between multiple "chunks" in the HTTP response stream. One easy way to reproduce this is to stream back a result with an image, which we serialize to base 64; it ends up being split between two chunks, each of which is invalid JSON.This PR circumvents that by processing each chunk "newline segment by newline segment". There is a
valuethat contains the current chunk, and abufferthat is assumed to contain all unfinished JSON from previous iterations. TL;DR:value.valuefor the substring until the first newline.bufferto an empty string and thevalueto the remaining text in the chunk after the substring. GOTO 2.