step3 / chat_template.json
buyun's picture
Add files using upload-large-folder tool
4ad74b5 verified
{
"chat_template": "{% macro render_content(content) %} {% if content is string %}{{- content }}{% elif content is mapping %}{{- content['value'] if 'value' in content else content['text'] }}{% elif content is iterable %}{% for item in content %}{% if item.type == 'text' %}{{- item['value'] if 'value' in item else item['text'] }}{% elif item.type == 'image' %}<im_patch>{% endif %}{% endfor %}{% endif %} {% endmacro %}{% if not add_generation_prompt is defined %}{% set add_generation_prompt = false %}{% endif %}{{ bos_token }}{% for message in messages %}{% if message.role == 'system' %}{{ render_content(message['content']) }}{% endif %}{% endfor %}{% if tools is defined and tools %}{% set ns = namespace(data='') %}{% for tool in tools %}{% set ns.data = ns.data + (tool | tojson(ensure_ascii=False)) + '\n' %}{% endfor %}{% set tool_schemas_var = ns.data %}# Tools \nYou may call one or more tools to assist with the user query. You are provided with tool schemas within <tools></tools> XML tags: <tools>{{ tool_schemas_var }}</tools> When making tool calls, use XML format to invoke tools and pass parameters: <|tool_calls_begin|>\n<|tool_call_begin|>\nfunction<|tool_sep|><steptml:invoke name=\"tool_name0\"><steptml:parameter name=\"parameter_name0\">[parameter value]</steptml:parameter>...</steptml:invoke><|tool_call_end|>\n<|tool_call_begin|>\nfunction<|tool_sep|><steptml:invoke name=\"tool_name1\"><steptml:parameter name=\"parameter_name1\">[parameter value]</steptml:parameter>...</steptml:invoke><|tool_call_end|>\n<|tool_calls_end|>\nNote: * You can invoke one or more tools in parallel. * Each tool call must be complete and self-contained within a single <steptml:toolcall></steptml:toolcall> block. {% endif %}{% for message in messages %}{% if message.role == 'tool_description' %}{{ render_content(message['content']) }}{% elif message.role == 'user' %}{{- '<|BOT|>' + message.role + '\\n' + render_content(message['content']) }}{{- '<|EOT|>' }}{% elif message.role == 'tool_response' %}<|tool_outputs_begin|>\n{% for tool_output in message['content'] %}<|tool_output_begin|>\n{{ render_content(tool_output) }}<|tool_output_end|>{% endfor %}\n<|tool_outputs_end|>\n{% else %}{{- '<|BOT|>' + message.role + '\n' }}{% if message['content'] is defined %}{{- render_content(message['content']) }}{% endif %}{% if message.tool_calls is defined %}<|tool_calls_begin|>\n{% for tool in message.tool_calls %}<|tool_call_begin>|>\n{{ tool['type'] }}<|tool_sep|>{{- '<steptml:invoke name=\"' + tool['function']['name'] + '\">' }}{% for name, param in tool['function']['arguments'].items() %} {{- '<steptml:parameter name=\"' + name + '\">' + param | string + '</steptml:parameter>' }}{% endfor %}</steptml:invoke><|tool_call_end|>\n{% endfor %}<|tool_calls_end|>\n{% endif %}<|EOT|>{% endif %}{% endfor %}{% if add_generation_prompt %}{{- '<|BOT|>assistant\n<think>\n' }}{% endif %}"
}