Update chat_template.jinja
Browse files- chat_template.jinja +18 -4
chat_template.jinja
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
{#-
|
| 2 |
In addition to the normal inputs of `messages` and `tools`, this template also accepts the
|
| 3 |
following kwargs:
|
|
@@ -204,7 +205,7 @@
|
|
| 204 |
{%- set reasoning_effort = "medium" %}
|
| 205 |
{%- endif %}
|
| 206 |
{{- "Reasoning: " + reasoning_effort + "\n\n" }}
|
| 207 |
-
{%- if builtin_tools
|
| 208 |
{{- "# Tools\n\n" }}
|
| 209 |
{%- set available_builtin_tools = namespace(browser=false, python=false) %}
|
| 210 |
{%- for tool in builtin_tools %}
|
|
@@ -301,7 +302,11 @@
|
|
| 301 |
{{- "<|start|>assistant to=" }}
|
| 302 |
{{- "functions." + tool_call.name + "<|channel|>commentary " }}
|
| 303 |
{{- (tool_call.content_type if tool_call.content_type is defined else "json") + "<|message|>" }}
|
| 304 |
-
{
|
|
|
|
|
|
|
|
|
|
|
|
|
| 305 |
{{- "<|call|>" }}
|
| 306 |
{%- set last_tool_call.name = tool_call.name %}
|
| 307 |
{%- elif loop.last and not add_generation_prompt %}
|
|
@@ -314,6 +319,10 @@
|
|
| 314 |
{#- <|return|> should never be an input to the model, but we include it as the final token #}
|
| 315 |
{#- when training, so the model learns to emit it. #}
|
| 316 |
{{- "<|start|>assistant<|channel|>final<|message|>" + message.content + "<|end|>" }}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 317 |
{%- else %}
|
| 318 |
{#- CoT is dropped during all previous turns, so we never render it for inference #}
|
| 319 |
{{- "<|start|>assistant<|channel|>final<|message|>" + message.content + "<|end|>" }}
|
|
@@ -324,7 +333,11 @@
|
|
| 324 |
{{- raise_exception("Message has tool role, but there was no previous assistant message with a tool call!") }}
|
| 325 |
{%- endif %}
|
| 326 |
{{- "<|start|>functions." + last_tool_call.name }}
|
| 327 |
-
{
|
|
|
|
|
|
|
|
|
|
|
|
|
| 328 |
{%- elif message.role == 'user' -%}
|
| 329 |
{{- "<|start|>user<|message|>" + message.content + "<|end|>" }}
|
| 330 |
{%- endif -%}
|
|
@@ -333,4 +346,5 @@
|
|
| 333 |
{#- Generation prompt #}
|
| 334 |
{%- if add_generation_prompt -%}
|
| 335 |
<|start|>assistant
|
| 336 |
-
{%- endif -%}
|
|
|
|
|
|
| 1 |
+
{# Chat template fixes by Unsloth #}
|
| 2 |
{#-
|
| 3 |
In addition to the normal inputs of `messages` and `tools`, this template also accepts the
|
| 4 |
following kwargs:
|
|
|
|
| 205 |
{%- set reasoning_effort = "medium" %}
|
| 206 |
{%- endif %}
|
| 207 |
{{- "Reasoning: " + reasoning_effort + "\n\n" }}
|
| 208 |
+
{%- if builtin_tools %}
|
| 209 |
{{- "# Tools\n\n" }}
|
| 210 |
{%- set available_builtin_tools = namespace(browser=false, python=false) %}
|
| 211 |
{%- for tool in builtin_tools %}
|
|
|
|
| 302 |
{{- "<|start|>assistant to=" }}
|
| 303 |
{{- "functions." + tool_call.name + "<|channel|>commentary " }}
|
| 304 |
{{- (tool_call.content_type if tool_call.content_type is defined else "json") + "<|message|>" }}
|
| 305 |
+
{%- if tool_call.arguments is string %}
|
| 306 |
+
{{- tool_call.arguments }}
|
| 307 |
+
{%- else %}
|
| 308 |
+
{{- tool_call.arguments|tojson }}
|
| 309 |
+
{%- endif %}
|
| 310 |
{{- "<|call|>" }}
|
| 311 |
{%- set last_tool_call.name = tool_call.name %}
|
| 312 |
{%- elif loop.last and not add_generation_prompt %}
|
|
|
|
| 319 |
{#- <|return|> should never be an input to the model, but we include it as the final token #}
|
| 320 |
{#- when training, so the model learns to emit it. #}
|
| 321 |
{{- "<|start|>assistant<|channel|>final<|message|>" + message.content + "<|end|>" }}
|
| 322 |
+
{%- elif "thinking" in message %}
|
| 323 |
+
{#- CoT is dropped during all previous turns, so we never render it for inference #}
|
| 324 |
+
{{- "<|start|>assistant<|channel|>analysis<|message|>" + message.content + "<|end|>" }}
|
| 325 |
+
{%- set last_tool_call.name = none %}
|
| 326 |
{%- else %}
|
| 327 |
{#- CoT is dropped during all previous turns, so we never render it for inference #}
|
| 328 |
{{- "<|start|>assistant<|channel|>final<|message|>" + message.content + "<|end|>" }}
|
|
|
|
| 333 |
{{- raise_exception("Message has tool role, but there was no previous assistant message with a tool call!") }}
|
| 334 |
{%- endif %}
|
| 335 |
{{- "<|start|>functions." + last_tool_call.name }}
|
| 336 |
+
{%- if message.content is string %}
|
| 337 |
+
{{- " to=assistant<|channel|>commentary<|message|>" + message.content + "<|end|>" }}
|
| 338 |
+
{%- else %}
|
| 339 |
+
{{- " to=assistant<|channel|>commentary<|message|>" + message.content|tojson + "<|end|>" }}
|
| 340 |
+
{%- endif %}
|
| 341 |
{%- elif message.role == 'user' -%}
|
| 342 |
{{- "<|start|>user<|message|>" + message.content + "<|end|>" }}
|
| 343 |
{%- endif -%}
|
|
|
|
| 346 |
{#- Generation prompt #}
|
| 347 |
{%- if add_generation_prompt -%}
|
| 348 |
<|start|>assistant
|
| 349 |
+
{%- endif -%}
|
| 350 |
+
{# Copyright 2025-present Unsloth. Apache 2.0 License. Unsloth chat template fixes. Edited from ggml-org & OpenAI #}
|