DarwinAnim8or commited on
Commit
bc8de60
·
verified ·
1 Parent(s): b69c17c

Update chat_template.jinja

Browse files
Files changed (1) hide show
  1. chat_template.jinja +12 -80
chat_template.jinja CHANGED
@@ -1,80 +1,12 @@
1
- {%- if messages[0]["role"] == "system" %}
2
- {%- set system_message = messages[0]["content"] %}
3
- {%- set loop_messages = messages[1:] %}
4
- {{- system_message + eos_token}}
5
- {%- else %}
6
- {%- set loop_messages = messages %}
7
- {%- endif %}
8
- {%- if not tools is defined %}
9
- {%- set tools = none %}
10
- {%- endif %}
11
- {%- set user_messages = loop_messages | selectattr("role", "equalto", "user") | list %}
12
-
13
- {{- bos_token }}
14
- {%- for message in loop_messages %}
15
- {%- if message["role"] == "user" %}
16
- {{- '<|start_header_id|>user<|end_header_id|>
17
-
18
- ' }}
19
- {%- if tools is not none and (message == user_messages[-1]) %}
20
- {{- "[AVAILABLE_TOOLS][" }}
21
- {%- for tool in tools %}
22
- {%- set tool = tool.function %}
23
- {{- '{"type": "function", "function": {' }}
24
- {%- for key, val in tool.items() if key != "return" %}
25
- {%- if val is string %}
26
- {{- '"' + key + '": "' + val + '"' }}
27
- {%- else %}
28
- {{- '"' + key + '": ' + val|tojson }}
29
- {%- endif %}
30
- {%- if not loop.last %}
31
- {{- ", " }}
32
- {%- endif %}
33
- {%- endfor %}
34
- {{- "}}" }}
35
- {%- if not loop.last %}
36
- {{- ", " }}
37
- {%- else %}
38
- {{- "]" }}
39
- {%- endif %}
40
- {%- endfor %}
41
- {{- "[/AVAILABLE_TOOLS]" }}
42
- {%- endif %}
43
- {{- "[INST]" + message["content"] + "[/INST]" }}
44
- {%- elif (message.tool_calls is defined and message.tool_calls is not none) %}
45
- {{- '<|start_header_id|>assistant<|end_header_id|>
46
-
47
- ' }}
48
- {{- "[TOOL_CALLS][" }}
49
- {%- for tool_call in message.tool_calls %}
50
- {%- set out = tool_call.function|tojson %}
51
- {{- out[:-1] }}
52
- {{- ', "id": "' + tool_call.id + '"}' }}
53
- {%- if not loop.last %}
54
- {{- ", " }}
55
- {%- else %}
56
- {{- "]" + eos_token }}
57
- {%- endif %}
58
- {%- endfor %}
59
- {%- elif message["role"] == "assistant" %}
60
- {{- '<|start_header_id|>assistant<|end_header_id|>
61
-
62
- ' }}
63
- {{- message["content"] + eos_token}}
64
- {%- elif message["role"] == "tool_results" or message["role"] == "tool" %}
65
- {%- if message.content is defined and message.content.content is defined %}
66
- {%- set content = message.content.content %}
67
- {%- else %}
68
- {%- set content = message.content %}
69
- {%- endif %}
70
- {{- '[TOOL_RESULTS]{"content": ' + content|string + ", " }}
71
- {{- '"call_id": "' + message.tool_call_id + '"}[/TOOL_RESULTS]' }}
72
- {%- else %}
73
- {{- raise_exception("Only user and assistant roles are supported, with the exception of an initial optional system message!") }}
74
- {%- endif %}
75
- {%- endfor %}
76
- {%- if add_generation_prompt %}
77
- {{- '<|start_header_id|>assistant<|end_header_id|>
78
-
79
- ' }}
80
- {%- endif %}
 
1
+ {% for message in messages %}
2
+ {%- if message['role'] == 'system' -%}
3
+ {{ '<|im_start|>system\n' + message['content'] + '<|im_end|>\n' }}
4
+ {%- elif message['role'] == 'user' -%}
5
+ {{ '<|im_start|>user\n' + message['content'] + '<|im_end|>\n' }}
6
+ {%- elif message['role'] == 'assistant' -%}
7
+ {{ '<|im_start|>assistant\n' + message['content'] + '<|im_end|>\n' }}
8
+ {%- endif -%}
9
+ {%- endfor -%}
10
+ {%- if add_generation_prompt -%}
11
+ {{ '<|im_start|>assistant\n' }}
12
+ {%- endif -%}