Repository navigation
Handle list-shaped streamed content from Mistral reasoning models - #43
Merged
Merged
Conversation
Mistral streams delta.content as a list of typed chunks (thinking/text) when reasoning is on, which made ''.join(content) raise TypeError and fail the chat turn. Fold only the text chunks into the answer and drop thinking. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GrLGiCjUbitdQqtZjkQa4j
Mistral reasoning streams send delta.content as typed chunks, which _fold_sse skipped because it only folded string fields, so logged responses had no content. Fold text chunks into content and thinking chunks into a separate thinking key. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GrLGiCjUbitdQqtZjkQa4j
Contributor
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
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.
Problem
Chat turns failed after a successful Mistral request:
With reasoning on (
reasoning_effortis sent by default whenLLM_REASONING_EFFORTis set), Mistral streamsdelta.contentas a list of typed chunks, not a string:[{"type": "thinking", "thinking": [{"type": "text", "text": "..."}]}] [{"type": "text", "text": "Olá"}]The OpenAI SDK passes stream chunks through without type checks, so the lists reached
''.joinand crashed.Changes
core/llm.py: a new_content_text()keeps only thetextchunks as the answer. Plain strings work as before. Thinking chunks are dropped, not stored asreasoning_content, because that field is sent back to the provider on the next tool-loop turn.api_logger.py:_fold_sseonly folded string delta fields, so logged Mistral responses had no content. List content now folds intocontent(text) and a separatethinkingkey.Tests
tests/test_llm_stream_content.pybuilds chunks the way the SDK does. It fails with the productionTypeErrorwithout the fix and passes with it.tests/test_api_logger.pynow also checks_fold_sseon a Mistral-shaped stream.ruff check .is clean.Generated by Claude Code