{{ bos_token }}
{%- set effective_reasoning_effort = reasoning_effort if reasoning_effort is defined and reasoning_effort in ['low', 'medium', 'high', 'max'] else 'max' -%}
{%- if (enable_thinking is not defined or enable_thinking) and effective_reasoning_effort is not none -%}<|system|>Reasoning Effort: {{ effective_reasoning_effort | upper }}{%- endif -%}
{%- macro render_extra_keys(json_dict, handled_keys) -%}
{%- if json_dict is mapping -%}
{%- for json_key in json_dict if json_key not in handled_keys -%}
{%- if json_dict[json_key] is mapping or (json_dict[json_key] is sequence and json_dict[json_key] is not string) -%}
{{- '\n<' ~ json_key ~ '>' ~ (json_dict[json_key] | tojson | safe) ~ '' ~ json_key ~ '>' }}
{%- else -%}
{{- '\n<' ~ json_key ~ '>' ~ (json_dict[json_key] | string) ~ '' ~ json_key ~ '>' }}
{%- endif -%}
{%- endfor -%}
{%- endif -%}
{%- endmacro -%}
{%- if tools -%}
<|system|>
# Tools
You have access to the following functions:
{%- for tool in tools -%}
{%- if tool.function is defined -%}
{%- set tool = tool.function -%}
{%- elif 'function' in tool -%}
{%- set tool = tool['function'] -%}
{%- endif -%}
{%- if tool.defer_loading is not defined or not tool.defer_loading -%}
{{- "\n\n" ~ tool.name ~ "" }}
{%- if tool.description is defined -%}
{{- '\n' ~ (tool.description | trim) ~ '' }}
{%- endif -%}
{{- '\n' }}
{%- if tool.parameters is defined and tool.parameters is mapping and tool.parameters.properties is defined and tool.parameters.properties is mapping -%}
{%- for param_name, param_fields in tool.parameters.properties|items -%}
{{- '\n' }}
{{- '\n' ~ param_name ~ '' }}
{%- if param_fields.type is defined -%}
{{- '\n' ~ (param_fields.type | string) ~ '' }}
{%- endif -%}
{%- if param_fields.description is defined -%}
{{- '\n' ~ (param_fields.description | trim) ~ '' }}
{%- endif -%}
{%- if param_fields.enum is defined -%}
{{- '\n' ~ (param_fields.enum | tojson | safe) ~ '' }}
{%- endif -%}
{%- set handled_keys = ['name', 'type', 'description', 'enum'] -%}
{{- render_extra_keys(param_fields, handled_keys) }}
{{- '\n' }}
{%- endfor -%}
{%- endif -%}
{%- set handled_keys = ['type', 'properties', 'required'] -%}
{{- render_extra_keys(tool.parameters, handled_keys) }}
{%- if tool.parameters is defined and tool.parameters.required is defined -%}
{{- '\n' ~ (tool.parameters.required | tojson | safe) ~ '' }}
{%- endif -%}
{{- '\n' }}
{%- set handled_keys = ['type', 'name', 'description', 'parameters', 'defer_loading', 'strict'] -%}
{{- render_extra_keys(tool, handled_keys) }}
{{- '\n' }}
{%- endif -%}
{%- endfor -%}
{{- "\n" }}
If you choose to call a function ONLY reply in the following format with NO suffix:
example_function_name
example_parameter_1
value_1
example_parameter_2
This is the value for the second parameter
that can span
multiple lines
Reminder:
- Function or tool calls MUST follow the specified format: function_name with inner and blocks, closed by
- Required parameters MUST be specified
- You may provide optional reasoning for your function call in natural language BEFORE the function call, but NOT after
- If there is no function call available, answer the question like normal with your current knowledge and do not tell the user about function calls
{%- endif -%}
{%- macro visible_text(content) -%}
{%- if content is string -%}
{{- content }}
{%- elif content is iterable and content is not mapping -%}
{%- for item in content -%}
{%- if item is mapping and item.type == 'text' -%}
{{- item.text }}
{%- elif item is string -%}
{{- item }}
{%- elif item is mapping and item.type in ['image', 'image_url', 'video', 'video_url', 'audio', 'audio_url', 'input_audio'] -%}
{%- set media_type = item.type | replace('_url', '') | replace('input_', '') -%}
{{- "You are unable to process this " ~ media_type ~ " because you don't have multi-modal input ability. Try different methods." }}
{%- endif -%}
{%- endfor -%}
{%- else -%}
{{- content }}
{%- endif -%}
{%- endmacro -%}
{%- set ns = namespace(last_user_index=-1) -%}
{%- for m in messages %}
{%- if m.role == 'user' %}
{%- set ns.last_user_index = loop.index0 -%}
{%- endif %}
{%- endfor %}
{%- for m in messages -%}
{%- if m.role == 'user' -%}<|user|>{{ visible_text(m.content) }}
{%- elif m.role == 'assistant' -%}
<|assistant|>
{%- set content = visible_text(m.content) %}
{%- if m.reasoning_content is string %}
{%- set reasoning_content = m.reasoning_content %}
{%- elif '' in content %}
{%- set reasoning_content = content.split('')[0].split('')[-1] %}
{%- set content = content.split('')[-1] %}
{%- endif %}
{%- if ((clear_thinking is defined and not clear_thinking) or loop.index0 > ns.last_user_index) and reasoning_content is defined -%}
{{ '' + reasoning_content + ''}}
{%- else -%}
{{ '' }}
{%- endif -%}
{%- if content.strip() -%}
{{ content.strip() }}
{%- endif -%}
{%- if m.tool_calls is defined and m.tool_calls is iterable and m.tool_calls | length > 0 %}
{{- '\n' -}}
{%- for tc in m.tool_calls -%}
{%- if tc.function is defined -%}
{%- set tc = tc.function -%}
{%- elif tc.function -%}
{%- set tc = tc.function -%}
{%- endif -%}
{{- '' ~ tc.name ~ '\n' -}}
{%- if tc.arguments is defined -%}
{%- set _args = tc.arguments -%}
{%- if _args is string -%}
{%- set _args = _args | fromjson -%}
{%- endif -%}
{%- if _args is mapping -%}
{%- for args_name, args_value in _args|items -%}
{{- ' ' ~ args_name ~ '\n' -}}
{%- set args_value = args_value | tojson | safe if args_value is mapping or (args_value is sequence and args_value is not string) else args_value | string -%}
{{- ' ' ~ args_value ~ '\n' -}}
{%- endfor -%}
{%- endif -%}
{%- endif -%}
{{- '\n' -}}
{%- endfor -%}
{%- endif -%}
{%- elif m.role == 'tool' -%}
{%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
{{- '<|observation|>' -}}
{%- endif %}
{%- if m.content is string -%}
{{- '\n' + m.content + '\n\n' -}}
{%- elif m.content is iterable and m.content is not mapping and m.content and m.content.0 is mapping and m.content.0.type is defined and m.content.0.type == "tool_reference" -%}
{{- '\n\n' -}}
{%- for tr in m.content -%}
{%- for tool in tools -%}
{%- if tool.function is defined -%}
{%- set tool = tool.function -%}
{%- elif 'function' in tool -%}
{%- set tool = tool['function'] -%}
{%- endif -%}
{%- if tool.name == tr.name -%}
{{- '\n' ~ tool.name ~ '\n\n' -}}
{%- endif -%}
{%- endfor -%}
{%- endfor -%}
{{- '\n\n' -}}
{%- elif m.content is iterable and m.content is not mapping and m.content and m.content.0 is mapping and m.content.0.output is defined -%}
{%- for tr in m.content -%}
{{- '\n' + tr.output + '\n\n' -}}
{%- endfor -%}
{%- else -%}
{{- '\n' + visible_text(m.content) + '\n\n' -}}
{%- endif -%}
{%- elif m.role == 'system' -%}
<|system|>{{ visible_text(m.content) }}
{%- endif -%}
{%- endfor -%}
{%- if add_generation_prompt -%}
<|assistant|>{{- '' if (enable_thinking is defined and not enable_thinking) else '' -}}
{%- endif -%}