fix: only strip extra fields from assistant messages in Mistral

This commit is contained in:
factnn 2026-06-24 14:51:50 +08:00
parent 657244be15
commit 7c3c805154
2 changed files with 16 additions and 1 deletions

View file

@ -296,7 +296,7 @@ class MistralConfig(OpenAIGPTConfig):
@staticmethod
def _strip_extra_fields(messages: list[AllMessageValues]) -> list[AllMessageValues]:
for m in messages:
if isinstance(m, dict):
if isinstance(m, dict) and m.get("role") == "assistant":
m.pop("metadata", None)
m.pop("provider_specific_fields", None)
m.pop("thinking_blocks", None)

View file

@ -281,6 +281,21 @@ class TestMistralReasoningSupport:
assert "cache_control" not in msg
assert "reasoning_content" not in msg
def test_user_message_extra_fields_are_preserved(self):
"""GH#30882: user messages should not be stripped of extra fields."""
mistral_config = MistralConfig()
messages: List[AllMessageValues] = [
cast(
AllMessageValues,
{"role": "user", "content": "Question?", "reasoning_content": "noise"},
)
]
result = mistral_config._transform_messages(messages, "mistral/mistral-large-latest")
assert len(result) == 1
msg = cast(dict, result[0])
assert msg["role"] == "user"
assert msg["reasoning_content"] == "noise"
def test_transform_request_magistral_with_reasoning(self):
"""Test transform_request method for magistral model with reasoning."""
mistral_config = MistralConfig()