Update chat_template.jinja
Browse files- chat_template.jinja +28 -87
chat_template.jinja
CHANGED
@@ -1,87 +1,28 @@
|
|
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 |
-
{%- for tool in tools %}
|
30 |
-
{%- set tool = tool.function %}
|
31 |
-
{{- '{"type": "function", "function": {' }}
|
32 |
-
{%- for key, val in tool.items() if key != "return" %}
|
33 |
-
{%- if val is string %}
|
34 |
-
{{- '"' + key + '": "' + val + '"' }}
|
35 |
-
{%- else %}
|
36 |
-
{{- '"' + key + '": ' + val|tojson }}
|
37 |
-
{%- endif %}
|
38 |
-
{%- if not loop.last %}
|
39 |
-
{{- ", " }}
|
40 |
-
{%- endif %}
|
41 |
-
{%- endfor %}
|
42 |
-
{{- "}}" }}
|
43 |
-
{%- if not loop.last %}
|
44 |
-
{{- ", " }}
|
45 |
-
{%- else %}
|
46 |
-
{{- "]" }}
|
47 |
-
{%- endif %}
|
48 |
-
{%- endfor %}
|
49 |
-
{{- "[/AVAILABLE_TOOLS]" }}
|
50 |
-
{%- endif %}
|
51 |
-
{%- if loop.last and system_message is defined %}
|
52 |
-
{{- "[INST]" + system_message + "\n\n" + message["content"] + "[/INST]" }}
|
53 |
-
{%- else %}
|
54 |
-
{{- "[INST]" + message["content"] + "[/INST]" }}
|
55 |
-
{%- endif %}
|
56 |
-
{%- elif (message.tool_calls is defined and message.tool_calls is not none) %}
|
57 |
-
{{- "[TOOL_CALLS][" }}
|
58 |
-
{%- for tool_call in message.tool_calls %}
|
59 |
-
{%- set out = tool_call.function|tojson %}
|
60 |
-
{{- out[:-1] }}
|
61 |
-
{%- if not tool_call.id is defined or tool_call.id|length != 9 %}
|
62 |
-
{{- raise_exception("Tool call IDs should be alphanumeric strings with length 9!") }}
|
63 |
-
{%- endif %}
|
64 |
-
{{- ', "id": "' + tool_call.id + '"}' }}
|
65 |
-
{%- if not loop.last %}
|
66 |
-
{{- ", " }}
|
67 |
-
{%- else %}
|
68 |
-
{{- "]" + eos_token }}
|
69 |
-
{%- endif %}
|
70 |
-
{%- endfor %}
|
71 |
-
{%- elif message["role"] == "assistant" %}
|
72 |
-
{{- message["content"] + eos_token}}
|
73 |
-
{%- elif message["role"] == "tool_results" or message["role"] == "tool" %}
|
74 |
-
{%- if message.content is defined and message.content.content is defined %}
|
75 |
-
{%- set content = message.content.content %}
|
76 |
-
{%- else %}
|
77 |
-
{%- set content = message.content %}
|
78 |
-
{%- endif %}
|
79 |
-
{{- '[TOOL_RESULTS]{"content": ' + content|string + ", " }}
|
80 |
-
{%- if not message.tool_call_id is defined or message.tool_call_id|length != 9 %}
|
81 |
-
{{- raise_exception("Tool call IDs should be alphanumeric strings with length 9!") }}
|
82 |
-
{%- endif %}
|
83 |
-
{{- '"call_id": "' + message.tool_call_id + '"}[/TOOL_RESULTS]' }}
|
84 |
-
{%- else %}
|
85 |
-
{{- raise_exception("Only user and assistant roles are supported, with the exception of an initial optional system message!") }}
|
86 |
-
{%- endif %}
|
87 |
-
{%- endfor %}
|
|
|
1 |
+
{{- bos_token -}}
|
2 |
+
{%- for message in messages -%}
|
3 |
+
{%- if (message["role"] == "user") == (loop.index % 2 == 0) -%}
|
4 |
+
{{- raise_exception("After the optional system message, conversation roles must alternate user/assistant/user/assistant/...") -}}
|
5 |
+
{%- endif -%}
|
6 |
+
{%- if message["role"] == "user" -%}
|
7 |
+
{{- "[INST]" -}}
|
8 |
+
{%- if message["content"] is string -%}
|
9 |
+
{{- message["content"] -}}
|
10 |
+
{%- else -%}
|
11 |
+
{%- for item in message["content"] -%}
|
12 |
+
{%- if item["type"] == "audio" -%}
|
13 |
+
{{- "[AUDIO]" -}}
|
14 |
+
{%- elif item["type"] == "text" -%}
|
15 |
+
{{- item["text"] -}}
|
16 |
+
{%- endif -%}
|
17 |
+
{%- endfor -%}
|
18 |
+
{%- endif -%}
|
19 |
+
{{- "[/INST]" -}}
|
20 |
+
{%- elif message["role"] == "assistant" -%}
|
21 |
+
{%- if message["content"] is not string -%}
|
22 |
+
{{- raise_exception("Assistant message content should be a string.") -}}
|
23 |
+
{%- endif -%}
|
24 |
+
{{- message["content"] + eos_token -}}
|
25 |
+
{%- else -%}
|
26 |
+
{{- raise_exception("Only user and assistant roles are supported!") -}}
|
27 |
+
{%- endif -%}
|
28 |
+
{%- endfor -%}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|