mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-28 06:23:07 +00:00
Merge e7a250f656 into 8d6b8dab3d
This commit is contained in:
commit
08cc8e0ee7
2 changed files with 46 additions and 2 deletions
|
|
@ -690,7 +690,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
|
||||
|
|
@ -719,7 +723,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)
|
||||
|
||||
|
|
|
|||
|
|
@ -1793,3 +1793,43 @@ class TestToolSchemaCombinatorFlatteningForOpenAI:
|
|||
)
|
||||
|
||||
assert request["tools"][0] is tool
|
||||
|
||||
|
||||
@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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue