mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-26 06:03:19 +00:00
fix(mistral): keep existing provider_specific_fields on the delta and document the raw block list
The reviewer on this PR pointed out two things about the new mistral_content_blocks field: - it carries the whole provider block list, so thinking/text blocks show up next to reasoning_content; the comment now states plainly that the field is the raw provider input, not a filtered citation list. - chunk_parser assigned delta["provider_specific_fields"] outright, which would drop a value the provider had already put on the delta. The existing dict is now updated in place; the field is only created when absent. Tests: 57 passed before and after (tests/unit/llms/mistral/test_mistral_chat_transformation.py).
This commit is contained in:
parent
cc3afe1b76
commit
88f482a79a
1 changed files with 10 additions and 1 deletions
|
|
@ -617,6 +617,10 @@ class MistralConfig(OpenAIGPTConfig):
|
|||
# The flattened content string cannot carry Mistral
|
||||
# citation chunks; keep the original block list
|
||||
# reachable instead of dropping them silently.
|
||||
# This is the list exactly as the provider sent it
|
||||
# -- thinking and text blocks included, not only the
|
||||
# reference blocks -- so the field is the raw
|
||||
# provider input, not a filtered citation list.
|
||||
choice["message"]["mistral_content_blocks"] = content
|
||||
if thinking_content:
|
||||
choice["message"]["reasoning_content"] = thinking_content
|
||||
|
|
@ -730,7 +734,12 @@ class MistralChatResponseIterator(OpenAIChatCompletionStreamingHandler):
|
|||
):
|
||||
# citation chunks carry no text; expose them on
|
||||
# provider_specific_fields instead of dropping them
|
||||
delta["provider_specific_fields"] = {"mistral_content_blocks": content}
|
||||
existing_fields = delta.get("provider_specific_fields")
|
||||
if isinstance(existing_fields, dict):
|
||||
# keep whatever the provider already put there
|
||||
existing_fields["mistral_content_blocks"] = content
|
||||
else:
|
||||
delta["provider_specific_fields"] = {"mistral_content_blocks": content}
|
||||
except Exception:
|
||||
# Fall back to default parsing if custom handling fails
|
||||
return super().chunk_parser(chunk)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue