darkc0de commited on
Commit
25ecaeb
·
verified ·
1 Parent(s): 524a3d5

Delete chat_template.jinja

Browse files
Files changed (1) hide show
  1. chat_template.jinja +0 -263
chat_template.jinja DELETED
@@ -1,263 +0,0 @@
1
- {#- Default date variables. To improve UX pass the correct ones to the Jinja render. #}
2
- {%- if today is not defined %}
3
- {%- set today = '29-04-2026' %}
4
- {%- endif %}
5
- {%- if yesterday is not defined %}
6
- {%- set yesterday = '28-04-2026' %}
7
- {%- endif %}
8
-
9
- {#- Default system message if no system prompt is passed. #}
10
- {%- set default_system_message -%}
11
- You are Mistral Medium 3.5, a Large Language Model (LLM) created by Mistral AI, a French startup headquartered in Paris.
12
- You are an intelligent conversational assistant powering an AI assistant called Le Chat.
13
- Your knowledge base was last updated on Friday, November 1, 2024.
14
- The current date is {{ today }}.
15
-
16
- # GENERAL GUIDELINES
17
-
18
- - Accurately answer the user's question.
19
- - For uncertain information or when the user's request requires up-to-date or specific data, use the available tools to fetch the information.
20
- - Be very attentive to dates, always try to resolve dates (e.g. "yesterday" is {{ yesterday }}) and when asked about information at specific dates, discard information that is at another date.
21
-
22
- # WEB BROWSING INSTRUCTIONS
23
-
24
- You cannot perform any web search or access internet to open URLs, links etc without dedicated tools.
25
-
26
- # MULTI-MODAL INSTRUCTIONS
27
-
28
- - You have the ability to read images.
29
- - You cannot read audio nor videos.
30
- - You cannot generate images without dedicated tools.
31
-
32
- # TOOL CALLING INSTRUCTIONS
33
-
34
- You may have access to tools that you can use to fetch information or perform actions. You must use these tools in the following situations:
35
-
36
- 1. When the request requires up-to-date information.
37
- 2. When the request requires specific data that you do not have in your knowledge base.
38
- 3. When the request involves actions that you cannot perform without tools.
39
-
40
- Always prioritize using tools to provide the most accurate and helpful response.
41
- {%- endset %}
42
-
43
- {#- Begin of sequence token. #}
44
- {{- '<s>' }}
45
-
46
-
47
- {#- Handle system prompt if it exists. #}
48
- {%- set loop_messages = messages %}
49
- {%- if messages[0]['role'] != 'system' and default_system_message != '' %}
50
- {{- '[SYSTEM_PROMPT]' + default_system_message + '[/SYSTEM_PROMPT]' }}
51
- {%- endif %}
52
-
53
-
54
- {#- Tools and model settings definition #}
55
- {%- set available_tools = '' %}
56
- {%- set has_tools = false %}
57
- {%- if tools is defined and tools is not none and tools|length > 0 %}
58
- {%- set has_tools = true %}
59
- {%- set available_tools = '[AVAILABLE_TOOLS]' + (tools| tojson) + '[/AVAILABLE_TOOLS]' %}
60
- {%- endif %}
61
- {%- if reasoning_effort is not defined or reasoning_effort is none %}
62
- {%- set reasoning_effort = 'none' %}
63
- {%- endif %}
64
- {%- if reasoning_effort not in ['none', 'high'] %}
65
- {{- raise_exception('reasoning_effort must be either "none" or "high"') }}
66
- {%- endif %}
67
- {%- set model_settings = '[MODEL_SETTINGS]{"reasoning_effort": "' + reasoning_effort + '"}[/MODEL_SETTINGS]' %}
68
-
69
- {#- Aggregate consecutive messages with the same role except system and tool. #}
70
- {#- A sentinel message is appended so the last group gets flushed inside the loop. #}
71
- {%- set ns_agg = namespace(messages=[], current_group=[], current_role=none) %}
72
- {%- for message in loop_messages + [{'role': '__sentinel__'}] %}
73
- {%- if message['role'] != ns_agg.current_role or message['role'] == 'system' or message['role'] == 'tool' %}
74
- {%- if ns_agg.current_role == 'tool' %}
75
- {%- set ns_agg.messages = ns_agg.messages + ns_agg.current_group %}
76
- {%- elif ns_agg.current_role is not none %}
77
- {%- set ns_c = namespace(text_parts=[], chunks=[], has_non_text=false, tool_calls=[]) %}
78
- {%- for msg in ns_agg.current_group %}
79
- {#- Convert reasoning / reasoning_content to a leading thinking chunk. #}
80
- {%- set reasoning = msg.get('reasoning_content', msg.get('reasoning', none)) %}
81
- {%- if reasoning is not none and reasoning != '' %}
82
- {%- set think_chunk = {'type': 'thinking', 'thinking': reasoning} %}
83
- {%- if msg['content'] is string and msg['content'] != '' %}
84
- {%- set new_content = [think_chunk, {'type': 'text', 'text': msg['content']}] %}
85
- {%- elif msg['content'] is not none and msg['content'] is not string and msg['content'] | length > 0 %}
86
- {%- set new_content = [think_chunk] + msg['content'] | list %}
87
- {%- else %}
88
- {%- set new_content = [think_chunk] %}
89
- {%- endif %}
90
- {%- if msg['tool_calls'] is defined and msg['tool_calls'] is not none %}
91
- {%- set msg = {'role': msg['role'], 'content': new_content, 'tool_calls': msg['tool_calls']} %}
92
- {%- else %}
93
- {%- set msg = {'role': msg['role'], 'content': new_content} %}
94
- {%- endif %}
95
- {%- endif %}
96
- {%- if msg['content'] is string %}
97
- {%- set ns_c.text_parts = ns_c.text_parts + [msg['content']] %}
98
- {%- elif msg['content'] is not none %}
99
- {%- for block in msg['content'] %}
100
- {%- if block['type'] == 'text' %}
101
- {%- set ns_c.text_parts = ns_c.text_parts + [block['text']] %}
102
- {%- else %}
103
- {%- if ns_c.text_parts | length > 0 %}
104
- {%- set ns_c.chunks = ns_c.chunks + [{'type': 'text', 'text': ns_c.text_parts | join('\n\n')}] %}
105
- {%- set ns_c.text_parts = [] %}
106
- {%- endif %}
107
- {%- set ns_c.chunks = ns_c.chunks + [block] %}
108
- {%- set ns_c.has_non_text = true %}
109
- {%- endif %}
110
- {%- endfor %}
111
- {%- endif %}
112
- {%- if msg['tool_calls'] is defined and msg['tool_calls'] is not none %}
113
- {%- set ns_c.tool_calls = ns_c.tool_calls + msg['tool_calls'] | list %}
114
- {%- endif %}
115
- {%- endfor %}
116
- {%- if ns_c.has_non_text %}
117
- {%- if ns_c.text_parts | length > 0 %}
118
- {%- set ns_c.chunks = ns_c.chunks + [{'type': 'text', 'text': ns_c.text_parts | join('\n\n')}] %}
119
- {%- endif %}
120
- {%- set merged_content = ns_c.chunks %}
121
- {%- else %}
122
- {%- set merged_content = ns_c.text_parts | join('\n\n') %}
123
- {%- endif %}
124
- {%- if ns_c.tool_calls | length > 0 %}
125
- {%- set ns_agg.messages = ns_agg.messages + [{'role': ns_agg.current_role, 'content': merged_content, 'tool_calls': ns_c.tool_calls}] %}
126
- {%- else %}
127
- {%- set ns_agg.messages = ns_agg.messages + [{'role': ns_agg.current_role, 'content': merged_content}] %}
128
- {%- endif %}
129
- {%- endif %}
130
- {%- if message['role'] != '__sentinel__' %}
131
- {%- set ns_agg.current_group = [message] %}
132
- {%- set ns_agg.current_role = message['role'] %}
133
- {%- endif %}
134
- {%- else %}
135
- {%- set ns_agg.current_group = ns_agg.current_group + [message] %}
136
- {%- endif %}
137
- {%- endfor %}
138
- {%- set loop_messages = ns_agg.messages %}
139
-
140
- {#- Validates message ordering. #}
141
- {%- set ns = namespace(available_tools_and_settings_emitted=false) %}
142
- {%- if loop_messages | length > 0 and loop_messages[0]['role'] != 'user' and loop_messages[0]['role'] != 'system' %}
143
- {{- raise_exception('Conversation must start with a user or system message, got ' + loop_messages[0]['role'] + '.') }}
144
- {%- endif %}
145
- {%- set ns_order = namespace(previous_role=none) %}
146
- {%- for message in loop_messages %}
147
- {%- set current_role = message['role'] %}
148
- {%- if ns_order.previous_role is not none %}
149
- {%- if ns_order.previous_role == 'system' %}
150
- {%- if current_role != 'user' and current_role != 'assistant' and current_role != 'system' %}
151
- {{- raise_exception('Unexpected role \'' + current_role + '\' after role \'' + ns_order.previous_role + '\'') }}
152
- {%- endif %}
153
- {%- elif ns_order.previous_role == 'user' %}
154
- {%- if current_role != 'assistant' and current_role != 'system' and current_role != 'user' %}
155
- {{- raise_exception('Unexpected role \'' + current_role + '\' after role \'' + ns_order.previous_role + '\'') }}
156
- {%- endif %}
157
- {%- elif ns_order.previous_role == 'assistant' %}
158
- {%- if current_role != 'assistant' and current_role != 'user' and current_role != 'tool' %}
159
- {{- raise_exception('Unexpected role \'' + current_role + '\' after role \'' + ns_order.previous_role + '\'') }}
160
- {%- endif %}
161
- {%- elif ns_order.previous_role == 'tool' %}
162
- {%- if current_role != 'assistant' and current_role != 'tool' and current_role != 'user' %}
163
- {{- raise_exception('Unexpected role \'' + current_role + '\' after role \'' + ns_order.previous_role + '\'') }}
164
- {%- endif %}
165
- {%- endif %}
166
- {%- endif %}
167
- {%- set ns_order.previous_role = current_role %}
168
- {%- endfor %}
169
-
170
- {#- Handle conversation messages. #}
171
- {%- for message in loop_messages %}
172
- {#- User messages supports text, image and image_url content. #}
173
- {%- if message['role'] == 'user' %}
174
- {%- if not ns.available_tools_and_settings_emitted %}
175
- {{- available_tools }}
176
- {{- model_settings }}
177
- {%- set ns.available_tools_and_settings_emitted = true %}
178
- {%- endif %}
179
- {%- if message['content'] is string %}
180
- {{- '[INST]' + message['content'] + '[/INST]' }}
181
- {%- elif message['content'] | length > 0 %}
182
- {{- '[INST]' }}
183
- {%- if message['content'] | length == 2 %}
184
- {%- set blocks = message['content'] | sort(attribute='type') %}
185
- {%- else %}
186
- {%- set blocks = message['content'] %}
187
- {%- endif %}
188
- {%- for block in blocks %}
189
- {%- if block['type'] == 'text' %}
190
- {{- block['text'] }}
191
- {%- elif block['type'] in ['image', 'image_url'] %}
192
- {{- '[IMG]' }}
193
- {%- else %}
194
- {{- raise_exception('Only text, image and image_url chunks are supported in user message content.') }}
195
- {%- endif %}
196
- {%- endfor %}
197
- {{- '[/INST]' }}
198
- {%- else %}
199
- {{- raise_exception('User message must have a string or a list of chunks in content') }}
200
- {%- endif %}
201
-
202
- {#- Assistant messages supports text and thinking content. #}
203
- {%- elif message['role'] == 'assistant' %}
204
- {%- if (message['content'] is none or message['content'] == '' or message['content']|length == 0) and (message['tool_calls'] is not defined or message['tool_calls'] is none or message['tool_calls']|length == 0) %}
205
- {{- raise_exception('Assistant message must have a string or a list of chunks in content or a list of tool calls.') }}
206
- {%- endif %}
207
-
208
- {%- if message['content'] is string and message['content'] != '' %}
209
- {{- message['content'] }}
210
- {%- elif message['content'] | length > 0 %}
211
- {%- for block in message['content'] %}
212
- {%- if block['type'] == 'text' %}
213
- {{- block['text'] }}
214
- {%- elif block['type'] == 'thinking' %}
215
- {{- '[THINK]' + block['thinking'] }}
216
- {%- if block.get('closed', true) %}{{- '[/THINK]' }}{%- endif %}
217
- {%- else %}
218
- {{- raise_exception('Only text and thinking chunks are supported in assistant message contents.') }}
219
- {%- endif %}
220
- {%- endfor %}
221
- {%- endif %}
222
-
223
- {%- if message['tool_calls'] is defined and message['tool_calls'] is not none and message['tool_calls']|length > 0 %}
224
- {%- for tool in message['tool_calls'] %}
225
- {{- '[TOOL_CALLS]' }}
226
- {%- set name = tool['function']['name'] %}
227
- {%- set arguments = tool['function']['arguments'] %}
228
- {%- if arguments is not string %}
229
- {%- set arguments = arguments|tojson|safe %}
230
- {%- elif arguments == '' %}
231
- {%- set arguments = '{}' %}
232
- {%- endif %}
233
- {{- name + '[ARGS]' + arguments }}
234
- {%- endfor %}
235
- {%- endif %}
236
-
237
- {{- '</s>' }}
238
-
239
- {#- Tool messages only supports text content. #}
240
- {%- elif message['role'] == 'tool' %}
241
- {{- '[TOOL_RESULTS]' + message['content']|string + '[/TOOL_RESULTS]' }}
242
-
243
- {#- System messages. #}
244
- {%- elif message['role'] == 'system' %}
245
- {{- '[SYSTEM_PROMPT]' -}}
246
- {%- if message['content'] is string %}
247
- {{- message['content'] -}}
248
- {%- else %}
249
- {%- for block in message['content'] %}
250
- {%- if block['type'] == 'text' %}
251
- {{- block['text'] }}
252
- {%- else %}
253
- {{- raise_exception('Only text chunks are supported in system message contents.') }}
254
- {%- endif %}
255
- {%- endfor %}
256
- {%- endif %}
257
- {{- '[/SYSTEM_PROMPT]' -}}
258
-
259
- {#- Raise exception for unsupported roles. #}
260
- {%- else %}
261
- {{- raise_exception('Only user, assistant, system and tool roles are supported, got ' + message['role'] + '.') }}
262
- {%- endif %}
263
- {%- endfor %}