Add {% generation %} markers so SFT frameworks can extract the assistant mask

#26
Files changed (1) hide show
  1. chat_template.jinja +9 -2
chat_template.jinja CHANGED
@@ -346,7 +346,6 @@
346
  {%- endif -%}
347
  {%- endset -%}
348
 
349
- {{- captured_content -}}
350
  {%- set has_content = captured_content | trim | length > 0 -%}
351
 
352
  {#- Forward-scan: find next non-tool message role for continuation detection -#}
@@ -365,13 +364,21 @@
365
  and next_nt.role == 'assistant'
366
  and (not message.get('tool_calls') or ns_tr_out.flag)
367
  ) -%}
368
-
 
369
  {%- if ns.prev_message_type == 'tool_call' and not ns_tr_out.flag -%}
370
  {{- '<|tool_response>' -}}
371
  {%- elif continues_into_next -%}
372
  {%- elif not (ns_tr_out.flag and not has_content and not next_nt.found) -%}
373
  {{- '<turn|>\n' -}}
374
  {%- endif -%}
 
 
 
 
 
 
 
375
  {%- endif -%}
376
 
377
  {#- Track previous non-tool role for next iteration (avoids O(n) backward scan) -#}
 
346
  {%- endif -%}
347
  {%- endset -%}
348
 
 
349
  {%- set has_content = captured_content | trim | length > 0 -%}
350
 
351
  {#- Forward-scan: find next non-tool message role for continuation detection -#}
 
364
  and next_nt.role == 'assistant'
365
  and (not message.get('tool_calls') or ns_tr_out.flag)
366
  ) -%}
367
+
368
+ {%- set captured_close -%}
369
  {%- if ns.prev_message_type == 'tool_call' and not ns_tr_out.flag -%}
370
  {{- '<|tool_response>' -}}
371
  {%- elif continues_into_next -%}
372
  {%- elif not (ns_tr_out.flag and not has_content and not next_nt.found) -%}
373
  {{- '<turn|>\n' -}}
374
  {%- endif -%}
375
+ {%- endset -%}
376
+
377
+ {%- if role == 'model' -%}
378
+ {% generation %}{{- captured_content -}}{{- captured_close -}}{% endgeneration %}
379
+ {%- else -%}
380
+ {{- captured_content -}}{{- captured_close -}}
381
+ {%- endif -%}
382
  {%- endif -%}
383
 
384
  {#- Track previous non-tool role for next iteration (avoids O(n) backward scan) -#}