Co-authored-by: Clément Sirieix <clement.sirieix@mistral.ai>
Co-authored-by: Kim-Adeline Miguel <kimadeline.miguel@mistral.ai>
Co-authored-by: Lucas Marandat <31749711+lucasmrdt@users.noreply.github.com>
Co-authored-by: Michel Thomazo <51709227+michelTho@users.noreply.github.com>
Co-authored-by: Paul Cacheux <paul.cacheux@mistral.ai>
Co-authored-by: Peter Evers <pevers90@gmail.com>
Co-authored-by: Pierre Rossinès <pierre.rossines@mistral.ai>
Co-authored-by: Pierre Rossinès <pierre.rossines@protonmail.com>
Co-authored-by: Quentin <quentin.torroba@mistral.ai>
Co-authored-by: Simon Van de Kerckhove <simon.vandekerckhove@mistral.ai>
Co-authored-by: Val <102326092+vdeva@users.noreply.github.com>
Co-authored-by: Vincent G <10739306+VinceOPS@users.noreply.github.com>
Co-authored-by: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
Mathias Gesbert 2026-04-09 18:40:46 +02:00 committed by GitHub
parent 90763daf81
commit e9a9217cc8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
113 changed files with 7202 additions and 541 deletions

View file

@ -529,26 +529,6 @@ class TestMistralMapperPrepareMessage:
result = mapper.prepare_message(msg)
assert result.content == "Hello!"
def test_strip_reasoning_removes_reasoning_from_assistant(
self, mapper: MistralMapper
) -> None:
msg = LLMMessage(
role=Role.assistant,
content="Answer",
reasoning_content="thinking...",
reasoning_signature="sig",
)
stripped = mapper.strip_reasoning(msg)
assert stripped.content == "Answer"
assert stripped.reasoning_content is None
assert stripped.reasoning_signature is None
def test_strip_reasoning_leaves_non_assistant_unchanged(
self, mapper: MistralMapper
) -> None:
msg = LLMMessage(role=Role.user, content="hello")
assert mapper.strip_reasoning(msg) is msg
class TestMistralBackendReasoningEffort:
"""Tests that MistralBackend correctly passes reasoning_effort to the SDK."""
@ -612,53 +592,6 @@ class TestMistralBackendReasoningEffort:
assert call_kwargs["reasoning_effort"] == expected_effort
assert call_kwargs["temperature"] == expected_temperature
@pytest.mark.asyncio
async def test_complete_strips_reasoning_when_thinking_off(
self, backend: MistralBackend
) -> None:
model = ModelConfig(
name="mistral-small-latest",
provider="mistral",
alias="mistral-small",
thinking="off",
)
messages = [
LLMMessage(role=Role.user, content="hi"),
LLMMessage(
role=Role.assistant, content="answer", reasoning_content="thinking..."
),
LLMMessage(role=Role.user, content="follow up"),
]
with patch.object(backend, "_get_client") as mock_get_client:
mock_client = MagicMock()
mock_response = MagicMock()
mock_response.choices = [MagicMock()]
mock_response.choices[0].message.content = "response"
mock_response.choices[0].message.tool_calls = None
mock_response.usage.prompt_tokens = 10
mock_response.usage.completion_tokens = 5
mock_client.chat.complete_async = AsyncMock(return_value=mock_response)
mock_get_client.return_value = mock_client
await backend.complete(
model=model,
messages=messages,
temperature=0.2,
tools=None,
max_tokens=None,
tool_choice=None,
extra_headers=None,
)
call_kwargs = mock_client.chat.complete_async.call_args.kwargs
assert call_kwargs["reasoning_effort"] is None
# The assistant message should have reasoning stripped
converted_msgs = call_kwargs["messages"]
assistant_msg = converted_msgs[1]
assert isinstance(assistant_msg, AssistantMessage)
assert assistant_msg.content == "answer"
class TestBuildHttpErrorBodyReading:
_MESSAGES: ClassVar[list[LLMMessage]] = [LLMMessage(role=Role.user, content="hi")]