apply_chat_template with tools not working

#4
by inkor - opened

Error when use template with tools

tools = [
{
"type": "function",
"function": {
"name": "query_daily_sales_report",
"description": "Connects to a database to retrieve overall sales volumes and sales information for a given day.",
"parameters": {
"type": "object",
"properties": {
"day": {
"type": "string",
"description": "Retrieves sales data for this day, formatted as YYYY-MM-DD."
}
},
"required": ["day"]
}
}
}
]

result = tokenizer.apply_chat_template(messages, tools=tools, add_generation_prompt=True, tokenize=False)

File ~/miniconda3/envs/transformers_llm/lib/python3.10/site-packages/transformers/tokenization_utils_base.py:1869, in PreTrainedTokenizerBase.apply_chat_template(self, conversation, tools, documents, chat_template, add_generation_prompt, continue_final_message, tokenize, padding, truncation, max_length, return_tensors, return_dict, return_assistant_tokens_mask, tokenizer_kwargs, **kwargs)
1867 all_generation_indices.append(generation_indices)
1868 else:
-> 1869 rendered_chat = compiled_template.render(
1870 messages=chat,
1871 tools=tool_schemas,
1872 documents=documents,
1873 add_generation_prompt=add_generation_prompt,
1874 **template_kwargs,
1875 )
1876 if continue_final_message:
1877 final_message = chat[-1]["content"]

File ~/miniconda3/envs/transformers_llm/lib/python3.10/site-packages/jinja2/environment.py:1304, in Template.render(self, *args, **kwargs)
1302 return self.environment.concat(self.root_render_func(ctx)) # type: ignore
1303 except Exception:
-> 1304 self.environment.handle_exception()

File ~/miniconda3/envs/transformers_llm/lib/python3.10/site-packages/jinja2/environment.py:939, in Environment.handle_exception(self, source)
934 """Exception handling helper. This is used internally to either raise
935 rewritten exceptions or return a rendered traceback for the template.
936 """
937 from .debug import rewrite_traceback_stack
--> 939 raise rewrite_traceback_stack(source=source)

File template:17, in top-level template code()

UndefinedError: 'dict object' has no attribute 'name'

Cohere For AI org

Hi, this model is not meant for tool use so wouldn't recommend using it for such use cases. It's built for good multilingual performance.
If you're interested in tool use, please check out Command-R and Command-R-plus .

Also closing this issue for now but feel free to reopen in case of other doubts and questions.

shivi changed discussion status to closed

Sign up or log in to comment