This commit is contained in:
ly-wang19 2026-08-27 16:59:27 -05:00 committed by GitHub
commit c295d32321
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 36 additions and 1 deletions

View file

@ -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(
{

View file

@ -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 = [