Wrap assistant messages inside "{% generation %}" markers in chat_template.jinja
#126
by
daohanlu
- opened
- chat_template.jinja +24 -17
chat_template.jinja
CHANGED
@@ -288,30 +288,37 @@
|
|
288 |
{%- endif %}
|
289 |
{%- if message.content and message.thinking %}
|
290 |
{{- raise_exception("Cannot pass both content and thinking in an assistant message with tool calls! Put the analysis message in one or the other, but not both.") }}
|
291 |
-
{%- elif message.content and not future_final_message.found %}
|
292 |
-
{{- "<|start|>assistant<|channel|>analysis<|message|>" + message.content + "<|end|>" }}
|
293 |
-
{%- elif message.thinking and not future_final_message.found %}
|
294 |
-
{{- "<|start|>assistant<|channel|>analysis<|message|>" + message.thinking + "<|end|>" }}
|
295 |
{%- endif %}
|
296 |
-
{
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
301 |
{%- set last_tool_call.name = tool_call.name %}
|
302 |
{%- elif loop.last and not add_generation_prompt %}
|
303 |
{#- Only render the CoT if the final turn is an assistant turn and add_generation_prompt is false #}
|
304 |
{#- This is a situation that should only occur in training, never in inference. #}
|
305 |
-
{
|
306 |
-
{
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
|
|
|
|
312 |
{%- else %}
|
313 |
{#- CoT is dropped during all previous turns, so we never render it for inference #}
|
314 |
-
{
|
|
|
|
|
315 |
{%- set last_tool_call.name = none %}
|
316 |
{%- endif %}
|
317 |
{%- elif message.role == 'tool' -%}
|
|
|
288 |
{%- endif %}
|
289 |
{%- if message.content and message.thinking %}
|
290 |
{{- raise_exception("Cannot pass both content and thinking in an assistant message with tool calls! Put the analysis message in one or the other, but not both.") }}
|
|
|
|
|
|
|
|
|
291 |
{%- endif %}
|
292 |
+
{% generation %}
|
293 |
+
{%- if message.content and not future_final_message.found %}
|
294 |
+
{{- "<|start|>assistant<|channel|>analysis<|message|>" + message.content + "<|end|>" }}
|
295 |
+
{%- elif message.thinking and not future_final_message.found %}
|
296 |
+
{{- "<|start|>assistant<|channel|>analysis<|message|>" + message.thinking + "<|end|>" }}
|
297 |
+
{%- endif %}
|
298 |
+
{{- "<|start|>assistant to=" }}
|
299 |
+
{{- "functions." + tool_call.name + "<|channel|>commentary " }}
|
300 |
+
{{- (tool_call.content_type if tool_call.content_type is defined else "json") + "<|message|>" }}
|
301 |
+
{{- tool_call.arguments|tojson }}
|
302 |
+
{{- "<|call|>" }}
|
303 |
+
{% endgeneration %}
|
304 |
{%- set last_tool_call.name = tool_call.name %}
|
305 |
{%- elif loop.last and not add_generation_prompt %}
|
306 |
{#- Only render the CoT if the final turn is an assistant turn and add_generation_prompt is false #}
|
307 |
{#- This is a situation that should only occur in training, never in inference. #}
|
308 |
+
{% generation %}
|
309 |
+
{%- if "thinking" in message %}
|
310 |
+
{{- "<|start|>assistant<|channel|>analysis<|message|>" + message.thinking + "<|end|>" }}
|
311 |
+
{%- endif %}
|
312 |
+
{#- <|return|> indicates the end of generation, but <|end|> does not #}
|
313 |
+
{#- <|return|> should never be an input to the model, but we include it as the final token #}
|
314 |
+
{#- when training, so the model learns to emit it. #}
|
315 |
+
{{- "<|start|>assistant<|channel|>final<|message|>" + message.content + "<|return|>" }}
|
316 |
+
{% endgeneration %}
|
317 |
{%- else %}
|
318 |
{#- CoT is dropped during all previous turns, so we never render it for inference #}
|
319 |
+
{% generation %}
|
320 |
+
{{- "<|start|>assistant<|channel|>final<|message|>" + message.content + "<|end|>" }}
|
321 |
+
{% endgeneration %}
|
322 |
{%- set last_tool_call.name = none %}
|
323 |
{%- endif %}
|
324 |
{%- elif message.role == 'tool' -%}
|