fix: aggregate streaming responses in auxiliary client#31598
Open
mrmign wants to merge 1 commit into
Open
Conversation
Some custom providers return SSE streams even when stream=False is not honored. This caused title_generation and other auxiliary tasks to fail with 'LLM returned invalid response (type=str)' errors. - Add _aggregate_stream_response() to consume SSE chunks into a standard .choices[0].message completion object - Detect streaming responses in _validate_llm_response(): * Raw SSE strings containing 'data:' prefix * Iterable objects without .choices attribute - Support OpenAI SDK ChatCompletionChunk objects and raw SSE text lines - Preserve reasoning_content from thinking models - Add comprehensive test suite (13 tests) Fixes NousResearch#7264
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.
Summary
Some custom providers return SSE streams even when
stream=Falseis not honored. This causedtitle_generationand other auxiliary tasks to fail with errors like:Changes
_aggregate_stream_response()— consumes SSE chunks into a standard.choices[0].messagecompletion object_validate_llm_response():data:prefix.choicesattributeChatCompletionChunkobjects and raw SSE text linesreasoning_contentfrom thinking models (e.g. Qwen, DeepSeek)How it works
When a custom provider ignores
stream=Falseand returns SSE data:_validate_llm_responsedetects the response is a stream (string withdata:or iterable without.choices)_aggregate_stream_responseto consume all chunksSimpleNamespacematching the expected.choices[0].messageshapeTest Plan
Fixes #7264