mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-07 08:26:10 +00:00
Merge 7e5a39aaeb into 7083c47998
This commit is contained in:
commit
c295d32321
2 changed files with 36 additions and 1 deletions
|
|
@ -247,7 +247,15 @@ def ollama_pt(
|
|||
for call in tool_calls:
|
||||
call_id: str = call["id"]
|
||||
function_name: str = call["function"]["name"]
|
||||
arguments = json.loads(call["function"]["arguments"])
|
||||
# Use the shared safe parser (mirrors the other tool-call
|
||||
# sites in this module): a no-argument function call carries
|
||||
# arguments="" / None, on which a bare json.loads raises
|
||||
# JSONDecodeError and aborts the whole request during prompt
|
||||
# construction. parse_tool_call_arguments returns {} for
|
||||
# empty/None and repairs truncated JSON.
|
||||
arguments = parse_tool_call_arguments(
|
||||
call["function"]["arguments"], tool_name=function_name
|
||||
)
|
||||
|
||||
ollama_tool_calls.append(
|
||||
{
|
||||
|
|
|
|||
|
|
@ -55,6 +55,33 @@ def test_ollama_pt_simple_messages():
|
|||
assert result["images"] == []
|
||||
|
||||
|
||||
def test_ollama_pt_assistant_tool_call_with_empty_arguments():
|
||||
"""A prior assistant tool call for a no-argument function carries
|
||||
arguments="" (or None). ollama_pt must not abort the request with a
|
||||
JSONDecodeError while rebuilding the prompt; empty arguments parse to {}."""
|
||||
messages = [
|
||||
{"role": "user", "content": "What time is it?"},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "",
|
||||
"tool_calls": [
|
||||
{
|
||||
"id": "call_1",
|
||||
"type": "function",
|
||||
"function": {"name": "get_current_time", "arguments": ""},
|
||||
}
|
||||
],
|
||||
},
|
||||
{"role": "tool", "content": "12:00", "tool_call_id": "call_1"},
|
||||
]
|
||||
|
||||
result = ollama_pt(model="llama2", messages=messages) # must not raise
|
||||
|
||||
assert isinstance(result, dict)
|
||||
assert "get_current_time" in result["prompt"]
|
||||
assert '"arguments": {}' in result["prompt"]
|
||||
|
||||
|
||||
def test_ollama_pt_consecutive_user_messages():
|
||||
"""Test handling consecutive user messages"""
|
||||
messages = [
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue