Django/Jinja · 646 bytes Raw Blame History
1 {#
2 ChatML reference template used by Qwen 2.5, SmolLM2, and compatible
3 models. Source-of-truth for Go `text/template` round-trip tests:
4 rendering these messages through this Jinja and the Go template must
5 produce token-identical sequences after tokenization.
6
7 Render `{"messages": [...]}` where each message has `role` in
8 {"system", "user", "assistant"} and a `content` string. Call with
9 `add_generation_prompt=True` to append the trailing assistant cue.
10 #}
11 {%- for message in messages -%}
12 <|im_start|>{{ message['role'] }}
13 {{ message['content'] }}<|im_end|>
14 {% endfor -%}
15 {%- if add_generation_prompt -%}
16 <|im_start|>assistant
17 {%- endif -%}
18