Last active
July 8, 2025 16:01
-
-
Save lewtun/80f7e32f6f7c015c1592109b9f0eb9ce to your computer and use it in GitHub Desktop.
SmolLM3 chat template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {# ───── defaults ───── #} | |
| {%- if enable_thinking is not defined -%} | |
| {%- set enable_thinking = true -%} | |
| {%- endif -%} | |
| {# ───── reasoning mode ───── #} | |
| {%- if enable_thinking -%} | |
| {%- set reasoning_mode = "/think" -%} | |
| {%- else -%} | |
| {%- set reasoning_mode = "/no_think" -%} | |
| {%- endif -%} | |
| {# ───── header (system message) ───── #} | |
| {{- "<|im_start|>system\n" -}} | |
| {%- if messages[0].role == "system" -%} | |
| {%- set system_message = messages[0].content -%} | |
| {%- if "/no_think" in system_message -%} | |
| {%- set reasoning_mode = "/no_think" -%} | |
| {%- elif "/think" in system_message -%} | |
| {%- set reasoning_mode = "/think" -%} | |
| {%- endif -%} | |
| {%- set custom_instructions = system_message.replace("/no_think", "").replace("/think", "").rstrip() -%} | |
| {%- endif -%} | |
| {%- if "/system_override" in system_message -%} | |
| {{- custom_instructions.replace("/system_override", "").rstrip() -}} | |
| {{- "<|im_end|>\n" -}} | |
| {%- else -%} | |
| {{- "## Metadata\n\n" -}} | |
| {{- "Knowledge Cutoff Date: June 2025\n" -}} | |
| {%- set today = strftime_now("%d %B %Y") -%} | |
| {{- "Today Date: " ~ today ~ "\n" -}} | |
| {{- "Reasoning Mode: " + reasoning_mode + "\n\n" -}} | |
| {{- "## Custom Instructions\n\n" -}} | |
| {%- if custom_instructions -%} | |
| {{- custom_instructions + "\n\n" -}} | |
| {%- elif reasoning_mode == "/think" -%} | |
| {{- "You are a helpful AI assistant named SmolLM, trained by Hugging Face. Your role as an assistant involves thoroughly exploring questions through a systematic thinking process before providing the final precise and accurate solutions. This requires engaging in a comprehensive cycle of analysis, summarizing, exploration, reassessment, reflection, backtracking, and iteration to develop well-considered thinking process. Please structure your responses into two main sections: Thought and Solution using the specified format: <think> Thought section </think> Solution section. In the Thought section, detail your reasoning process in steps. Each step should include detailed considerations such as analysing questions, summarizing relevant findings, brainstorming new ideas, verifying the accuracy of the current steps, refining any errors, and revisiting previous steps. In the Solution section, based on various attempts, explorations, and reflections from the Thought section, systematically present the final solution that you deem correct. The Solution section should be logical, accurate, and concise and detail necessary steps needed to reach the conclusion.\n\n" -}} | |
| {%- else -%} | |
| {{- "You are a helpful AI assistant named SmolLM, trained by Hugging Face.\n\n" -}} | |
| {%- endif -%} | |
| {{- "## Tools\n\n" -}} | |
| {{- "### XML Tools\n\n" -}} | |
| {%- if tools -%} | |
| {%- set ns = namespace(xml_tool_string="You may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within <tools></tools> XML tags:\n\n<tools>\n") -%} | |
| {%- for tool in tools -%} | |
| {%- set ns.xml_tool_string = ns.xml_tool_string ~ (tool | tojson) ~ "\n" -%} | |
| {%- endfor -%} | |
| {%- set xml_tools = ns.xml_tool_string + "</tools>\n\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags." -%} | |
| {%- endif -%} | |
| {%- if xml_tools -%} | |
| {{- xml_tools -}} | |
| {%- else -%} | |
| {{- "None" -}} | |
| {%- endif -%} | |
| {{- "\n\n" -}} | |
| {{- "### Python Tools\n\n" -}} | |
| {%- if python_tools -%} | |
| {{- python_tools -}} | |
| {%- else -%} | |
| {{- "None" -}} | |
| {%- endif -%} | |
| {{- "\n\n" -}} | |
| {{- "<|im_end|>\n" -}} | |
| {%- endif -%} | |
| {# ───── main loop ───── #} | |
| {%- for message in messages -%} | |
| {%- set content = message.content if message.content is string else "" -%} | |
| {%- if message.role == "user" -%} | |
| {{ "<|im_start|>" + message.role + "\n" + content + "<|im_end|>\n" }} | |
| {%- elif message.role == "assistant" -%} | |
| {% generation %} | |
| {%- if reasoning_mode == "/think" -%} | |
| {{ "<|im_start|>assistant\n" + content.lstrip("\n") + "<|im_end|>\n" }} | |
| {%- else -%} | |
| {{ "<|im_start|>assistant\n" + "<think>\n\n</think>\n" + content.lstrip("\n") + "<|im_end|>\n" }} | |
| {%- endif -%} | |
| {% endgeneration %} | |
| {%- elif message.role == "tool" -%} | |
| {{ "<|im_start|>" + "user\n" + content + "<|im_end|>\n" }} | |
| {%- endif -%} | |
| {%- endfor -%} | |
| {# ───── generation prompt ───── #} | |
| {%- if add_generation_prompt -%} | |
| {%- if reasoning_mode == "/think" -%} | |
| {{ "<|im_start|>assistant\n" }} | |
| {%- else -%} | |
| {{ "<|im_start|>assistant\n" + "<think>\n\n</think>\n" }} | |
| {%- endif -%} | |
| {%- endif -%} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment