From bc3e0c083092c9b8d28fa45417777c0f7c7764ac Mon Sep 17 00:00:00 2001 From: ochafik Date: Sat, 28 Sep 2024 23:05:35 +0100 Subject: [PATCH] `tool-call`: Qwen 2.5 Instruct also requires object arguments --- common/chat-template.cpp | 2 +- tests/chat/goldens/Qwen-Qwen2.5-7B-Instruct-tool_use.txt | 6 +++--- .../chat/goldens/Qwen-Qwen2.5-Math-7B-Instruct-tool_use.txt | 6 +++--- .../goldens/meta-llama-Llama-3.2-3B-Instruct-tool_use.txt | 6 +++--- tests/update_jinja_goldens.py | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/common/chat-template.cpp b/common/chat-template.cpp index 7234e524cdcfe..514c0baf20112 100644 --- a/common/chat-template.cpp +++ b/common/chat-template.cpp @@ -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("") != std::string::npos) { diff --git a/tests/chat/goldens/Qwen-Qwen2.5-7B-Instruct-tool_use.txt b/tests/chat/goldens/Qwen-Qwen2.5-7B-Instruct-tool_use.txt index f5fb6a25ea835..7862ad435857f 100644 --- a/tests/chat/goldens/Qwen-Qwen2.5-7B-Instruct-tool_use.txt +++ b/tests/chat/goldens/Qwen-Qwen2.5-7B-Instruct-tool_use.txt @@ -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 -{"name": "ipython", "arguments": "{\"code\": \"print('Hello, World!')\"}"} +{"name": "ipython", "arguments": {"code": "print('Hello, World!')"}} <|im_end|> <|im_start|>user @@ -33,7 +33,7 @@ Anything else?<|im_end|> Test a tautology.<|im_end|> <|im_start|>assistant -{"name": "test", "arguments": "{\"condition\":true}"} +{"name": "test", "arguments": {"condition": true}} <|im_end|> <|im_start|>user @@ -45,7 +45,7 @@ Truth is definitely true.<|im_end|> Check it on the web.<|im_end|> <|im_start|>assistant -{"name": "brave_search", "arguments": "{\"query\": \"what is truth anyway am I right?\"}"} +{"name": "brave_search", "arguments": {"query": "what is truth anyway am I right?"}} <|im_end|> <|im_start|>user diff --git a/tests/chat/goldens/Qwen-Qwen2.5-Math-7B-Instruct-tool_use.txt b/tests/chat/goldens/Qwen-Qwen2.5-Math-7B-Instruct-tool_use.txt index e77903e911d64..b25b2054faccd 100644 --- a/tests/chat/goldens/Qwen-Qwen2.5-Math-7B-Instruct-tool_use.txt +++ b/tests/chat/goldens/Qwen-Qwen2.5-Math-7B-Instruct-tool_use.txt @@ -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 -{"name": "ipython", "arguments": "{\"code\": \"print('Hello, World!')\"}"} +{"name": "ipython", "arguments": {"code": "print('Hello, World!')"}} <|im_end|> <|im_start|>user @@ -33,7 +33,7 @@ Anything else?<|im_end|> Test a tautology.<|im_end|> <|im_start|>assistant -{"name": "test", "arguments": "{\"condition\":true}"} +{"name": "test", "arguments": {"condition": true}} <|im_end|> <|im_start|>user @@ -45,7 +45,7 @@ Truth is definitely true.<|im_end|> Check it on the web.<|im_end|> <|im_start|>assistant -{"name": "brave_search", "arguments": "{\"query\": \"what is truth anyway am I right?\"}"} +{"name": "brave_search", "arguments": {"query": "what is truth anyway am I right?"}} <|im_end|> <|im_start|>user diff --git a/tests/chat/goldens/meta-llama-Llama-3.2-3B-Instruct-tool_use.txt b/tests/chat/goldens/meta-llama-Llama-3.2-3B-Instruct-tool_use.txt index 00cf2ddf469cf..407abbdd9ff1a 100644 --- a/tests/chat/goldens/meta-llama-Llama-3.2-3B-Instruct-tool_use.txt +++ b/tests/chat/goldens/meta-llama-Llama-3.2-3B-Instruct-tool_use.txt @@ -92,7 +92,7 @@ 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|> @@ -100,7 +100,7 @@ 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|> @@ -108,7 +108,7 @@ 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|> diff --git a/tests/update_jinja_goldens.py b/tests/update_jinja_goldens.py index 826da56ccf36a..0f15271239742 100644 --- a/tests/update_jinja_goldens.py +++ b/tests/update_jinja_goldens.py @@ -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']: