Skip to content

Commit

Permalink
tool-call: Qwen 2.5 Instruct also requires object arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
ochafik committed Sep 28, 2024
1 parent b10ef04 commit bc3e0c0
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion common/chat-template.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ llama_chat_template::llama_chat_template(const std::string & chat_template, cons
_supports_tools = chat_template.find("tools") != std::string::npos;
_requires_object_arguments =
chat_template.find("tool_call.arguments | items") != std::string::npos
|| chat_template.find("{{- tool_call.arguments | tojson }}") != std::string::npos;
|| chat_template.find("tool_call.arguments | tojson") != std::string::npos;
_supports_system_role = chat_template.find("System role not supported") == std::string::npos;

if (chat_template.find("<tool_call>") != std::string::npos) {
Expand Down
6 changes: 3 additions & 3 deletions tests/chat/goldens/Qwen-Qwen2.5-7B-Instruct-tool_use.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ For each function call, return a json object with function name and arguments wi
Print a hello world message with python.<|im_end|>
<|im_start|>assistant
<tool_call>
{"name": "ipython", "arguments": "{\"code\": \"print('Hello, World!')\"}"}
{"name": "ipython", "arguments": {"code": "print('Hello, World!')"}}
</tool_call><|im_end|>
<|im_start|>user
<tool_response>
Expand All @@ -33,7 +33,7 @@ Anything else?<|im_end|>
Test a tautology.<|im_end|>
<|im_start|>assistant
<tool_call>
{"name": "test", "arguments": "{\"condition\":true}"}
{"name": "test", "arguments": {"condition": true}}
</tool_call><|im_end|>
<|im_start|>user
<tool_response>
Expand All @@ -45,7 +45,7 @@ Truth is definitely true.<|im_end|>
Check it on the web.<|im_end|>
<|im_start|>assistant
<tool_call>
{"name": "brave_search", "arguments": "{\"query\": \"what is truth anyway am I right?\"}"}
{"name": "brave_search", "arguments": {"query": "what is truth anyway am I right?"}}
</tool_call><|im_end|>
<|im_start|>user
<tool_response>
Expand Down
6 changes: 3 additions & 3 deletions tests/chat/goldens/Qwen-Qwen2.5-Math-7B-Instruct-tool_use.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ For each function call, return a json object with function name and arguments wi
Print a hello world message with python.<|im_end|>
<|im_start|>assistant
<tool_call>
{"name": "ipython", "arguments": "{\"code\": \"print('Hello, World!')\"}"}
{"name": "ipython", "arguments": {"code": "print('Hello, World!')"}}
</tool_call><|im_end|>
<|im_start|>user
<tool_response>
Expand All @@ -33,7 +33,7 @@ Anything else?<|im_end|>
Test a tautology.<|im_end|>
<|im_start|>assistant
<tool_call>
{"name": "test", "arguments": "{\"condition\":true}"}
{"name": "test", "arguments": {"condition": true}}
</tool_call><|im_end|>
<|im_start|>user
<tool_response>
Expand All @@ -45,7 +45,7 @@ Truth is definitely true.<|im_end|>
Check it on the web.<|im_end|>
<|im_start|>assistant
<tool_call>
{"name": "brave_search", "arguments": "{\"query\": \"what is truth anyway am I right?\"}"}
{"name": "brave_search", "arguments": {"query": "what is truth anyway am I right?"}}
</tool_call><|im_end|>
<|im_start|>user
<tool_response>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,23 +92,23 @@ Respond in the format {"name": function name, "parameters": dictionary of argume

Print a hello world message with python.<|eot_id|><|start_header_id|>assistant<|end_header_id|>

{"name": "ipython", "parameters": "{\"code\": \"print('Hello, World!')\"}"}<|eot_id|><|start_header_id|>ipython<|end_header_id|>
{"name": "ipython", "parameters": {"code": "print('Hello, World!')"}}<|eot_id|><|start_header_id|>ipython<|end_header_id|>

"{\"stdout\": \"Hello, World!\"}"<|eot_id|><|start_header_id|>assistant<|end_header_id|>

Anything else?<|eot_id|><|start_header_id|>user<|end_header_id|>

Test a tautology.<|eot_id|><|start_header_id|>assistant<|end_header_id|>

{"name": "test", "parameters": "{\"condition\":true}"}<|eot_id|><|start_header_id|>ipython<|end_header_id|>
{"name": "test", "parameters": {"condition": true}}<|eot_id|><|start_header_id|>ipython<|end_header_id|>

"true"<|eot_id|><|start_header_id|>assistant<|end_header_id|>

Truth is definitely true.<|eot_id|><|start_header_id|>user<|end_header_id|>

Check it on the web.<|eot_id|><|start_header_id|>assistant<|end_header_id|>

{"name": "brave_search", "parameters": "{\"query\": \"what is truth anyway am I right?\"}"}<|eot_id|><|start_header_id|>ipython<|end_header_id|>
{"name": "brave_search", "parameters": {"query": "what is truth anyway am I right?"}}<|eot_id|><|start_header_id|>ipython<|end_header_id|>

"{\"title\":\"Truth: don't ask the web, ask an LLM instead!\",\"url\":\"https://en.wikipedia.org/wiki/Truth\"}"<|eot_id|><|start_header_id|>assistant<|end_header_id|>

Expand Down
2 changes: 1 addition & 1 deletion tests/update_jinja_goldens.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def handle_chat_template(model_id, variant, template_src):
render_context = json.loads(json.dumps(context))

# Work around Llama-3.1 template quirk: it expects tool_call.function.arguments to be an object rather than its JSON string representation.
if 'tool_call.arguments | items' in template_src:
if 'tool_call.arguments | items' in template_src or 'tool_call.arguments | tojson' in template_src:
for message in render_context['messages']:
if 'tool_calls' in message:
for tool_call in message['tool_calls']:
Expand Down

0 comments on commit bc3e0c0

Please sign in to comment.