tabbyAPI-ollama/templates/tool_calls/chatml_with_headers.jinja
kingbri 871f71c4e7 Templates: Adjust tool call example
Use the new tool call variables and formatting. Also prettify the template.

Signed-off-by: kingbri <8082010+kingbri1@users.noreply.github.com>
2025-07-05 21:42:23 -04:00

69 lines
2.3 KiB
Django/Jinja

{# Metadata #}
{%- set stop_strings = ["<|im_start|>", "<|im_end|>"] -%}
{%- set tool_start = "<|tool_start|>" -%}
{# Variables #}
{%- set message_roles = ['system', 'user', 'assistant', 'tool'] -%}
{%- set tool_end = "<|tool_end|>" -%}
{%- set start_header = "<|start_header_id|>" -%}
{%- set end_header = "<|end_header_id|>\n" -%}
{%- set example_tool_call -%}[
{
"id": "tool_id_1342",
"function": {
"arguments": "arg_name": 3,
"name": "tool_name"
},
"type": "function"
},
{
"id": "example_id_13f42",
"function": {
"arguments": "example_arg": 1.0, "another_example_arg": true,
"name": "another_tool_name"
},
"type": "function"
}
]
{%- endset -%}
{%- set inital_system_prompt -%}You are an assistant that has access to the following set of tools, to call a tool:
1. Prefix calls with '{{ tool_start }}' and end calls with '{{ tool_end }}'
2. Ensure you use the correct type for arguments. For example, if the argument is a string, ensure it is enclosed in quotes, otherwise, it should not be.
3. Generate all calls using the following json tool call format. Here is a multi tool call example:
{{ tool_start }}{{ example_tool_call }}{{ tool_end }}
Here are the tools available for you to call:
{{ tools | tojson(indent=2) }}
{%- endset -%}
{%- for message in messages -%}
{%- set role = message['role'] | lower -%}
{%- if role not in message_roles -%}
{{ raise_exception('Invalid role ' + message['role'] + '. Only ' + message_roles | join(', ') + ' are supported.') }}
{%- endif -%}
{%- set content = message['content'] if message['content'] is defined else '' | trim -%}
{%- if loop.first -%}
{{- bos_token }}{{ start_header }}{{ role }}{{ end_header }}
{{- inital_system_prompt + "\n\n" }}
{{- content }}{{ eos_token }}
{%- endif -%}
{%- if not loop.first -%}
{{- start_header }}{{ role }}{{ end_header }}
{{- content }}
{%- if 'tool_calls' in message and message['tool_calls'] -%}
{{- tool_start }}{{ message['tool_calls'] | tojson(indent=2) }}{{ tool_end }}
{%- endif -%}
{{- eos_token }}
{%- endif -%}
{%- endfor -%}
{%- if add_generation_prompt %}
{{- start_header }}assistant{{ end_header }}
{%- endif %}