Wrap assistant messages inside "{% generation %}" markers in chat_template.jinja

#126
Files changed (1) hide show
  1. 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
- {{- "<|start|>assistant to=" }}
297
- {{- "functions." + tool_call.name + "<|channel|>commentary " }}
298
- {{- (tool_call.content_type if tool_call.content_type is defined else "json") + "<|message|>" }}
299
- {{- tool_call.arguments|tojson }}
300
- {{- "<|call|>" }}
 
 
 
 
 
 
 
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
- {%- if "thinking" in message %}
306
- {{- "<|start|>assistant<|channel|>analysis<|message|>" + message.thinking + "<|end|>" }}
307
- {%- endif %}
308
- {#- <|return|> indicates the end of generation, but <|end|> does not #}
309
- {#- <|return|> should never be an input to the model, but we include it as the final token #}
310
- {#- when training, so the model learns to emit it. #}
311
- {{- "<|start|>assistant<|channel|>final<|message|>" + message.content + "<|return|>" }}
 
 
312
  {%- else %}
313
  {#- CoT is dropped during all previous turns, so we never render it for inference #}
314
- {{- "<|start|>assistant<|channel|>final<|message|>" + message.content + "<|end|>" }}
 
 
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' -%}