This commit is contained in:
Saylee 2026-11-06 00:42:50 +00:00 • committed by GitHub
commit dca333c82d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 46 additions and 2 deletions

View file

@ -793,7 +793,11 @@ class OpenAIGPTConfig(BaseLLMModelInfo, BaseConfig):
json_mode_content_str: str | None = str(new_tool_calls[0]["function"].get("arguments", "")) or None
if json_mode_content_str is not None:
translated_message = Message(content=json_mode_content_str)
finish_reason = "stop"
finish_reason = (
"stop"
if choice["finish_reason"] in ("tool_calls", "function_call")
else choice["finish_reason"]
)
if translated_message is None:
## get the reasoning content
@ -822,7 +826,7 @@ class OpenAIGPTConfig(BaseLLMModelInfo, BaseConfig):
)
translated_choice.finish_reason = map_finish_reason(
self._get_finish_reason(translated_message, choice["finish_reason"])
self._get_finish_reason(translated_message, finish_reason)
)
transformed_choices.append(translated_choice)

View file

@ -2215,3 +2215,43 @@ async def test_chat_sends_a_breakpoint_by_the_deployments_own_flag_not_a_sibling
"opted-in": True,
"flagless": False,
}
@pytest.mark.parametrize(
"provider_finish_reason, expected_finish_reason",
[
("tool_calls", "stop"),
("function_call", "stop"),
("length", "length"),
("stop", "stop"),
],
)
def test_transform_choices_json_mode_reports_stop_only_for_tool_call_reasons(
provider_finish_reason, expected_finish_reason
):
"""json_mode folds a tool call into JSON content. Only tool-call reasons become
'stop'; a truncated ('length') or already-final reason must survive untouched."""
choice = [
{
"finish_reason": provider_finish_reason,
"index": 0,
"logprobs": None,
"message": {
"content": None,
"role": "assistant",
"tool_calls": [
{
"id": "call_1",
"type": "function",
"function": {"name": "json_tool_call", "arguments": '{"a": 1}'},
}
],
},
}
]
out = OpenAIGPTConfig()._transform_choices(choices=choice, json_mode=True)
assert out[0].message.content == '{"a": 1}'
assert out[0].message.tool_calls is None
assert out[0].finish_reason == expected_finish_reason