Co-authored-by: Kim-Adeline Miguel <51720070+kimadeline@users.noreply.github.com>
Co-authored-by: Mathias Gesbert <mathias.gesbert@mistral.ai>
Co-authored-by: Maxime Dolores <maxime.dolores@ext.mistral.ai>
Co-authored-by: Nelson PROIA <144663685+Nelson-PROIA@users.noreply.github.com>
Co-authored-by: Paul VEZIA <166131032+le-codeur-rapide@users.noreply.github.com>
Co-authored-by: Pierre Rossinès <pierre.rossines@mistral.ai>
Co-authored-by: Quentin <quentin.torroba@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:
Guillaume LE GOFF 2026-06-12 13:16:04 +02:00 committed by GitHub
parent 702d0f412e
commit cafb6d4147
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
247 changed files with 12401 additions and 3029 deletions

View file

@ -498,6 +498,83 @@ class TestAdapterParseResponse:
assert chunk.message.content == "Hello!"
assert chunk.usage.prompt_tokens == 10
def test_non_streaming_captures_refusal_stop_reason(self, adapter, provider):
data = {
"content": [],
"usage": {"input_tokens": 10, "output_tokens": 2},
"stop_reason": "refusal",
}
chunk = adapter.parse_response(data, provider)
assert chunk.stop is not None
assert chunk.stop.reason == "refusal"
def test_streaming_message_delta_captures_refusal_stop_reason(
self, adapter, provider
):
data = {
"type": "message_delta",
"delta": {"stop_reason": "refusal", "stop_sequence": None},
"usage": {"output_tokens": 7},
}
chunk = adapter.parse_response(data, provider)
assert chunk.stop is not None
assert chunk.stop.reason == "refusal"
assert chunk.usage.completion_tokens == 7
def test_streaming_message_delta_end_turn_stop_reason(self, adapter, provider):
data = {
"type": "message_delta",
"delta": {"stop_reason": "end_turn", "stop_sequence": None},
"usage": {"output_tokens": 3},
}
chunk = adapter.parse_response(data, provider)
assert chunk.stop is not None
assert chunk.stop.reason == "end_turn"
def test_non_streaming_captures_refusal_stop_details(self, adapter, provider):
data = {
"content": [],
"usage": {"input_tokens": 10, "output_tokens": 2},
"stop_reason": "refusal",
"stop_details": {
"type": "refusal",
"category": "cyber",
"explanation": "This request was declined.",
},
}
chunk = adapter.parse_response(data, provider)
assert chunk.stop is not None
assert chunk.stop.category == "cyber"
assert chunk.stop.explanation == "This request was declined."
def test_non_streaming_without_stop_details_is_none(self, adapter, provider):
data = {
"content": [],
"usage": {"input_tokens": 10, "output_tokens": 2},
"stop_reason": "end_turn",
}
chunk = adapter.parse_response(data, provider)
assert chunk.stop is not None
assert chunk.stop.category is None
assert chunk.stop.explanation is None
def test_streaming_message_delta_captures_refusal_stop_details(
self, adapter, provider
):
data = {
"type": "message_delta",
"delta": {
"stop_reason": "refusal",
"stop_sequence": None,
"stop_details": {"type": "refusal", "category": "bio"},
},
"usage": {"output_tokens": 7},
}
chunk = adapter.parse_response(data, provider)
assert chunk.stop is not None
assert chunk.stop.category == "bio"
assert chunk.stop.explanation is None
def test_streaming_text_delta(self, adapter, provider):
data = {
"type": "content_block_delta",