1= """{% if tools_grammar %}
2 {{- '<|im_start|>assistant\n' }}
3 {{- 'You are an AI assistant that outputs in JSON format. Think about your tools, your previous data and your next step. Available tools are:' }}
4 {% for tool in tools_grammar %}
5 {% if not loop.last %}
6 {{- tool }}
7 {% else %}
8 {{- tool + '<|im_end|>' }}
9 {% endif %}
10 {% endfor %}
11{% endif %}
12
13{% for message in messages %}
14 {% if (loop.last and add_generation_prompt) or not loop.last %}
15 {{- '<|im_start|>' + message['role'] + '\n' + message['content'] + '<|im_end|>\n' }}
16 {% else %}
17 {{- '<|im_start|>' + message['role'] + '\n' + message['content'] }}
18 {% endif %}
19{% endfor %}
20{% if add_generation_prompt and messages[-1]['role'] != 'assistant' %}
21 {{- '<|im_start|>assistant' }}
22{% endif %}
23"""