Open
Description
Reminder
- I have read the above rules and searched the existing issues.
Description
The current tool call format cannot handle cases where the value is in the form of xxx<tool_call>xxx</tool_call>
, while the Qwen2.5 and Qwen3 templates support this format.
Run the following code:
def get_current_temperature(location: str, unit: str) -> float:
"""
Get the current temperature at a location.
Args:
location: The location to get the temperature for, in the format "City, Country"
unit: The unit to return the temperature in. (choices: ["celsius", "fahrenheit"])
Returns:
The current temperature at the specified location in the specified units, as a float.
"""
return 22. # A real function should probably actually get the temperature!
def get_current_wind_speed(location: str) -> float:
"""
Get the current wind speed in km/h at a given location.
Args:
location: The location to get the temperature for, in the format "City, Country"
Returns:
The current wind speed at the given location in km/h, as a float.
"""
return 6. # A real function should probably actually get the wind speed!
tools = [get_current_temperature, get_current_wind_speed]
from transformers import AutoModelForCausalLM, AutoTokenizer
model_path = "Qwen/Qwen2.5-7B-Instruct"
# model_path = "Qwen/Qwen3-1.7B"
tokenizer = AutoTokenizer.from_pretrained(model_path)
messages = [
{"role": "system", "content": "You are a bot that responds to weather queries. You should reply with the unit used in the queried location."},
{"role": "user", "content": "Hey, what's the temperature in Paris right now?"}
]
tool_call = {"name": "get_current_temperature", "arguments": {"location": "Paris, France", "unit": "celsius"}}
messages.append({"role": "assistant", "content": "hello", "tool_calls": [{"type": "function", "function": tool_call}]})
messages.append({"role": "tool", "content": "22."})
inputs = tokenizer.apply_chat_template(messages, tools=tools, add_generation_prompt=True, tokenize=False)
print("*" * 50)
print("inputs:", inputs)
Please pay attention to the position of 'hello' below.
Pull Request
No response