Tool Calling in Chat Template
#160
by
aashkaaa
- opened
Hi, I have a question regarding how a tool call should be formatted by the chat template.
According to the OpenAI cookbook (https://cookbook.openai.com/articles/openai-harmony#prompt-format), I see that model should call tools in the following way:<|channel|>analysis<|message|>Need to use function get_current_weather.<|end|><|start|>assistant<|channel|>commentary to=functions.get_current_weather <|constrain|>json<|message|>{"location":"San Francisco"}<|call|>
i.e., <|channel|>commentary precedes to=functions.FUNCTION_NAME
However, looking at the chat template, it seems like the <|channel|> commentary is being added after the to=functions.FUNCTION_NAME call:
{{- "functions." + tool_call.name + "<|channel|>commentary " }}```
I see this difference when using the model-- the model produces the tool call in the format given in the cookbook (channel before to=functions.FUNCTION_NAME), but calling `apply_chat_template` on messages with a tool call will place the channel after the to=functions.FUNCTION_NAME
Is this a bug in the chat template, or am I misunderstanding something?