{#- Penny chat template: the exact format Penny's SFT stages train on (penny.data_mix.encode_chat). <|end▁of▁sentence|>{system}<|User|>{user}<|Assistant|>…{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 "" in front of its reply. Reasoning can come inside the content ("…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 "" (thinking mode, the default), so the model always reasons first. enable_thinking=false opens it with "" 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|>' + m['reasoning_content'] + '' + content + '<|end▁of▁sentence|>' -}} {%- elif (content | trim).startswith('') -%} {{- '<|Assistant|>' + content + '<|end▁of▁sentence|>' -}} {%- else -%} {{- '<|Assistant|>' + 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|>' -}} {%- else -%} {{- '<|Assistant|>' -}} {%- endif -%} {%- endif -%}