m-ric HF Staff commited on
Commit
a169fa4
·
verified ·
1 Parent(s): 2ea4d77

Update chat_template.jinja

Browse files
Files changed (1) hide show
  1. chat_template.jinja +21 -26
chat_template.jinja CHANGED
@@ -41,32 +41,29 @@
41
  {%- else -%}
42
  {{- "You are a helpful AI assistant named SmolLM, trained by Hugging Face.\n\n" -}}
43
  {%- endif -%}
44
-
45
- {{- "## Tools\n\n" -}}
46
- {{- "### XML Tools\n\n" -}}
47
- {%- if tools -%}
48
- {%- 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") -%}
49
- {%- for tool in tools -%}
50
- {%- set ns.xml_tool_string = ns.xml_tool_string ~ (tool | tojson) ~ "\n" -%}
51
- {%- endfor -%}
52
- {%- 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." -%}
53
- {%- endif -%}
54
- {%- if xml_tools -%}
55
- {{- xml_tools -}}
56
- {%- else -%}
57
- {{- "None" -}}
58
- {%- endif -%}
59
- {{- "\n\n" -}}
60
- {{- "### Python Tools\n\n" -}}
61
- {%- if python_tools -%}
62
- {{- python_tools -}}
63
- {%- else -%}
64
- {{- "None" -}}
65
  {%- endif -%}
66
- {{- "\n\n" -}}
67
- {{- "<|im_end|>\n" -}}
68
  {%- endif -%}
69
-
70
  {# ───── main loop ───── #}
71
  {%- for message in messages -%}
72
  {%- set content = message.content if message.content is string else "" -%}
@@ -80,12 +77,10 @@
80
  {{ "<|im_start|>assistant\n" + "<think>\n\n</think>\n" + content.lstrip("\n") + "<|im_end|>\n" }}
81
  {%- endif -%}
82
  {% endgeneration %}
83
-
84
  {%- elif message.role == "tool" -%}
85
  {{ "<|im_start|>" + "user\n" + content + "<|im_end|>\n" }}
86
  {%- endif -%}
87
  {%- endfor -%}
88
-
89
  {# ───── generation prompt ───── #}
90
  {%- if add_generation_prompt -%}
91
  {%- if reasoning_mode == "/think" -%}
 
41
  {%- else -%}
42
  {{- "You are a helpful AI assistant named SmolLM, trained by Hugging Face.\n\n" -}}
43
  {%- endif -%}
44
+
45
+ {%- if xml_tools or python_tools -%}
46
+ {{- "### Tools\n\n" -}}
47
+ {%- if xml_tools -%}
48
+ {%- set ns = namespace(xml_tool_string="You may call one or more functions to assist with the user query.\nYou are provided with function signatures within <tools></tools> XML tags:\n\n<tools>\n") -%}
49
+ {%- for tool in xml_tools[:] -%} {# The slicing makes sure that xml_tools is a list #}
50
+ {%- set ns.xml_tool_string = ns.xml_tool_string ~ (tool | string) ~ "\n" -%}
51
+ {%- endfor -%}
52
+ {%- set xml_tool_string = 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:\n<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call>" -%}
53
+ {{- xml_tool_string -}}
54
+ {%- endif -%}
55
+ {%- if python_tools -%}
56
+ {%- set ns = namespace(python_tool_string="When you send a message containing Python code between '<code>' and '</code>' tags, it will be executed in a stateful Jupyter notebook environment, and you will then be given the output to continued reasoning in an agentic loop.\n\nYou can use the following tools in your python code like regular functions:\n<tools>\n") -%}
57
+ {%- for tool in python_tools[:] -%} {# The slicing makes sure that python_tools is a list #}
58
+ {%- set ns.python_tool_string = ns.python_tool_string ~ (tool | string) ~ "\n" -%}
59
+ {%- endfor -%}
60
+ {%- set python_tool_string = ns.python_tool_string + "</tools>\n\nThe state persists between code executions: so variables that you define in one step are still available thereafter." -%}
61
+ {{- python_tool_string -}}
62
+ {%- endif -%}
63
+ {{- "\n\n" -}}
64
+ {{- "<|im_end|>\n" -}}
65
  {%- endif -%}
 
 
66
  {%- endif -%}
 
67
  {# ───── main loop ───── #}
68
  {%- for message in messages -%}
69
  {%- set content = message.content if message.content is string else "" -%}
 
77
  {{ "<|im_start|>assistant\n" + "<think>\n\n</think>\n" + content.lstrip("\n") + "<|im_end|>\n" }}
78
  {%- endif -%}
79
  {% endgeneration %}
 
80
  {%- elif message.role == "tool" -%}
81
  {{ "<|im_start|>" + "user\n" + content + "<|im_end|>\n" }}
82
  {%- endif -%}
83
  {%- endfor -%}
 
84
  {# ───── generation prompt ───── #}
85
  {%- if add_generation_prompt -%}
86
  {%- if reasoning_mode == "/think" -%}