quangtvn commited on
Commit
caf128e
·
verified ·
1 Parent(s): 481a2a5

(Trained with Unsloth)

Browse files
Files changed (1) hide show
  1. chat_template.jinja +1 -141
chat_template.jinja CHANGED
@@ -1,4 +1,4 @@
1
- {% if 'role' in messages[0] %}{{- bos_token }}
2
  {%- if custom_tools is defined %}
3
  {%- set tools = custom_tools %}
4
  {%- endif %}
@@ -137,143 +137,3 @@
137
 
138
  ' }}
139
  {%- endif %}
140
- {% else %}{{- bos_token }}
141
- {%- if custom_tools is defined %}
142
- {%- set tools = custom_tools %}
143
- {%- endif %}
144
- {%- if not tools_in_user_message is defined %}
145
- {%- set tools_in_user_message = true %}
146
- {%- endif %}
147
- {%- if not date_string is defined %}
148
- {%- set date_string = "26 July 2024" %}
149
- {%- endif %}
150
- {%- if not tools is defined %}
151
- {%- set tools = none %}
152
- {%- endif %}
153
-
154
- {#- This block extracts the system message, so we can slot it into the right place. #}
155
- {%- if messages[0]['from'] == 'system' %}
156
- {%- set system_message = messages[0]['value'] %}
157
- {%- set messages = messages[1:] %}
158
- {%- else %}
159
- {%- set system_message = "" %}
160
- {%- endif %}
161
-
162
- {#- System message + builtin tools #}
163
- {{- "<|start_header_id|>system<|end_header_id|>
164
-
165
- " }}
166
- {%- if builtin_tools is defined or tools is not none %}
167
- {{- "Environment: ipython
168
- " }}
169
- {%- endif %}
170
- {%- if builtin_tools is defined %}
171
- {{- "Tools: " + builtin_tools | reject('equalto', 'code_interpreter') | join(", ") + "
172
-
173
- "}}
174
- {%- endif %}
175
- {{- "Cutting Knowledge Date: December 2023
176
- " }}
177
- {{- "Today Date: " + date_string + "
178
-
179
- " }}
180
- {%- if tools is not none and not tools_in_user_message %}
181
- {{- "You have access to the following functions. To call a function, please respond with JSON for a function call." }}
182
- {{- 'Respond in the format {"name": function name, "parameters": dictionary of argument name and its value}.' }}
183
- {{- "Do not use variables.
184
-
185
- " }}
186
- {%- for t in tools %}
187
- {{- t | tojson(indent=4) }}
188
- {{- "
189
-
190
- " }}
191
- {%- endfor %}
192
- {%- endif %}
193
- {{- system_message }}
194
- {{- "<|eot_id|>" }}
195
-
196
- {#- Custom tools are passed in a user message with some extra guidance #}
197
- {%- if tools_in_user_message and not tools is none %}
198
- {#- Extract the first user message so we can plug it in here #}
199
- {%- if messages | length != 0 %}
200
- {%- set first_user_message = messages[0]['value'] %}
201
- {%- set messages = messages[1:] %}
202
- {%- else %}
203
- {{- raise_exception("Cannot put tools in the first user message when there's no first user message!") }}
204
- {%- endif %}
205
- {{- '<|start_header_id|>user<|end_header_id|>
206
-
207
- ' -}}
208
- {{- "Given the following functions, please respond with a JSON for a function call " }}
209
- {{- "with its proper arguments that best answers the given prompt.
210
-
211
- " }}
212
- {{- 'Respond in the format {"name": function name, "parameters": dictionary of argument name and its value}.' }}
213
- {{- "Do not use variables.
214
-
215
- " }}
216
- {%- for t in tools %}
217
- {{- t | tojson(indent=4) }}
218
- {{- "
219
-
220
- " }}
221
- {%- endfor %}
222
- {{- first_user_message + "<|eot_id|>"}}
223
- {%- endif %}
224
-
225
- {%- for message in messages %}
226
- {%- if not (message.role == 'ipython' or message.role == 'tool' or 'tool_calls' in message) %}
227
- {{- '<|start_header_id|>' + message['from'] + '<|end_header_id|>
228
-
229
- '+ message['value'] + '<|eot_id|>' }}
230
- {%- elif 'tool_calls' in message %}
231
- {%- if not message.tool_calls|length == 1 %}
232
- {{- raise_exception("This model only supports single tool-calls at once!") }}
233
- {%- endif %}
234
- {%- set tool_call = message.tool_calls[0].function %}
235
- {%- if builtin_tools is defined and tool_call.name in builtin_tools %}
236
- {{- '<|start_header_id|>assistant<|end_header_id|>
237
-
238
- ' -}}
239
- {{- "<|python_tag|>" + tool_call.name + ".call(" }}
240
- {%- for arg_name, arg_val in tool_call.arguments | items %}
241
- {{- arg_name + '="' + arg_val + '"' }}
242
- {%- if not loop.last %}
243
- {{- ", " }}
244
- {%- endif %}
245
- {%- endfor %}
246
- {{- ")" }}
247
- {%- else %}
248
- {{- '<|start_header_id|>assistant<|end_header_id|>
249
-
250
- ' -}}
251
- {{- '{"name": "' + tool_call.name + '", ' }}
252
- {{- '"parameters": ' }}
253
- {{- tool_call.arguments | tojson }}
254
- {{- "}" }}
255
- {%- endif %}
256
- {%- if builtin_tools is defined %}
257
- {#- This means we're in ipython mode #}
258
- {{- "<|eom_id|>" }}
259
- {%- else %}
260
- {{- "<|eot_id|>" }}
261
- {%- endif %}
262
- {%- elif message.role == "tool" or message.role == "ipython" %}
263
- {{- "<|start_header_id|>ipython<|end_header_id|>
264
-
265
- " }}
266
- {%- if message.content is mapping or message.content is iterable %}
267
- {{- message.content | tojson }}
268
- {%- else %}
269
- {{- message.content }}
270
- {%- endif %}
271
- {{- "<|eot_id|>" }}
272
- {%- endif %}
273
- {%- endfor %}
274
- {%- if add_generation_prompt %}
275
- {{- '<|start_header_id|>assistant<|end_header_id|>
276
-
277
- ' }}
278
- {%- endif %}
279
- {% endif %}
 
1
+ {{- bos_token }}
2
  {%- if custom_tools is defined %}
3
  {%- set tools = custom_tools %}
4
  {%- endif %}
 
137
 
138
  ' }}
139
  {%- endif %}