mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-16 09:22:22 +00:00
Merge 3fde52bef5 into b8283d8b61
This commit is contained in:
commit
cc39922886
2 changed files with 33 additions and 5 deletions
|
|
@ -936,14 +936,17 @@ def gemini_convert_messages_with_history(
|
|||
model=model,
|
||||
forward_function_call_id=forward_function_call_id,
|
||||
)
|
||||
## check if gemini_tool_call already exists in assistant_content
|
||||
for gemini_tool_call_part in gemini_tool_call_parts:
|
||||
## check if gemini_tool_call already exists in assistant_content before this batch
|
||||
pre_existing_parts = list(assistant_content)
|
||||
assistant_content.extend(
|
||||
gemini_tool_call_part
|
||||
for gemini_tool_call_part in gemini_tool_call_parts
|
||||
if not check_if_part_exists_in_parts(
|
||||
assistant_content,
|
||||
pre_existing_parts,
|
||||
gemini_tool_call_part,
|
||||
excluded_keys=["thoughtSignature"],
|
||||
):
|
||||
assistant_content.append(gemini_tool_call_part)
|
||||
)
|
||||
)
|
||||
# Only record this as the active tool-call message when it actually
|
||||
# carries tool calls. The `if` guard above is also entered for a
|
||||
# text-only assistant message (`assistant_msg.get("tool_calls", [])
|
||||
|
|
|
|||
|
|
@ -3016,3 +3016,28 @@ def test_anthropic_messages_history_replays_to_gemini_without_claude_signature()
|
|||
assert signatures == [_get_dummy_thought_signature()]
|
||||
assert [part for part in parts if part.get("text") == thinking] == [{"thought": True, "text": thinking}]
|
||||
assert next(part for part in parts if "function_call" in part)["thoughtSignature"] == _get_dummy_thought_signature()
|
||||
|
||||
def test_parallel_tool_calls_with_identical_name_and_arguments() -> None:
|
||||
"""Parallel tool calls with identical name and arguments must both be preserved.
|
||||
|
||||
Regression test for https://github.com/BerriAI/litellm/issues/48831
|
||||
"""
|
||||
messages: Final = [
|
||||
{"role": "user", "content": "What time is it? Ask twice."},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": None,
|
||||
"tool_calls": [
|
||||
{"id": "call_1", "type": "function", "function": {"name": "get_time", "arguments": "{}"}},
|
||||
{"id": "call_2", "type": "function", "function": {"name": "get_time", "arguments": "{}"}},
|
||||
],
|
||||
},
|
||||
{"role": "tool", "tool_call_id": "call_1", "content": "12:00"},
|
||||
{"role": "tool", "tool_call_id": "call_2", "content": "12:01"},
|
||||
]
|
||||
|
||||
contents = gemini_convert_messages_with_history(messages=messages, model="gemini-2.5-flash")
|
||||
model_parts = next(c["parts"] for c in contents if c.get("role") == "model")
|
||||
function_calls = [p for p in model_parts if "function_call" in p or "functionCall" in p]
|
||||
assert len(function_calls) == 2
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue