File size: 2,205 Bytes
cb13718
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
{#- Penny chat template: the exact format Penny's SFT stages train on (penny.data_mix.encode_chat).

    <|end▁of▁sentence|>{system}<|User|>{user}<|Assistant|><think>…</think>{reply}<|end▁of▁sentence|>

  * The conversation starts with bos_token (= <|end▁of▁sentence|>, the token Penny saw before every
    pretraining document).
  * An assistant turn without reasoning gets an empty-think marker "</think>" in front of its reply.
    Reasoning can come inside the content ("<think>…</think>reply") or in `reasoning_content`.
  * Any role other than system / user / assistant (tool, function, ...) is shown as a user turn
    "[role] content".
  * add_generation_prompt opens an assistant turn with "<think>" (thinking mode, the default), so
    the model always reasons first. enable_thinking=false opens it with "</think>" instead, for a
    direct answer. Both are single tokens, so the prompt is token-for-token what SFT trained on.
-#}
{%- macro text(c) -%}
{%- if c is string -%}{{ c }}
{%- elif c is iterable -%}{%- for p in c -%}{%- if p is mapping and p.get('type', 'text') == 'text' -%}{{ p.get('text', '') }}{%- elif p is string -%}{{ p }}{%- endif -%}{%- endfor -%}
{%- endif -%}
{%- endmacro -%}
{{- bos_token -}}
{%- for m in messages -%}
{%- set content = text(m['content']) if m.get('content') is not none else '' -%}
{%- if m['role'] == 'system' -%}
{{- content -}}
{%- elif m['role'] == 'user' -%}
{{- '<|User|>' + content -}}
{%- elif m['role'] == 'assistant' -%}
{%- if m.get('reasoning_content') -%}
{{- '<|Assistant|><think>' + m['reasoning_content'] + '</think>' + content + '<|end▁of▁sentence|>' -}}
{%- elif (content | trim).startswith('<think>') -%}
{{- '<|Assistant|>' + content + '<|end▁of▁sentence|>' -}}
{%- else -%}
{{- '<|Assistant|></think>' + content + '<|end▁of▁sentence|>' -}}
{%- endif -%}
{%- else -%}
{{- '<|User|>[' + m['role'] + '] ' + content -}}
{%- endif -%}
{%- endfor -%}
{%- if add_generation_prompt -%}
{%- if enable_thinking is defined and not enable_thinking -%}
{{- '<|Assistant|></think>' -}}
{%- else -%}
{{- '<|Assistant|><think>' -}}
{%- endif -%}
{%- endif -%}