fix: prevent reasoning field from being copied into provider_specific_fields

This commit is contained in:
alchemicjon 2026-10-19 12:44:58 -04:00
parent 1dfceccf10
commit cb8b9c0e0b
No known key found for this signature in database
2 changed files with 23 additions and 1 deletions

View file

@ -741,7 +741,7 @@ def convert_to_model_response_object(
# Preserve provider_specific_fields if already present
# in the response (e.g. from proxy passthrough)
provider_specific_fields = dict(choice["message"].get("provider_specific_fields", None) or {})
for f in choice["message"].keys() - _MESSAGE_FIELDS:
for f in choice["message"].keys() - _MESSAGE_FIELDS - {"reasoning"}:
provider_specific_fields[f] = choice["message"][f]
# Handle reasoning models that display `reasoning_content` within `content`

View file

@ -2873,6 +2873,28 @@ class TestConvertToModelResponseObjectCompletion:
assert message.reasoning_content == "2+2=4"
assert "reasoning_content" not in (message.provider_specific_fields or {})
def test_reasoning_not_mirrored_into_provider_specific_fields(self):
response_object = {
"id": "chatcmpl-6",
"model": "openrouter/deepseek/deepseek-r1",
"choices": [
{
"finish_reason": "stop",
"index": 0,
"message": {"content": "The answer is 4.", "role": "assistant", "reasoning": "2+2=4"},
}
],
"usage": {"prompt_tokens": 5, "completion_tokens": 10, "total_tokens": 15},
}
result = convert_to_model_response_object(
response_object=response_object,
model_response_object=ModelResponse(),
)
message = result.choices[0].message
assert message.reasoning_content == "2+2=4"
assert "reasoning" not in (message.provider_specific_fields or {})
def test_response_none_raises(self):
with pytest.raises(Exception, match="Invalid response object"):
convert_to_model_response_object(