Update chat_template.jinja
Browse files- chat_template.jinja +57 -4
chat_template.jinja
CHANGED
@@ -1,4 +1,57 @@
|
|
1 |
-
{{bos_token}}{%
|
2 |
-
|
3 |
-
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{{bos_token}}{% if messages[0]['role'] == 'system' %}
|
2 |
+
{%- set system_message = messages[0]['content'] %}
|
3 |
+
{%- set loop_messages = messages[1:] %}
|
4 |
+
{%- else %}
|
5 |
+
{%- set system_message = 'You are a helpful assistant trained by Liquid AI.' %}
|
6 |
+
{%- set loop_messages = messages %}
|
7 |
+
{%- endif %}
|
8 |
+
{%- if tools %}
|
9 |
+
{%- set system_message = system_message + '\nList of tools: <|tool_list_start|>' + (tools | tojson) + '<|tool_list_end|>' %}
|
10 |
+
{%- endif %}
|
11 |
+
{{- '<|im_start|>system\n' + system_message + '<|im_end|>\n'}}
|
12 |
+
{%- for message in loop_messages %}
|
13 |
+
{%- if message['role'] == 'user' %}
|
14 |
+
{{- '<|im_start|>user\n' + message['content'] + '<|im_end|>\n'}}
|
15 |
+
{%- elif message['role'] == 'assistant' %}
|
16 |
+
{{- '<|im_start|>assistant\n'}}
|
17 |
+
{%- if message.get('tool_calls') %}
|
18 |
+
{# ───── create a list to append tool calls to ───── #}
|
19 |
+
{%- set tool_calls_ns = namespace(tool_calls=[])%}
|
20 |
+
{%- for tool_call in message['tool_calls'] %}
|
21 |
+
{%- set func_name = tool_call['function']['name'] %}
|
22 |
+
{%- set func_args = tool_call['function']['arguments'] %}
|
23 |
+
{# ───── create a list of func_arg strings to accumulate for each tool call ───── #}
|
24 |
+
{%- set args_ns = namespace(arg_strings=[])%}
|
25 |
+
{%- for arg_name, arg_value in func_args.items() %}
|
26 |
+
{%- set formatted_arg_value = arg_value %}
|
27 |
+
{%- if arg_value is string %}
|
28 |
+
{%- set formatted_arg_value = '"' + arg_value + '"' %}
|
29 |
+
{%- elif arg_value is mapping %}
|
30 |
+
{%- set formatted_arg_value = arg_value | tojson %}
|
31 |
+
{%- elif arg_value is iterable %}
|
32 |
+
{%- set formatted_arg_value = '[' + arg_value + ']' %}
|
33 |
+
{%- endif %}
|
34 |
+
{# ───── format each argument key,value pair ───── #}
|
35 |
+
{%- set args_ns.arg_strings = args_ns.arg_strings + [(arg_name + '=' + formatted_arg_value)] %}
|
36 |
+
{%- endfor %}
|
37 |
+
{# ───── append each formatted tool call ───── #}
|
38 |
+
{%- set tool_calls_ns.tool_calls = tool_calls_ns.tool_calls + [(func_name + '(' + (args_ns.arg_strings | join(",")) + ')' )]%}
|
39 |
+
{%- endfor %}
|
40 |
+
{# ───── format the final tool calls ───── #}
|
41 |
+
{{-'<|tool_call_start|>[' + (tool_calls_ns.tool_calls | join(",")) + ']<|tool_call_end|>'}}
|
42 |
+
{%- if message['content'] %}
|
43 |
+
{{-message['content']}}
|
44 |
+
{%- endif %}
|
45 |
+
{%- else %}
|
46 |
+
{{-message['content']}}
|
47 |
+
{%- endif %}
|
48 |
+
{{-'<|im_end|>\n'}}
|
49 |
+
{%- elif message['role'] == 'tool' %}
|
50 |
+
{{-'<|im_start|>tool\n<|tool_response_start|>' + message['content'] + '<|tool_response_end|><|im_end|>\n'}}
|
51 |
+
{%- elif message['role'] == 'system' %}
|
52 |
+
{{-'<|im_start|>system\n' + message['content'] + '<|im_end|>\n'}}
|
53 |
+
{%- endif %}
|
54 |
+
{%- endfor %}
|
55 |
+
{%- if add_generation_prompt %}
|
56 |
+
{{-'<|im_start|>assistant\n'}}
|
57 |
+
{%- endif %}
|