File size: 1,200 Bytes
a4bd9d4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
{{- bos_token }}

{# --- Extract system message (optional) --- #}
{%- if messages and messages[0]['role'] == 'system' %}
  {%- set system_message = messages[0]['content'] | trim %}
  {%- set messages = messages[1:] %}
{%- else %}
  {%- set system_message = "Respond with your reasoning wrapped in <think>...</think>, then provide the final answer within \\\\boxed{}." %}
{%- endif %}

{# --- System block --- #}
{{- "<|start_header_id|>system<|end_header_id|>\n\n" }}
{{- system_message }}
{{- "<|eot_id|>" }}

{# --- Render all remaining messages --- #}
{%- for message in messages %}
  {%- if message['role'] in ['system', 'user', 'assistant'] %}
    {%- if message['role'] == 'assistant' %}
      {{- "<|start_header_id|>assistant<|end_header_id|>\n\n" }}
      {%- generation %}
      {{- message['content'] | trim }}
      {%- endgeneration %}
      {{- "<|eot_id|>" }}
    {%- else %}
      {{- "<|start_header_id|>" + message['role'] + "<|end_header_id|>\n\n" + (message['content'] | trim) + "<|eot_id|>" }}
    {%- endif %}
  {%- endif %}
{%- endfor %}

{# --- Generation prompt --- #}
{%- if add_generation_prompt %}
  {{- "<|start_header_id|>assistant<|end_header_id|>\n\n" }}
{%- endif %}