CrowdMind commited on
Commit
39c9abe
·
verified ·
1 Parent(s): 9a26e8d

Upload chat_template.jinja

Browse files
Files changed (1) hide show
  1. chat_template.jinja +16 -0
chat_template.jinja ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {#
2
+ Chat format for the nanochat tokenizer.
3
+ The tokenizer adds <|bos|> automatically, so this template must not emit it.
4
+ A leading system message is folded into the first user turn, matching
5
+ nanochat/tokenizer.py::render_conversation.
6
+ #}
7
+ {%- set system = messages[0]['content'] if messages and messages[0]['role'] == 'system' else '' -%}
8
+ {%- set ns = namespace(first_user=true) -%}
9
+ {%- for message in messages -%}
10
+ {%- if message['role'] == 'user' -%}
11
+ {{ '<|user_start|>' }}{% if ns.first_user and system %}{{ system + '\n\n' }}{% endif %}{{ message['content'] }}{{ '<|user_end|>' }}{% set ns.first_user = false %}
12
+ {%- elif message['role'] == 'assistant' -%}
13
+ {{ '<|assistant_start|>' + message['content'] + '<|assistant_end|>' }}
14
+ {%- endif -%}
15
+ {%- endfor -%}
16
+ {%- if add_generation_prompt -%}{{ '<|assistant_start|>' }}{%- endif -%}