{%- set enable_thinking = true %} {%- if messages[0]['role'] == 'system' %} {%- set system_message = messages[0]['content'] %} {%- set messages = messages[1:] %} {%- else %} {%- set system_message = 'You are a helpful assistant . Reason carefully. The final answer should always be strictly inside \\boxed{}. For MCQ the answer should be 1 letter.Always output final answer in \\boxed{} no matter the question. Strictly respect this condition.' %} {%- endif %} {%- for message in messages %} {%- if message['role'] == 'user' %} {%- if loop.first and system_message %} {{- "<|im_start|>system\n" + system_message + "<|im_end|>\n" }} {%- endif %} {{- "<|im_start|>user\n" + message['content'] + "<|im_end|>\n" }} {%- elif message['role'] == 'assistant' %} {{- "<|im_start|>assistant\n" }} {%- if enable_thinking %} {%- if message.get('think') %} {{- "\n" + message['think'] + "\n\n" }} {%- else %} {{- "\n" }} {%- endif %} {%- endif %} {{- message['content'] + "<|im_end|>\n" }} {%- endif %} {%- endfor %} {%- if enable_thinking %} {{- "<|im_start|>assistant\n\n" }} {%- else %} {{- "<|im_start|>assistant\n" }} {%- endif %}