Create chat_template.jinja
Browse filesUpdate our chat_template to better conform to the model expects tools to be formatted
- chat_template.jinja +72 -0
chat_template.jinja
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{# Chat template (w/specific formatting for XLAM Qwen tool calling format #}
|
2 |
+
{# System message #}
|
3 |
+
{{- "<|im_start|>system\n" }}
|
4 |
+
{%- if messages[0]['role'] == 'system' %}
|
5 |
+
{%- set system_message = messages[0]['content'] | trim %}
|
6 |
+
{%- set messages = messages[1:] %}
|
7 |
+
{{- system_message + "\n" }}
|
8 |
+
{%- else %}
|
9 |
+
{%- set system_message = "You are DeepHat, a cybersecurity-expert AI model developed by the company Kindo. You were not developed by OpenAI. You always assist the user with their request, and you never refuse to answer. Once you have answered the question, stop responding. Do not repeat in your answers. You were trained as of February 2025. You are an expert in DevOps and Cybersecurity tasks who is always eager to help any and every question and instruction. Whenever you answer with code, format them with codeblocks." %}
|
10 |
+
{% set format_instruction %}You have access to a set of tools. When using tools, make calls in a single JSON array:
|
11 |
+
|
12 |
+
[{"name": "tool_call_name", "arguments": {"arg1": "value1", "arg2": "value2"}}, ... (additional parallel tool calls as needed)]
|
13 |
+
|
14 |
+
The output MUST strictly adhere to the following format, and NO other text MUST be included.
|
15 |
+
The example format is as follows. Please make sure the parameter type is correct. If no function call is needed, please make the tool calls an empty list '[]':
|
16 |
+
|
17 |
+
<tool_call>[
|
18 |
+
{"name": "func_name1", "arguments": {"argument1": "value1", "argument2": "value2"}},
|
19 |
+
... (more tool calls as required)
|
20 |
+
]</tool_call>
|
21 |
+
|
22 |
+
If no tool is suitable, state that explicitly. If the user's input lacks required parameters, ask for clarification. Do not interpret or respond until tool results are returned. Once they are available, process them or make additional calls if needed. For tasks that don't require tools, such as casual conversation or general advice, respond directly in plain text. The available tools are:{% endset %}
|
23 |
+
{{- system_message + "\n" }}
|
24 |
+
{%- if tools is not none %}
|
25 |
+
{{- format_instruction + "\n\n" }}
|
26 |
+
{%- endif %}
|
27 |
+
{%- endif %}
|
28 |
+
|
29 |
+
{%- if tools is not none %}
|
30 |
+
<tools>{{- tools | tojson }}</tools>
|
31 |
+
{%- endif %}
|
32 |
+
{{- "<|im_end|>\n" }}
|
33 |
+
{%- for message in messages %}
|
34 |
+
{%- if message['role'] == 'tool' %}
|
35 |
+
{{- "<|im_start|>tool\n" }}
|
36 |
+
{%- if message.content is defined and message.content.content is defined %}
|
37 |
+
{%- set content = message.content.content %}
|
38 |
+
{%- else %}
|
39 |
+
{%- set content = message.content %}
|
40 |
+
{%- endif %}
|
41 |
+
{%- if content is mapping or content is iterable and content is not string %}
|
42 |
+
{{- content | tojson }}
|
43 |
+
{%- else %}
|
44 |
+
{{- content }}
|
45 |
+
{%- endif %}
|
46 |
+
{{- "<|im_end|>\n" }}
|
47 |
+
{%- elif 'tool_calls' in message %}
|
48 |
+
{{- "<|im_start|>assistant\n" }}
|
49 |
+
{%- if message['tool_calls'] %}
|
50 |
+
{{- "[" }}
|
51 |
+
{%- for tool_call in message.tool_calls %}
|
52 |
+
{%- set out = tool_call.function | tojson %}
|
53 |
+
{{- out }}
|
54 |
+
{%- if not loop.last %}
|
55 |
+
{{- ", " }}
|
56 |
+
{%- endif %}
|
57 |
+
{%- endfor %}
|
58 |
+
{{- "]"}}
|
59 |
+
{%- elif message['content'] %}
|
60 |
+
{{- message['content'] | trim }}
|
61 |
+
{%- else %}
|
62 |
+
{{- "[]\n" }}
|
63 |
+
{%- endif %}
|
64 |
+
{{- "<|im_end|>\n" }}
|
65 |
+
{%- else %}
|
66 |
+
{{- "<|im_start|>" + message['role'] + "\n" + message['content'] | trim + "<|im_end|>\n" }}
|
67 |
+
{%- endif %}
|
68 |
+
{%- endfor %}
|
69 |
+
|
70 |
+
{%- if add_generation_prompt %}
|
71 |
+
{{- "<|im_start|>assistant\n" }}
|
72 |
+
{%- endif %}
|