SmolVLM-Instruct / chat_template.json
mjschock's picture
Upload model trained with Unsloth
db18629 verified
{
"chat_template": "{%- set config = namespace(has_system_message=false, has_tools=false) -%}{%- set system_messages = messages | selectattr('role', 'equalto', 'system') | list -%}{%- set config.has_system_message = system_messages | length > 0 -%}{%- set config.has_tools = tools is not none and tools | length > 0 -%}{%- if not config.has_system_message -%}{%- set messages = [{ \"content\": \"You are an AI agent acting as a human assistant.\", \"role\": \"system\" }] + messages -%}{%- endif -%}{%- for message in messages -%}{% if loop.first %}{{ bos_token }}{% endif %}{{ message.role | capitalize }}:{{ ' ' }}{%- if message.role == 'system' -%}{{ message.content }}{%- if config.has_tools -%}{{ '\n\n' }}You are aware of the following tools in your environment:\n{\n \"tools\": [\n {% for tool in tools %}\n {\n \"function\": {\n \"description\": \"{{ tool.function.description }}\",\n \"name\": \"{{ tool.function.name }}\",\n \"parameters\": {{ tool.function.parameters | tojson }}\n },\n \"type\": \"{{ tool.type }}\"\n }{% if not loop.last %},{% endif %}\n\n {% endfor %}\n ]\n}\n\nIf you would like to suggest one or more tool calls, please respond in the following format:\n{\n \"finish_reason\": \"tool_calls\",\n \"tool_calls\": [\n {\n \"arguments\": \"{\\\"parameter_name\\\": \\\"parameter_value\\\"}\",\n \"id\": \"call_id\",\n \"name\": \"tool_name\"\n }\n ]\n}\n{%- endif -%}<end_of_utterance>{{ '\n' }}{%- endif -%}{%- if message.role == 'user' -%}{% if message['content'] is string %}{{message['content']}}{% else %}{% for line in message['content'] %}{% if line['type'] == 'text' %}{{line['text']}}{% elif line['type'] in ['image', 'image_url'] %}{{ '<image>' }}{% endif %}{% endfor %}{% endif %}<end_of_utterance>{{ '\n' }}{%- endif -%}{%- if message.role == 'assistant' -%}{% generation %}{%- if message.tool_calls | default(false) -%}\n{\n \"finish_reason\": \"tool_calls\",\n \"tool_calls\": [\n {% for tool_call in message.tool_calls %}\n {\n \"arguments\": {{ tool_call.function.arguments | tojson }},\n \"id\": \"{{ tool_call.id }}\",\n \"name\": \"{{ tool_call.function.name }}\"\n }{% if not loop.last %},{% endif %}\n\n {% endfor %}\n ]\n}\n{%- else -%}{{ message.content }}{%- endif -%}{% endgeneration %}<end_of_utterance>{{ '\n' }}{%- endif -%}{%- if message.role == 'tool' -%}\n{\n \"content\": {{ message.content | tojson }},\n \"name\": \"{{ message.name }}\",\n \"tool_call_id\": \"{{ message.tool_call_id }}\"\n}\n<end_of_utterance>{{ '\n' }}{%- endif -%}{%- endfor -%}{%- if add_generation_prompt -%}Assistant:{{ ' ' }}{%- endif -%}"
}