jianguozhang commited on
Commit
713b2de
1 Parent(s): d98e603

Update xLAM chat template examples

Browse files
example/xlam_chat_template_examples_11_21.ipynb ADDED
@@ -0,0 +1,1341 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "metadata": {},
7
+ "outputs": [
8
+ {
9
+ "name": "stderr",
10
+ "output_type": "stream",
11
+ "text": [
12
+ "/export/agentstudio-family/miniconda3/v2lite-train/lib/python3.10/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
13
+ " from .autonotebook import tqdm as notebook_tqdm\n"
14
+ ]
15
+ }
16
+ ],
17
+ "source": [
18
+ "import os\n",
19
+ "import json\n",
20
+ "from typing import List, Union\n",
21
+ "from pprint import pprint\n",
22
+ "import torch\n",
23
+ "import inspect\n",
24
+ "from collections import defaultdict\n",
25
+ "from transformers import AutoTokenizer\n",
26
+ "from agentstudio.agentstudio_utils import *\n"
27
+ ]
28
+ },
29
+ {
30
+ "cell_type": "markdown",
31
+ "metadata": {},
32
+ "source": [
33
+ "### Global Variables"
34
+ ]
35
+ },
36
+ {
37
+ "cell_type": "code",
38
+ "execution_count": 4,
39
+ "metadata": {},
40
+ "outputs": [],
41
+ "source": [
42
+ "def get_current_weather(location: str, format: str, date: int):\n",
43
+ " \"\"\"\n",
44
+ " Get the current weather\n",
45
+ "\n",
46
+ " Args:\n",
47
+ " location: The city and state, e.g. San Francisco, CA\n",
48
+ " format: The temperature unit to use. Infer this from the users location. (choices: [\"celsius\", \"fahrenheit\"])\n",
49
+ " date: a specific date to get the weather for\n",
50
+ " \"\"\"\n",
51
+ " pass\n",
52
+ "\n",
53
+ "def get_current_temperature(location: str, unit: str, longitude: float, latitude: float) -> float:\n",
54
+ " \"\"\"\n",
55
+ " Get the current temperature at a location.\n",
56
+ " \n",
57
+ " Args:\n",
58
+ " location: The location to get the temperature for, in the format \"City, Country\"\n",
59
+ " unit: The unit to return the temperature in. (choices: [\"celsius\", \"fahrenheit\"])\n",
60
+ " longitude: the longitude of the location\n",
61
+ " latitude: the latitude of the location\n",
62
+ " Returns:\n",
63
+ " The current temperature at the specified location in the specified units, as a float.\n",
64
+ " \"\"\"\n",
65
+ " return 22. # A real function should probably actually get the temperature!\n",
66
+ "\n",
67
+ "def get_current_wind_speed(location: str) -> float:\n",
68
+ " \"\"\"\n",
69
+ " Get the current wind speed in km/h at a given location.\n",
70
+ " \n",
71
+ " Args:\n",
72
+ " location: The location to get the temperature for, in the format \"City, Country\"\n",
73
+ " Returns:\n",
74
+ " The current wind speed at the given location in km/h, as a float.\n",
75
+ " \"\"\"\n",
76
+ " return 6. # A real function should probably actually get the wind speed!\n",
77
+ "\n",
78
+ "tools_simple_str = \"\"\"\n",
79
+ "def get_current_weather(location: str, format: str, date: int):\n",
80
+ " '''\n",
81
+ " Get the current weather\n",
82
+ "\n",
83
+ " Args:\n",
84
+ " location: The city and state, e.g. San Francisco, CA\n",
85
+ " format: The temperature unit to use. Infer this from the users location. (choices: [\"celsius\", \"fahrenheit\"])\n",
86
+ " date: a specific date to get the weather for\n",
87
+ " '''\n",
88
+ " pass\n",
89
+ "\n",
90
+ "def get_current_temperature(location: str, unit: str, longitude: float, latitude: float) -> float:\n",
91
+ " '''\n",
92
+ " Get the current temperature at a location.\n",
93
+ " \n",
94
+ " Args:\n",
95
+ " location: The location to get the temperature for, in the format \"City, Country\"\n",
96
+ " unit: The unit to return the temperature in. (choices: [\"celsius\", \"fahrenheit\"])\n",
97
+ " longitude: the longitude of the location\n",
98
+ " latitude: the latitude of the location\n",
99
+ " Returns:\n",
100
+ " The current temperature at the specified location in the specified units, as a float.\n",
101
+ " '''\n",
102
+ " return 22. # A real function should probably actually get the temperature!\n",
103
+ "\n",
104
+ "def get_current_wind_speed(location: str) -> float:\n",
105
+ " '''\n",
106
+ " Get the current wind speed in km/h at a given location.\n",
107
+ " \n",
108
+ " Args:\n",
109
+ " location: The location to get the temperature for, in the format \"City, Country\"\n",
110
+ " Returns:\n",
111
+ " The current wind speed at the given location in km/h, as a float.\n",
112
+ " '''\n",
113
+ " return 6. # A real function should probably actually get the wind speed!\n",
114
+ "\"\"\"\n",
115
+ "\n",
116
+ "tools = [get_current_weather, get_current_temperature, get_current_wind_speed]\n",
117
+ "tools_str = json.dumps([{\"name\": tool.__name__, \"parameters\": str(inspect.signature(tool)), \"description\": tool.__doc__.strip()} for tool in tools], indent=4)\n",
118
+ "\n",
119
+ "BASE_XLAM_DIR = \"/export/agentstudio-family/checkpoints/xlam_v1\"\n",
120
+ "model_list = [\n",
121
+ " \"xlam_7b_r\",\n",
122
+ " \"xlam_8x7b_r\",\n",
123
+ " \"xlam_8x22b_r\"\n",
124
+ "]\n"
125
+ ]
126
+ },
127
+ {
128
+ "cell_type": "markdown",
129
+ "metadata": {},
130
+ "source": [
131
+ "### DO NOT RUN THIS CELL as JIANGUO has updated for xLAM 1.0 Series (xLAM Tool Call Template)"
132
+ ]
133
+ },
134
+ {
135
+ "cell_type": "code",
136
+ "execution_count": 5,
137
+ "metadata": {},
138
+ "outputs": [],
139
+ "source": [
140
+ "xlam_chat_template = \"\"\"\n",
141
+ "{%- if messages[0][\"role\"] == \"system\" %}\n",
142
+ " {%- set system_message = messages[0][\"content\"] %}\n",
143
+ " {%- if messages[1][\"role\"] == \"system\" %}\n",
144
+ " {%- set format_message = messages[1][\"content\"] %}\n",
145
+ " {%- set loop_messages = messages[2:] %}\n",
146
+ " {%- else %}\n",
147
+ " {%- set loop_messages = messages[1:] %}\n",
148
+ " {%- endif %}\n",
149
+ "{%- else %}\n",
150
+ " {%- set loop_messages = messages %}\n",
151
+ "{%- endif %}\n",
152
+ "{%- if not tools is defined %}\n",
153
+ " {%- set tools = none %}\n",
154
+ "{%- endif %}\n",
155
+ "\n",
156
+ "{#- This block checks for alternating user/assistant messages, skipping tool calling messages #}\n",
157
+ "{%- set ns = namespace() %}\n",
158
+ "{%- set ns.index = 0 %}\n",
159
+ "{%- for message in loop_messages %}\n",
160
+ " {%- if ((message[\"role\"] == \"user\") and (ns.index % 2 != 0)) or (message[\"role\"] not in [\"user\", \"assistant\", \"tool\", \"tool_results\"]) %}\n",
161
+ " {{- raise_exception(\"After the optional system message, conversation roles can only be from user/assistant/tool; After each tool message, the next message must be from the assistant\") }}\n",
162
+ " {%- endif %}\n",
163
+ " {%- set ns.index = ns.index + 1 %}\n",
164
+ "{%- endfor %}\n",
165
+ "\n",
166
+ "{{- bos_token }}\n",
167
+ "{{- \"[INST]\" }}\n",
168
+ "{%- if system_message is not defined %}\n",
169
+ " {% set system_message %}\n",
170
+ "You are an expert in composing functions. You are given a question and a set of possible functions. \n",
171
+ "Based on the question, you will need to make one or more function/tool calls to achieve the purpose. \n",
172
+ "If none of the functions can be used, point it out and refuse to answer. \n",
173
+ "If the given question lacks the parameters required by the function, also point it out.{% endset %}\n",
174
+ "{%- endif %}\n",
175
+ "{{- \"\\n[BEGIN OF TASK INSTRUCTION]\\n\" + system_message + \"\\n[END OF TASK INSTRUCTION]\\n\\n\" }}\n",
176
+ "\n",
177
+ "{%- if tools is not none %}\n",
178
+ " {{- \"[BEGIN OF AVAILABLE_TOOLS]\\n\" }}\n",
179
+ " {{- tools|string }}\n",
180
+ " {{- \"\\n[END OF AVAILABLE_TOOLS]\\n\\n\" }}\n",
181
+ "{%- endif %}\n",
182
+ " \n",
183
+ "{%- if format_message is not defined %}\n",
184
+ " {% set format_message %}\n",
185
+ "Your output should be in the JSON format, which specifies a list of function calls. The example format is as follows. Please make sure the parameter type is correct. If no function call is needed, please make tool_calls an empty list '[]'.\n",
186
+ "```{\"thought\": \"the thought process, or an empty string\", \"tool_calls\": [{\"name\": \"api_name1\", \"arguments\": {\"argument1\": \"value1\", \"argument2\": \"value2\"}}]}```\n",
187
+ " {% endset %}\n",
188
+ "{%- endif %}\n",
189
+ "{{- \"[BEGIN OF FORMAT INSTRUCTION]\\n\" + format_message + \"[END OF FORMAT INSTRUCTION]\\n\\n\" }}\n",
190
+ "\n",
191
+ "{%- if loop_messages[0][\"role\"] == \"user\" %}\n",
192
+ " {%- set query = loop_messages[0][\"content\"] %}\n",
193
+ " {{- \"[BEGIN OF QUERY]\\n\" + query + \"\\n[END OF QUERY]\\n\" }}\n",
194
+ " {%- set loop_messages = loop_messages[1:] %}\n",
195
+ "{%- endif %}\n",
196
+ "\n",
197
+ "{% if loop_messages %}\n",
198
+ " {{- \"[BEGIN OF HISTORY STEPS]\\n[\" }}\n",
199
+ " {%- set step_id = namespace(value=1) %}\n",
200
+ " {%- for message in loop_messages %}\n",
201
+ " {%- if message[\"role\"] == \"assistant\" %}\n",
202
+ " {%- if message.tool_calls is defined and message.tool_calls is not none %}\n",
203
+ " {% if message.tool_calls is iterable and (message.tool_calls is not string and message.tool_calls is not mapping) %}\n",
204
+ " {{- \"{'thought':\" + message.content|tojson + \", 'tool_calls':\" + message.tool_calls|tojson + \", 'step_id':\" + step_id.value|string + \",\" }}\n",
205
+ " {%- else %}\n",
206
+ " {{- raise_exception(\"The tool_calls must be a list!\") }}\n",
207
+ " {%- endif %}\n",
208
+ " {%- else %}\n",
209
+ " {{- \"{'thought':\" + message.content|tojson + \", 'tool_calls':[]\" + \", 'step_id':\" + step_id.value|string + \",\" }}\n",
210
+ " {%- endif %}\n",
211
+ " {%- if loop.nextitem is not defined %}\n",
212
+ " {{- \" 'next_observation':''}\" }}\n",
213
+ " {%- elif loop.nextitem[\"role\"] == \"user\" %}\n",
214
+ " {{- \" 'next_observation':''\" }}\n",
215
+ " {%- elif loop.nextitem[\"role\"] != \"tool_results\" and loop.nextitem[\"role\"] != \"tool\" %}\n",
216
+ " {{- \" 'next_observation':''},\" }}\n",
217
+ " {%- endif %}\n",
218
+ " {%- elif message[\"role\"] == \"tool_results\" or message[\"role\"] == \"tool\" %}\n",
219
+ " {{- \" 'next_observation':\" + message.content|tojson }}\n",
220
+ " {%- if loop.nextitem is defined and loop.nextitem[\"role\"] != \"user\" %}\n",
221
+ " {{- \"}, \" }}\n",
222
+ " {%- elif not loop.nextitem is defined %}\n",
223
+ " {{- \"} \" }}\n",
224
+ " {%- endif %}\n",
225
+ " {%- set step_id.value = step_id.value + 1 %}\n",
226
+ " {%- elif message[\"role\"] == \"user\" %}\n",
227
+ " {{- \", 'user_input':\" + message.content|tojson }}\n",
228
+ " {%- if loop.nextitem is defined %}\n",
229
+ " {{- \"}, \" }}\n",
230
+ " {%- else %}\n",
231
+ " {{- \"} \" }}\n",
232
+ " {%- endif %}\n",
233
+ " {%- set step_id.value = step_id.value + 1 %}\n",
234
+ " {%- endif %}\n",
235
+ " {%- endfor %}\n",
236
+ " {{- \"]\\n[END OF HISTORY STEPS]\\n\" }}\n",
237
+ "{%- endif %}\n",
238
+ "{{- \"[/INST]\" }}\n",
239
+ "\"\"\".strip()"
240
+ ]
241
+ },
242
+ {
243
+ "cell_type": "markdown",
244
+ "metadata": {},
245
+ "source": [
246
+ "### DO NOT RUN THIS CELL as JIANGUO has updated for xLAM 1.0 Series(Update Tokenizer)"
247
+ ]
248
+ },
249
+ {
250
+ "cell_type": "code",
251
+ "execution_count": null,
252
+ "metadata": {},
253
+ "outputs": [
254
+ {
255
+ "name": "stdout",
256
+ "output_type": "stream",
257
+ "text": [
258
+ "Updated tokenizer for /export/agentstudio-family/checkpoints/xlam_v1/xlam_7b_r\n",
259
+ "Updated tokenizer for /export/agentstudio-family/checkpoints/xlam_v1/xlam_8x7b_r\n",
260
+ "Updated tokenizer for /export/agentstudio-family/checkpoints/xlam_v1/xlam_8x22b_r\n"
261
+ ]
262
+ }
263
+ ],
264
+ "source": [
265
+ "def check_tokenizer(model_list, BASE_XLAM_DIR):\n",
266
+ " for checkpoint in model_list:\n",
267
+ " tokenize_config = open_json(os.path.join(BASE_XLAM_DIR, checkpoint, \"tokenizer_config.json\"))\n",
268
+ " \n",
269
+ " del tokenize_config[\"chat_template\"]\n",
270
+ " original_tokenize_config = open_json(os.path.join(BASE_XLAM_DIR, checkpoint, \"original_tokenizer_config.json\"))\n",
271
+ " del original_tokenize_config[\"chat_template\"]\n",
272
+ " if tokenize_config != original_tokenize_config:\n",
273
+ " raise ValueError(f\"Tokenizer config is not the same for {checkpoint}\")\n",
274
+ "\n",
275
+ "def update_tokenizer(model_list, BASE_XLAM_DIR):\n",
276
+ " \"\"\"\n",
277
+ " Chat_templates: https://github.com/mistralai/cookbook/blob/main/concept-deep-dive/tokenization/chat_templates.md\n",
278
+ " We update Mixtral-8x22b-inst-v0.1 to better handle the system prompt in https://huggingface.co/mistralai/Mixtral-8x22B-Instruct-v0.1/discussions/54\n",
279
+ " \"\"\"\n",
280
+ " for checkpoint in model_list:\n",
281
+ " checkpoint = os.path.join(BASE_XLAM_DIR, checkpoint)\n",
282
+ " if os.path.exists(checkpoint):\n",
283
+ " raise ValueError(\"Tokenizer is already updated for xLAM 1.0 series: {}. Contact ❤❤❤Jianguo Zhang❤❤❤ for more details! \".format(checkpoint))\n",
284
+ " \n",
285
+ " if \"8x22b\" in checkpoint:\n",
286
+ " original_tokenize_config = open_json(os.path.join(checkpoint, \"original_tokenizer_config_fixed.json\"))\n",
287
+ " else:\n",
288
+ " original_tokenize_config = open_json(os.path.join(checkpoint, \"original_tokenizer_config.json\"))\n",
289
+ " chat_template = {\n",
290
+ " \"default\": original_tokenize_config[\"chat_template\"],\n",
291
+ " \"tool_use\": xlam_chat_template\n",
292
+ " }\n",
293
+ " \n",
294
+ " original_tokenize_config[\"chat_template\"] = chat_template\n",
295
+ " save_json(os.path.join(checkpoint, \"tokenizer_config.json\"), original_tokenize_config)\n",
296
+ " print(f\"Updated tokenizer for {checkpoint}\")\n",
297
+ "\n",
298
+ "update_tokenizer(model_list, BASE_XLAM_DIR)\n",
299
+ "check_tokenizer(model_list, BASE_XLAM_DIR)\n"
300
+ ]
301
+ },
302
+ {
303
+ "cell_type": "markdown",
304
+ "metadata": {},
305
+ "source": [
306
+ "### Verify the tokenizer"
307
+ ]
308
+ },
309
+ {
310
+ "cell_type": "code",
311
+ "execution_count": 7,
312
+ "metadata": {},
313
+ "outputs": [],
314
+ "source": [
315
+ "def verify_tokenizer(messages, model_list, tools, BASE_XLAM_DIR, fc_modes, file_suffix):\n",
316
+ " for fc_mode in fc_modes:\n",
317
+ " xlam_models_prompt = defaultdict(str)\n",
318
+ "\n",
319
+ " for checkpoint in model_list: \n",
320
+ " checkpoint = os.path.join(BASE_XLAM_DIR, checkpoint)\n",
321
+ " tokenizer = AutoTokenizer.from_pretrained(checkpoint)\n",
322
+ " \n",
323
+ " if fc_mode:\n",
324
+ " model_input = tokenizer.apply_chat_template(\n",
325
+ " messages,\n",
326
+ " tools=tools,\n",
327
+ " tokenize=False\n",
328
+ " )\n",
329
+ " else:\n",
330
+ " model_input = tokenizer.apply_chat_template(\n",
331
+ " messages,\n",
332
+ " tokenize=False\n",
333
+ " )\n",
334
+ " \n",
335
+ " if \"xlam_8x22b_r\" in checkpoint:\n",
336
+ " print(\"*\"*100)\n",
337
+ " print(\"Checkpoint: \", checkpoint)\n",
338
+ " # print(\"Chat Template: \", tokenizer.chat_template)\n",
339
+ " \n",
340
+ " print(\"-\" * 100)\n",
341
+ " print(\"FC Mode: \", fc_mode)\n",
342
+ " print(\"-\" * 100)\n",
343
+ " print(model_input)\n",
344
+ " xlam_models_prompt[checkpoint] = model_input\n",
345
+ " \n",
346
+ " # save the final message for reference\n",
347
+ " xlam_models_prompt[\"messages\"] = messages\n",
348
+ " if fc_mode:\n",
349
+ " xlam_models_prompt[\"avaliable_tools\"] = tools_str\n",
350
+ " xlam_models_prompt[\"avaliable_tools-easy_to_read\"] = tools_simple_str\n",
351
+ " \n",
352
+ " if fc_mode:\n",
353
+ " save_json(f\"xlam_chat_template-function_call_mode-{file_suffix}.json\", xlam_models_prompt)\n",
354
+ " else:\n",
355
+ " save_json(f\"xlam_chat_template-non_function_call_mode-{file_suffix}.json\", xlam_models_prompt)\n"
356
+ ]
357
+ },
358
+ {
359
+ "cell_type": "markdown",
360
+ "metadata": {},
361
+ "source": [
362
+ "### Example 1 (General Chat without a System Message at the Beginning)"
363
+ ]
364
+ },
365
+ {
366
+ "cell_type": "code",
367
+ "execution_count": 8,
368
+ "metadata": {},
369
+ "outputs": [
370
+ {
371
+ "name": "stdout",
372
+ "output_type": "stream",
373
+ "text": [
374
+ "****************************************************************************************************\n",
375
+ "Checkpoint: /export/agentstudio-family/checkpoints/xlam_v1/xlam_8x22b_r\n",
376
+ "----------------------------------------------------------------------------------------------------\n",
377
+ "FC Mode: True\n",
378
+ "----------------------------------------------------------------------------------------------------\n",
379
+ "<s>[INST]\n",
380
+ "[BEGIN OF TASK INSTRUCTION]\n",
381
+ "You are an expert in composing functions. You are given a question and a set of possible functions. \n",
382
+ "Based on the question, you will need to make one or more function/tool calls to achieve the purpose. \n",
383
+ "If none of the functions can be used, point it out and refuse to answer. \n",
384
+ "If the given question lacks the parameters required by the function, also point it out.\n",
385
+ "[END OF TASK INSTRUCTION]\n",
386
+ "\n",
387
+ "[BEGIN OF AVAILABLE_TOOLS]\n",
388
+ "[{'type': 'function', 'function': {'name': 'get_current_weather', 'description': 'Get the current weather', 'parameters': {'type': 'object', 'properties': {'location': {'type': 'string', 'description': 'The city and state, e.g. San Francisco, CA'}, 'format': {'type': 'string', 'enum': ['celsius', 'fahrenheit'], 'description': 'The temperature unit to use. Infer this from the users location.'}, 'date': {'type': 'integer', 'description': 'a specific date to get the weather for'}}, 'required': ['location', 'format', 'date']}}}, {'type': 'function', 'function': {'name': 'get_current_temperature', 'description': 'Get the current temperature at a location.', 'parameters': {'type': 'object', 'properties': {'location': {'type': 'string', 'description': 'The location to get the temperature for, in the format \"City, Country\"'}, 'unit': {'type': 'string', 'enum': ['celsius', 'fahrenheit'], 'description': 'The unit to return the temperature in.'}, 'longitude': {'type': 'number', 'description': 'the longitude of the location'}, 'latitude': {'type': 'number', 'description': 'the latitude of the location'}}, 'required': ['location', 'unit', 'longitude', 'latitude']}, 'return': {'type': 'number', 'description': 'The current temperature at the specified location in the specified units, as a float.'}}}, {'type': 'function', 'function': {'name': 'get_current_wind_speed', 'description': 'Get the current wind speed in km/h at a given location.', 'parameters': {'type': 'object', 'properties': {'location': {'type': 'string', 'description': 'The location to get the temperature for, in the format \"City, Country\"'}}, 'required': ['location']}, 'return': {'type': 'number', 'description': 'The current wind speed at the given location in km/h, as a float.'}}}]\n",
389
+ "[END OF AVAILABLE_TOOLS]\n",
390
+ "\n",
391
+ "[BEGIN OF FORMAT INSTRUCTION]\n",
392
+ "Your output should be in the JSON format, which specifies a list of function calls. The example format is as follows. Please make sure the parameter type is correct. If no function call is needed, please make tool_calls an empty list '[]'.\n",
393
+ "```{\"thought\": \"the thought process, or an empty string\", \"tool_calls\": [{\"name\": \"api_name1\", \"arguments\": {\"argument1\": \"value1\", \"argument2\": \"value2\"}}]}```\n",
394
+ "[END OF FORMAT INSTRUCTION]\n",
395
+ "\n",
396
+ "[BEGIN OF QUERY]\n",
397
+ "My girlfriend Mary and I want to go to Disney in LA. Can you help us plan the trip?\n",
398
+ "[END OF QUERY]\n",
399
+ "\n",
400
+ "[BEGIN OF HISTORY STEPS]\n",
401
+ "[{'thought':\"Sure! I can help with booking flights, finding weather information, and checking Disney details. First, let's choose a good date. Do you want to check the weather to find a sunny and warm day?\", 'tool_calls':[], 'step_id':1, 'next_observation':'', 'user_input':\"Yes, we'd love that. We prefer sunny days with warm temperatures.\"}, {'thought':\"Got it. Let me check the weather forecast for Los Angeles to help you find the best date.\", 'tool_calls':[], 'step_id':2, 'next_observation':'', 'user_input':\"Sounds great! Thanks for your help.\"} ]\n",
402
+ "[END OF HISTORY STEPS]\n",
403
+ "[/INST]\n",
404
+ "****************************************************************************************************\n",
405
+ "Checkpoint: /export/agentstudio-family/checkpoints/xlam_v1/xlam_8x22b_r\n",
406
+ "----------------------------------------------------------------------------------------------------\n",
407
+ "FC Mode: False\n",
408
+ "----------------------------------------------------------------------------------------------------\n",
409
+ "<s>[INST] My girlfriend Mary and I want to go to Disney in LA. Can you help us plan the trip?[/INST] Sure! I can help with booking flights, finding weather information, and checking Disney details. First, let's choose a good date. Do you want to check the weather to find a sunny and warm day?</s>[INST] Yes, we'd love that. We prefer sunny days with warm temperatures.[/INST] Got it. Let me check the weather forecast for Los Angeles to help you find the best date.</s>[INST] Sounds great! Thanks for your help.[/INST]\n"
410
+ ]
411
+ }
412
+ ],
413
+ "source": [
414
+ "messages = [\n",
415
+ " {\"role\": \"user\", \"content\": \"My girlfriend Mary and I want to go to Disney in LA. Can you help us plan the trip?\"},\n",
416
+ " \n",
417
+ " {\"role\": \"assistant\", \"content\": \"Sure! I can help with booking flights, finding weather information, and checking Disney details. First, let's choose a good date. Do you want to check the weather to find a sunny and warm day?\"},\n",
418
+ " \n",
419
+ " {\"role\": \"user\", \"content\": \"Yes, we'd love that. We prefer sunny days with warm temperatures.\"},\n",
420
+ " \n",
421
+ " {\"role\": \"assistant\", \"content\": \"Got it. Let me check the weather forecast for Los Angeles to help you find the best date.\"}, # example 1\n",
422
+ "\n",
423
+ " {\"role\": \"user\", \"content\": \"Sounds great! Thanks for your help.\"},\n",
424
+ "]\n",
425
+ "\n",
426
+ "verify_tokenizer(messages, model_list, tools, BASE_XLAM_DIR, fc_modes=[True, False], file_suffix=\"example_1\")"
427
+ ]
428
+ },
429
+ {
430
+ "cell_type": "markdown",
431
+ "metadata": {},
432
+ "source": [
433
+ "### Example 2 (Function Call Where Tool_Calls is a List, i.e., Similar to OpenAI Requirements)"
434
+ ]
435
+ },
436
+ {
437
+ "cell_type": "code",
438
+ "execution_count": 9,
439
+ "metadata": {},
440
+ "outputs": [
441
+ {
442
+ "name": "stdout",
443
+ "output_type": "stream",
444
+ "text": [
445
+ "****************************************************************************************************\n",
446
+ "Checkpoint: /export/agentstudio-family/checkpoints/xlam_v1/xlam_8x22b_r\n",
447
+ "----------------------------------------------------------------------------------------------------\n",
448
+ "FC Mode: True\n",
449
+ "----------------------------------------------------------------------------------------------------\n",
450
+ "<s>[INST]\n",
451
+ "[BEGIN OF TASK INSTRUCTION]\n",
452
+ "Based on the previous context and API request history, generate an API request or a response as an AI assistant. The current time is 2039-03-09 18:56:09 Wednesday.\n",
453
+ "[END OF TASK INSTRUCTION]\n",
454
+ "\n",
455
+ "[BEGIN OF AVAILABLE_TOOLS]\n",
456
+ "[{'type': 'function', 'function': {'name': 'get_current_weather', 'description': 'Get the current weather', 'parameters': {'type': 'object', 'properties': {'location': {'type': 'string', 'description': 'The city and state, e.g. San Francisco, CA'}, 'format': {'type': 'string', 'enum': ['celsius', 'fahrenheit'], 'description': 'The temperature unit to use. Infer this from the users location.'}, 'date': {'type': 'integer', 'description': 'a specific date to get the weather for'}}, 'required': ['location', 'format', 'date']}}}, {'type': 'function', 'function': {'name': 'get_current_temperature', 'description': 'Get the current temperature at a location.', 'parameters': {'type': 'object', 'properties': {'location': {'type': 'string', 'description': 'The location to get the temperature for, in the format \"City, Country\"'}, 'unit': {'type': 'string', 'enum': ['celsius', 'fahrenheit'], 'description': 'The unit to return the temperature in.'}, 'longitude': {'type': 'number', 'description': 'the longitude of the location'}, 'latitude': {'type': 'number', 'description': 'the latitude of the location'}}, 'required': ['location', 'unit', 'longitude', 'latitude']}, 'return': {'type': 'number', 'description': 'The current temperature at the specified location in the specified units, as a float.'}}}, {'type': 'function', 'function': {'name': 'get_current_wind_speed', 'description': 'Get the current wind speed in km/h at a given location.', 'parameters': {'type': 'object', 'properties': {'location': {'type': 'string', 'description': 'The location to get the temperature for, in the format \"City, Country\"'}}, 'required': ['location']}, 'return': {'type': 'number', 'description': 'The current wind speed at the given location in km/h, as a float.'}}}]\n",
457
+ "[END OF AVAILABLE_TOOLS]\n",
458
+ "\n",
459
+ "[BEGIN OF FORMAT INSTRUCTION]\n",
460
+ "Your output should be in the JSON format, which specifies a list of function calls. The example format is as follows. Please make sure the parameter type is correct. If no function call is needed, please make tool_calls an empty list '[]'.\n",
461
+ "```{\"thought\": \"the thought process, or an empty string\", \"tool_calls\": [{\"name\": \"api_name1\", \"arguments\": {\"argument1\": \"value1\", \"argument2\": \"value2\"}}]}```\n",
462
+ "[END OF FORMAT INSTRUCTION]\n",
463
+ "\n",
464
+ "[BEGIN OF QUERY]\n",
465
+ "User: I need to cancel a virtual yoga class that I booked. The booking ID is YGA123.\n",
466
+ "[END OF QUERY]\n",
467
+ "\n",
468
+ "[BEGIN OF HISTORY STEPS]\n",
469
+ "[{'thought':\"\", 'tool_calls':[{\"name\": \"cancel_booking\", \"arguments\": {\"booking_id\": \"YGA123\"}}], 'step_id':1, 'next_observation':{\"data\": {\"class_name\": \"Yoga for Relaxation\", \"class_time\": \"2039-03-10 17:00\", \"instructor_name\": \"Maggie Zhu\", \"cancellation_time\": \"2039-03-09 19:10\"}}}, {'thought':\"AI: Your booking for Yoga for Relaxation with Maggie Zhu on 2039-03-10 at 17:00 has been successfully cancelled and the cancellation time is 2039-03-09 19:10.\", 'tool_calls':[], 'step_id':2, 'next_observation':'', 'user_input':\"User: Can you please show me the virtual yoga and meditation classes available on the platform for tomorrow at 10am?\"}, {'thought':\"\", 'tool_calls':[{\"name\": \"get_classes\", \"arguments\": {\"date\": \"2039-03-10\", \"time\": \"10:00\"}}], 'step_id':3, 'next_observation':{\"data\": [{\"name\": \"Yoga for Relaxation\", \"instructor\": \"Maggie Zhu\", \"time\": \"2039-03-10 10:00\", \"duration\": 60}, {\"name\": \"Meditation for Beginners\", \"instructor\": \"John Lee\", \"time\": \"2039-03-10 10:30\", \"duration\": 30}]}}, {'thought':\"AI: There are two virtual yoga and meditation classes available on the platform for tomorrow at 10am: Yoga for Relaxation with Maggie Zhu that lasts for 60 minutes starting at 10:00 and Meditation for Beginners with John Lee which lasts for 30 minutes, starting at 10:30.\", 'tool_calls':[], 'step_id':4, 'next_observation':'', 'user_input':\"User: I'd like to book a virtual meditation class called \\\"Meditation for Beginners\\\" tomorrow at 8am.\"}, {'thought':\"\", 'tool_calls':[{\"name\": \"get_classes\", \"arguments\": {\"date\": \"2039-03-10\", \"time\": \"08:00\"}}], 'step_id':5, 'next_observation':{\"data\": [{\"name\": \"Meditation for Beginners\", \"instructor\": \"John Lee\", \"time\": \"2039-03-10 08:00\", \"duration\": 30}]}} ]\n",
470
+ "[END OF HISTORY STEPS]\n",
471
+ "[/INST]\n"
472
+ ]
473
+ }
474
+ ],
475
+ "source": [
476
+ "messages_2 = [\n",
477
+ " {\n",
478
+ " \"role\": \"system\",\n",
479
+ " \"content\": \"Based on the previous context and API request history, generate an API request or a response as an AI assistant. The current time is 2039-03-09 18:56:09 Wednesday.\"\n",
480
+ " },\n",
481
+ " {\n",
482
+ " \"role\": \"user\",\n",
483
+ " \"content\": \"User: I need to cancel a virtual yoga class that I booked. The booking ID is YGA123.\"\n",
484
+ " },\n",
485
+ " {\n",
486
+ " \"role\": \"assistant\",\n",
487
+ " \"content\": \"\",\n",
488
+ " \"tool_calls\": [\n",
489
+ " {\n",
490
+ " \"name\": \"cancel_booking\",\n",
491
+ " \"arguments\": {\n",
492
+ " \"booking_id\": \"YGA123\"\n",
493
+ " }\n",
494
+ " }\n",
495
+ " ]\n",
496
+ " },\n",
497
+ " {\n",
498
+ " \"role\": \"tool\",\n",
499
+ " \"name\": \"cancel_booking\",\n",
500
+ " \"content\": {\n",
501
+ " \"data\": {\n",
502
+ " \"class_name\": \"Yoga for Relaxation\",\n",
503
+ " \"class_time\": \"2039-03-10 17:00\",\n",
504
+ " \"instructor_name\": \"Maggie Zhu\",\n",
505
+ " \"cancellation_time\": \"2039-03-09 19:10\"\n",
506
+ " }\n",
507
+ " }\n",
508
+ " },\n",
509
+ " {\n",
510
+ " \"role\": \"assistant\",\n",
511
+ " \"content\": \"AI: Your booking for Yoga for Relaxation with Maggie Zhu on 2039-03-10 at 17:00 has been successfully cancelled and the cancellation time is 2039-03-09 19:10.\"\n",
512
+ " },\n",
513
+ " {\n",
514
+ " \"role\": \"user\",\n",
515
+ " \"content\": \"User: Can you please show me the virtual yoga and meditation classes available on the platform for tomorrow at 10am?\"\n",
516
+ " },\n",
517
+ " {\n",
518
+ " \"role\": \"assistant\",\n",
519
+ " \"content\": \"\",\n",
520
+ " \"tool_calls\": [\n",
521
+ " {\n",
522
+ " \"name\": \"get_classes\",\n",
523
+ " \"arguments\": {\n",
524
+ " \"date\": \"2039-03-10\",\n",
525
+ " \"time\": \"10:00\"\n",
526
+ " }\n",
527
+ " }\n",
528
+ " ]\n",
529
+ " },\n",
530
+ " {\n",
531
+ " \"role\": \"tool\",\n",
532
+ " \"name\": \"get_classes\",\n",
533
+ " \"content\": {\n",
534
+ " \"data\": [\n",
535
+ " {\n",
536
+ " \"name\": \"Yoga for Relaxation\",\n",
537
+ " \"instructor\": \"Maggie Zhu\",\n",
538
+ " \"time\": \"2039-03-10 10:00\",\n",
539
+ " \"duration\": 60\n",
540
+ " },\n",
541
+ " {\n",
542
+ " \"name\": \"Meditation for Beginners\",\n",
543
+ " \"instructor\": \"John Lee\",\n",
544
+ " \"time\": \"2039-03-10 10:30\",\n",
545
+ " \"duration\": 30\n",
546
+ " }\n",
547
+ " ]\n",
548
+ " }\n",
549
+ " },\n",
550
+ " {\n",
551
+ " \"role\": \"assistant\",\n",
552
+ " \"content\": \"AI: There are two virtual yoga and meditation classes available on the platform for tomorrow at 10am: Yoga for Relaxation with Maggie Zhu that lasts for 60 minutes starting at 10:00 and Meditation for Beginners with John Lee which lasts for 30 minutes, starting at 10:30.\"\n",
553
+ " },\n",
554
+ " {\n",
555
+ " \"role\": \"user\",\n",
556
+ " \"content\": \"User: I'd like to book a virtual meditation class called \\\"Meditation for Beginners\\\" tomorrow at 8am.\"\n",
557
+ " },\n",
558
+ " {\n",
559
+ " \"role\": \"assistant\",\n",
560
+ " \"content\": \"\",\n",
561
+ " \"tool_calls\": [\n",
562
+ " {\n",
563
+ " \"name\": \"get_classes\",\n",
564
+ " \"arguments\": {\n",
565
+ " \"date\": \"2039-03-10\",\n",
566
+ " \"time\": \"08:00\"\n",
567
+ " }\n",
568
+ " }\n",
569
+ " ]\n",
570
+ " },\n",
571
+ " {\n",
572
+ " \"role\": \"tool\",\n",
573
+ " \"name\": \"get_classes\",\n",
574
+ " \"content\": {\n",
575
+ " \"data\": [\n",
576
+ " {\n",
577
+ " \"name\": \"Meditation for Beginners\",\n",
578
+ " \"instructor\": \"John Lee\",\n",
579
+ " \"time\": \"2039-03-10 08:00\",\n",
580
+ " \"duration\": 30\n",
581
+ " }\n",
582
+ " ]\n",
583
+ " }\n",
584
+ " }\n",
585
+ "]\n",
586
+ "verify_tokenizer(messages_2, model_list, tools, BASE_XLAM_DIR, fc_modes = [True], file_suffix = \"example_2\")"
587
+ ]
588
+ },
589
+ {
590
+ "cell_type": "markdown",
591
+ "metadata": {},
592
+ "source": [
593
+ "### Example 2 (Function Call Where Tool_Calls is not a List)"
594
+ ]
595
+ },
596
+ {
597
+ "cell_type": "code",
598
+ "execution_count": 10,
599
+ "metadata": {},
600
+ "outputs": [],
601
+ "source": [
602
+ "messages_2 = [\n",
603
+ " {\n",
604
+ " \"role\": \"system\",\n",
605
+ " \"content\": \"Based on the previous context and API request history, generate an API request or a response as an AI assistant. The current time is 2039-03-09 18:56:09 Wednesday.\"\n",
606
+ " },\n",
607
+ " {\n",
608
+ " \"role\": \"user\",\n",
609
+ " \"content\": \"User: I need to cancel a virtual yoga class that I booked. The booking ID is YGA123.\"\n",
610
+ " },\n",
611
+ " {\n",
612
+ " \"role\": \"assistant\",\n",
613
+ " \"content\": \"\",\n",
614
+ " \"tool_calls\": {\n",
615
+ " \"name\": \"cancel_booking\",\n",
616
+ " \"arguments\": {\n",
617
+ " \"booking_id\": \"YGA123\"\n",
618
+ " }\n",
619
+ " }\n",
620
+ " },\n",
621
+ " {\n",
622
+ " \"role\": \"tool\",\n",
623
+ " \"name\": \"cancel_booking\",\n",
624
+ " \"content\": {\n",
625
+ " \"data\": {\n",
626
+ " \"class_name\": \"Yoga for Relaxation\",\n",
627
+ " \"class_time\": \"2039-03-10 17:00\",\n",
628
+ " \"instructor_name\": \"Maggie Zhu\",\n",
629
+ " \"cancellation_time\": \"2039-03-09 19:10\"\n",
630
+ " }\n",
631
+ " }\n",
632
+ " },\n",
633
+ " {\n",
634
+ " \"role\": \"assistant\",\n",
635
+ " \"content\": \"AI: Your booking for Yoga for Relaxation with Maggie Zhu on 2039-03-10 at 17:00 has been successfully cancelled and the cancellation time is 2039-03-09 19:10.\"\n",
636
+ " },\n",
637
+ " {\n",
638
+ " \"role\": \"user\",\n",
639
+ " \"content\": \"User: Can you please show me the virtual yoga and meditation classes available on the platform for tomorrow at 10am?\"\n",
640
+ " },\n",
641
+ " {\n",
642
+ " \"role\": \"assistant\",\n",
643
+ " \"content\": \"\",\n",
644
+ " \"tool_calls\": {\n",
645
+ " \"name\": \"get_classes\",\n",
646
+ " \"arguments\": {\n",
647
+ " \"date\": \"2039-03-10\",\n",
648
+ " \"time\": \"10:00\"\n",
649
+ " }\n",
650
+ " }\n",
651
+ " },\n",
652
+ " {\n",
653
+ " \"role\": \"tool\",\n",
654
+ " \"name\": \"get_classes\",\n",
655
+ " \"content\": {\n",
656
+ " \"data\": [\n",
657
+ " {\n",
658
+ " \"name\": \"Yoga for Relaxation\",\n",
659
+ " \"instructor\": \"Maggie Zhu\",\n",
660
+ " \"time\": \"2039-03-10 10:00\",\n",
661
+ " \"duration\": 60\n",
662
+ " },\n",
663
+ " {\n",
664
+ " \"name\": \"Meditation for Beginners\",\n",
665
+ " \"instructor\": \"John Lee\",\n",
666
+ " \"time\": \"2039-03-10 10:30\",\n",
667
+ " \"duration\": 30\n",
668
+ " }\n",
669
+ " ]\n",
670
+ " }\n",
671
+ " },\n",
672
+ " {\n",
673
+ " \"role\": \"assistant\",\n",
674
+ " \"content\": \"AI: There are two virtual yoga and meditation classes available on the platform for tomorrow at 10am: Yoga for Relaxation with Maggie Zhu that lasts for 60 minutes starting at 10:00 and Meditation for Beginners with John Lee which lasts for 30 minutes, starting at 10:30.\"\n",
675
+ " },\n",
676
+ " {\n",
677
+ " \"role\": \"user\",\n",
678
+ " \"content\": \"User: I'd like to book a virtual meditation class called \\\"Meditation for Beginners\\\" tomorrow at 8am.\"\n",
679
+ " },\n",
680
+ " {\n",
681
+ " \"role\": \"assistant\",\n",
682
+ " \"content\": \"\",\n",
683
+ " \"tool_calls\": {\n",
684
+ " \"name\": \"get_classes\",\n",
685
+ " \"arguments\": {\n",
686
+ " \"date\": \"2039-03-10\",\n",
687
+ " \"time\": \"08:00\"\n",
688
+ " }\n",
689
+ " }\n",
690
+ " },\n",
691
+ " {\n",
692
+ " \"role\": \"tool\",\n",
693
+ " \"name\": \"get_classes\",\n",
694
+ " \"content\": {\n",
695
+ " \"data\": [\n",
696
+ " {\n",
697
+ " \"name\": \"Meditation for Beginners\",\n",
698
+ " \"instructor\": \"John Lee\",\n",
699
+ " \"time\": \"2039-03-10 08:00\",\n",
700
+ " \"duration\": 30\n",
701
+ " }\n",
702
+ " ]\n",
703
+ " }\n",
704
+ " }\n",
705
+ "]"
706
+ ]
707
+ },
708
+ {
709
+ "cell_type": "code",
710
+ "execution_count": 11,
711
+ "metadata": {},
712
+ "outputs": [
713
+ {
714
+ "ename": "TemplateError",
715
+ "evalue": "The tool_calls must be a list!",
716
+ "output_type": "error",
717
+ "traceback": [
718
+ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
719
+ "\u001b[0;31mTemplateError\u001b[0m Traceback (most recent call last)",
720
+ "Cell \u001b[0;32mIn[11], line 4\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 2\u001b[0m \u001b[38;5;124;03mtool_calls is similar to OpenAI requirements, and it should be a list of API call(s), not a dictionary \u001b[39;00m\n\u001b[1;32m 3\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m----> 4\u001b[0m \u001b[43mverify_tokenizer\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmessages_2\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmodel_list\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtools\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mBASE_XLAM_DIR\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mfc_modes\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m \u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mfile_suffix\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mexample_2\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n",
721
+ "Cell \u001b[0;32mIn[7], line 10\u001b[0m, in \u001b[0;36mverify_tokenizer\u001b[0;34m(messages, model_list, tools, BASE_XLAM_DIR, fc_modes, file_suffix)\u001b[0m\n\u001b[1;32m 7\u001b[0m tokenizer \u001b[38;5;241m=\u001b[39m AutoTokenizer\u001b[38;5;241m.\u001b[39mfrom_pretrained(checkpoint)\n\u001b[1;32m 9\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m fc_mode:\n\u001b[0;32m---> 10\u001b[0m model_input \u001b[38;5;241m=\u001b[39m \u001b[43mtokenizer\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mapply_chat_template\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 11\u001b[0m \u001b[43m \u001b[49m\u001b[43mmessages\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 12\u001b[0m \u001b[43m \u001b[49m\u001b[43mtools\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtools\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 13\u001b[0m \u001b[43m \u001b[49m\u001b[43mtokenize\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\n\u001b[1;32m 14\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 15\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 16\u001b[0m model_input \u001b[38;5;241m=\u001b[39m tokenizer\u001b[38;5;241m.\u001b[39mapply_chat_template(\n\u001b[1;32m 17\u001b[0m messages,\n\u001b[1;32m 18\u001b[0m tokenize\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mFalse\u001b[39;00m\n\u001b[1;32m 19\u001b[0m )\n",
722
+ "File \u001b[0;32m/export/agentstudio-family/miniconda3/v2lite-train/lib/python3.10/site-packages/transformers/tokenization_utils_base.py:1867\u001b[0m, in \u001b[0;36mPreTrainedTokenizerBase.apply_chat_template\u001b[0;34m(self, conversation, tools, documents, chat_template, add_generation_prompt, continue_final_message, tokenize, padding, truncation, max_length, return_tensors, return_dict, return_assistant_tokens_mask, tokenizer_kwargs, **kwargs)\u001b[0m\n\u001b[1;32m 1865\u001b[0m all_generation_indices\u001b[38;5;241m.\u001b[39mappend(generation_indices)\n\u001b[1;32m 1866\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m-> 1867\u001b[0m rendered_chat \u001b[38;5;241m=\u001b[39m \u001b[43mcompiled_template\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrender\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 1868\u001b[0m \u001b[43m \u001b[49m\u001b[43mmessages\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mchat\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1869\u001b[0m \u001b[43m \u001b[49m\u001b[43mtools\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtool_schemas\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1870\u001b[0m \u001b[43m \u001b[49m\u001b[43mdocuments\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mdocuments\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1871\u001b[0m \u001b[43m \u001b[49m\u001b[43madd_generation_prompt\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43madd_generation_prompt\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1872\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mtemplate_kwargs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1873\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1874\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m continue_final_message:\n\u001b[1;32m 1875\u001b[0m final_message \u001b[38;5;241m=\u001b[39m chat[\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m1\u001b[39m][\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcontent\u001b[39m\u001b[38;5;124m\"\u001b[39m]\n",
723
+ "File \u001b[0;32m/export/agentstudio-family/miniconda3/v2lite-train/lib/python3.10/site-packages/jinja2/environment.py:1304\u001b[0m, in \u001b[0;36mTemplate.render\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 1302\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39menvironment\u001b[38;5;241m.\u001b[39mconcat(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mroot_render_func(ctx)) \u001b[38;5;66;03m# type: ignore\u001b[39;00m\n\u001b[1;32m 1303\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m:\n\u001b[0;32m-> 1304\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43menvironment\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mhandle_exception\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n",
724
+ "File \u001b[0;32m/export/agentstudio-family/miniconda3/v2lite-train/lib/python3.10/site-packages/jinja2/environment.py:939\u001b[0m, in \u001b[0;36mEnvironment.handle_exception\u001b[0;34m(self, source)\u001b[0m\n\u001b[1;32m 934\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"Exception handling helper. This is used internally to either raise\u001b[39;00m\n\u001b[1;32m 935\u001b[0m \u001b[38;5;124;03mrewritten exceptions or return a rendered traceback for the template.\u001b[39;00m\n\u001b[1;32m 936\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 937\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mdebug\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m rewrite_traceback_stack\n\u001b[0;32m--> 939\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m rewrite_traceback_stack(source\u001b[38;5;241m=\u001b[39msource)\n",
725
+ "File \u001b[0;32m<template>:82\u001b[0m, in \u001b[0;36mtop-level template code\u001b[0;34m()\u001b[0m\n",
726
+ "File \u001b[0;32m/export/agentstudio-family/miniconda3/v2lite-train/lib/python3.10/site-packages/jinja2/sandbox.py:394\u001b[0m, in \u001b[0;36mSandboxedEnvironment.call\u001b[0;34m(_SandboxedEnvironment__self, _SandboxedEnvironment__context, _SandboxedEnvironment__obj, *args, **kwargs)\u001b[0m\n\u001b[1;32m 392\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m __self\u001b[38;5;241m.\u001b[39mis_safe_callable(__obj):\n\u001b[1;32m 393\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m SecurityError(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00m__obj\u001b[38;5;132;01m!r}\u001b[39;00m\u001b[38;5;124m is not safely callable\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m--> 394\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43m__context\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcall\u001b[49m\u001b[43m(\u001b[49m\u001b[43m__obj\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
727
+ "File \u001b[0;32m/export/agentstudio-family/miniconda3/v2lite-train/lib/python3.10/site-packages/transformers/utils/chat_template_utils.py:410\u001b[0m, in \u001b[0;36m_compile_jinja_template.<locals>.raise_exception\u001b[0;34m(message)\u001b[0m\n\u001b[1;32m 409\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mraise_exception\u001b[39m(message):\n\u001b[0;32m--> 410\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m jinja2\u001b[38;5;241m.\u001b[39mexceptions\u001b[38;5;241m.\u001b[39mTemplateError(message)\n",
728
+ "\u001b[0;31mTemplateError\u001b[0m: The tool_calls must be a list!"
729
+ ]
730
+ }
731
+ ],
732
+ "source": [
733
+ "\"\"\"\n",
734
+ "tool_calls is similar to OpenAI requirements, and it should be a list of API call(s), not a dictionary \n",
735
+ "\"\"\"\n",
736
+ "verify_tokenizer(messages_2, model_list, tools, BASE_XLAM_DIR, fc_modes = [True], file_suffix = \"example_2\")"
737
+ ]
738
+ },
739
+ {
740
+ "cell_type": "code",
741
+ "execution_count": 12,
742
+ "metadata": {},
743
+ "outputs": [
744
+ {
745
+ "ename": "TemplateError",
746
+ "evalue": "Conversation roles must alternate user/assistant/user/assistant/...",
747
+ "output_type": "error",
748
+ "traceback": [
749
+ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
750
+ "\u001b[0;31mTemplateError\u001b[0m Traceback (most recent call last)",
751
+ "Cell \u001b[0;32mIn[12], line 6\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 2\u001b[0m \u001b[38;5;124;03mIf you're using the tool_call format, you must adhere to the specific requirements of the tool_call format \u001b[39;00m\n\u001b[1;32m 3\u001b[0m \u001b[38;5;124;03minstead of using the general chat template.\u001b[39;00m\n\u001b[1;32m 4\u001b[0m \u001b[38;5;124;03mTemplateError: Conversation roles must alternate user/assistant/user/assistant/...\u001b[39;00m\n\u001b[1;32m 5\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m----> 6\u001b[0m \u001b[43mverify_tokenizer\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmessages_2\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmodel_list\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtools\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mBASE_XLAM_DIR\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mfc_modes\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m \u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mfile_suffix\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mexample_2\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n",
752
+ "Cell \u001b[0;32mIn[7], line 16\u001b[0m, in \u001b[0;36mverify_tokenizer\u001b[0;34m(messages, model_list, tools, BASE_XLAM_DIR, fc_modes, file_suffix)\u001b[0m\n\u001b[1;32m 10\u001b[0m model_input \u001b[38;5;241m=\u001b[39m tokenizer\u001b[38;5;241m.\u001b[39mapply_chat_template(\n\u001b[1;32m 11\u001b[0m messages,\n\u001b[1;32m 12\u001b[0m tools\u001b[38;5;241m=\u001b[39mtools,\n\u001b[1;32m 13\u001b[0m tokenize\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mFalse\u001b[39;00m\n\u001b[1;32m 14\u001b[0m )\n\u001b[1;32m 15\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m---> 16\u001b[0m model_input \u001b[38;5;241m=\u001b[39m \u001b[43mtokenizer\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mapply_chat_template\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 17\u001b[0m \u001b[43m \u001b[49m\u001b[43mmessages\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 18\u001b[0m \u001b[43m \u001b[49m\u001b[43mtokenize\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\n\u001b[1;32m 19\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 21\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mxlam_8x22b_r\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;129;01min\u001b[39;00m checkpoint:\n\u001b[1;32m 22\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m*\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;241m*\u001b[39m\u001b[38;5;241m100\u001b[39m)\n",
753
+ "File \u001b[0;32m/export/agentstudio-family/miniconda3/v2lite-train/lib/python3.10/site-packages/transformers/tokenization_utils_base.py:1867\u001b[0m, in \u001b[0;36mPreTrainedTokenizerBase.apply_chat_template\u001b[0;34m(self, conversation, tools, documents, chat_template, add_generation_prompt, continue_final_message, tokenize, padding, truncation, max_length, return_tensors, return_dict, return_assistant_tokens_mask, tokenizer_kwargs, **kwargs)\u001b[0m\n\u001b[1;32m 1865\u001b[0m all_generation_indices\u001b[38;5;241m.\u001b[39mappend(generation_indices)\n\u001b[1;32m 1866\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m-> 1867\u001b[0m rendered_chat \u001b[38;5;241m=\u001b[39m \u001b[43mcompiled_template\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrender\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 1868\u001b[0m \u001b[43m \u001b[49m\u001b[43mmessages\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mchat\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1869\u001b[0m \u001b[43m \u001b[49m\u001b[43mtools\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtool_schemas\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1870\u001b[0m \u001b[43m \u001b[49m\u001b[43mdocuments\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mdocuments\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1871\u001b[0m \u001b[43m \u001b[49m\u001b[43madd_generation_prompt\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43madd_generation_prompt\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1872\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mtemplate_kwargs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1873\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1874\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m continue_final_message:\n\u001b[1;32m 1875\u001b[0m final_message \u001b[38;5;241m=\u001b[39m chat[\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m1\u001b[39m][\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcontent\u001b[39m\u001b[38;5;124m\"\u001b[39m]\n",
754
+ "File \u001b[0;32m/export/agentstudio-family/miniconda3/v2lite-train/lib/python3.10/site-packages/jinja2/environment.py:1304\u001b[0m, in \u001b[0;36mTemplate.render\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 1302\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39menvironment\u001b[38;5;241m.\u001b[39mconcat(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mroot_render_func(ctx)) \u001b[38;5;66;03m# type: ignore\u001b[39;00m\n\u001b[1;32m 1303\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m:\n\u001b[0;32m-> 1304\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43menvironment\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mhandle_exception\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n",
755
+ "File \u001b[0;32m/export/agentstudio-family/miniconda3/v2lite-train/lib/python3.10/site-packages/jinja2/environment.py:939\u001b[0m, in \u001b[0;36mEnvironment.handle_exception\u001b[0;34m(self, source)\u001b[0m\n\u001b[1;32m 934\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"Exception handling helper. This is used internally to either raise\u001b[39;00m\n\u001b[1;32m 935\u001b[0m \u001b[38;5;124;03mrewritten exceptions or return a rendered traceback for the template.\u001b[39;00m\n\u001b[1;32m 936\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 937\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mdebug\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m rewrite_traceback_stack\n\u001b[0;32m--> 939\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m rewrite_traceback_stack(source\u001b[38;5;241m=\u001b[39msource)\n",
756
+ "File \u001b[0;32m<template>:1\u001b[0m, in \u001b[0;36mtop-level template code\u001b[0;34m()\u001b[0m\n",
757
+ "File \u001b[0;32m/export/agentstudio-family/miniconda3/v2lite-train/lib/python3.10/site-packages/jinja2/sandbox.py:394\u001b[0m, in \u001b[0;36mSandboxedEnvironment.call\u001b[0;34m(_SandboxedEnvironment__self, _SandboxedEnvironment__context, _SandboxedEnvironment__obj, *args, **kwargs)\u001b[0m\n\u001b[1;32m 392\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m __self\u001b[38;5;241m.\u001b[39mis_safe_callable(__obj):\n\u001b[1;32m 393\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m SecurityError(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00m__obj\u001b[38;5;132;01m!r}\u001b[39;00m\u001b[38;5;124m is not safely callable\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m--> 394\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43m__context\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcall\u001b[49m\u001b[43m(\u001b[49m\u001b[43m__obj\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
758
+ "File \u001b[0;32m/export/agentstudio-family/miniconda3/v2lite-train/lib/python3.10/site-packages/transformers/utils/chat_template_utils.py:410\u001b[0m, in \u001b[0;36m_compile_jinja_template.<locals>.raise_exception\u001b[0;34m(message)\u001b[0m\n\u001b[1;32m 409\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mraise_exception\u001b[39m(message):\n\u001b[0;32m--> 410\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m jinja2\u001b[38;5;241m.\u001b[39mexceptions\u001b[38;5;241m.\u001b[39mTemplateError(message)\n",
759
+ "\u001b[0;31mTemplateError\u001b[0m: Conversation roles must alternate user/assistant/user/assistant/..."
760
+ ]
761
+ }
762
+ ],
763
+ "source": [
764
+ "\"\"\"\n",
765
+ "If you're using the tool_call format, you must adhere to the specific requirements of the tool_call chat template\n",
766
+ "instead of using the general chat template.\n",
767
+ "TemplateError: Conversation roles must alternate user/assistant/user/assistant/...\n",
768
+ "\"\"\"\n",
769
+ "verify_tokenizer(messages_2, model_list, tools, BASE_XLAM_DIR, fc_modes = [False], file_suffix = \"example_2\")"
770
+ ]
771
+ },
772
+ {
773
+ "cell_type": "markdown",
774
+ "metadata": {},
775
+ "source": [
776
+ "### Example 3 (add a user turn after user/assistant/tool)"
777
+ ]
778
+ },
779
+ {
780
+ "cell_type": "code",
781
+ "execution_count": 15,
782
+ "metadata": {},
783
+ "outputs": [],
784
+ "source": [
785
+ "messages_3 = [\n",
786
+ " {\n",
787
+ " \"role\": \"system\",\n",
788
+ " \"content\": \"Based on the previous context and API request history, generate an API request or a response as an AI assistant. The current time is 2039-03-09 18:56:09 Wednesday.\"\n",
789
+ " },\n",
790
+ " {\n",
791
+ " \"role\": \"user\",\n",
792
+ " \"content\": \"User: I need to cancel a virtual yoga class that I booked. The booking ID is YGA123.\"\n",
793
+ " },\n",
794
+ " {\n",
795
+ " \"role\": \"assistant\",\n",
796
+ " \"content\": \"\",\n",
797
+ " \"tool_calls\": [\n",
798
+ " {\n",
799
+ " \"name\": \"cancel_booking\",\n",
800
+ " \"arguments\": {\n",
801
+ " \"booking_id\": \"YGA123\"\n",
802
+ " }\n",
803
+ " }\n",
804
+ " ]\n",
805
+ " },\n",
806
+ " {\n",
807
+ " \"role\": \"tool\",\n",
808
+ " \"name\": \"cancel_booking\",\n",
809
+ " \"content\": {\n",
810
+ " \"data\": {\n",
811
+ " \"class_name\": \"Yoga for Relaxation\",\n",
812
+ " \"class_time\": \"2039-03-10 17:00\",\n",
813
+ " \"instructor_name\": \"Maggie Zhu\",\n",
814
+ " \"cancellation_time\": \"2039-03-09 19:10\"\n",
815
+ " }\n",
816
+ " }\n",
817
+ " },\n",
818
+ " {\n",
819
+ " \"role\": \"assistant\",\n",
820
+ " \"content\": \"AI: Your booking for Yoga for Relaxation with Maggie Zhu on 2039-03-10 at 17:00 has been successfully cancelled and the cancellation time is 2039-03-09 19:10.\"\n",
821
+ " },\n",
822
+ " {\n",
823
+ " \"role\": \"user\",\n",
824
+ " \"content\": \"User: Can you please show me the virtual yoga and meditation classes available on the platform for tomorrow at 10am?\"\n",
825
+ " },\n",
826
+ " {\n",
827
+ " \"role\": \"assistant\",\n",
828
+ " \"content\": \"\",\n",
829
+ " \"tool_calls\": [\n",
830
+ " {\n",
831
+ " \"name\": \"get_classes\",\n",
832
+ " \"arguments\": {\n",
833
+ " \"date\": \"2039-03-10\",\n",
834
+ " \"time\": \"10:00\"\n",
835
+ " }\n",
836
+ " }\n",
837
+ " ]\n",
838
+ " },\n",
839
+ " {\n",
840
+ " \"role\": \"tool\",\n",
841
+ " \"name\": \"get_classes\",\n",
842
+ " \"content\": {\n",
843
+ " \"data\": [\n",
844
+ " {\n",
845
+ " \"name\": \"Yoga for Relaxation\",\n",
846
+ " \"instructor\": \"Maggie Zhu\",\n",
847
+ " \"time\": \"2039-03-10 10:00\",\n",
848
+ " \"duration\": 60\n",
849
+ " },\n",
850
+ " {\n",
851
+ " \"name\": \"Meditation for Beginners\",\n",
852
+ " \"instructor\": \"John Lee\",\n",
853
+ " \"time\": \"2039-03-10 10:30\",\n",
854
+ " \"duration\": 30\n",
855
+ " }\n",
856
+ " ]\n",
857
+ " }\n",
858
+ " },\n",
859
+ " {\n",
860
+ " \"role\": \"assistant\",\n",
861
+ " \"content\": \"AI: There are two virtual yoga and meditation classes available on the platform for tomorrow at 10am: Yoga for Relaxation with Maggie Zhu that lasts for 60 minutes starting at 10:00 and Meditation for Beginners with John Lee which lasts for 30 minutes, starting at 10:30.\"\n",
862
+ " },\n",
863
+ " {\n",
864
+ " \"role\": \"user\",\n",
865
+ " \"content\": \"User: I'd like to book a virtual meditation class called \\\"Meditation for Beginners\\\" tomorrow at 8am.\"\n",
866
+ " },\n",
867
+ " {\n",
868
+ " \"role\": \"assistant\",\n",
869
+ " \"content\": \"\",\n",
870
+ " \"tool_calls\": [\n",
871
+ " {\n",
872
+ " \"name\": \"get_classes\",\n",
873
+ " \"arguments\": {\n",
874
+ " \"date\": \"2039-03-10\",\n",
875
+ " \"time\": \"08:00\"\n",
876
+ " }\n",
877
+ " }\n",
878
+ " ]\n",
879
+ " },\n",
880
+ " {\n",
881
+ " \"role\": \"tool\",\n",
882
+ " \"name\": \"get_classes\",\n",
883
+ " \"content\": {\n",
884
+ " \"data\": [\n",
885
+ " {\n",
886
+ " \"name\": \"Meditation for Beginners\",\n",
887
+ " \"instructor\": \"John Lee\",\n",
888
+ " \"time\": \"2039-03-10 08:00\",\n",
889
+ " \"duration\": 30\n",
890
+ " }\n",
891
+ " ]\n",
892
+ " }\n",
893
+ " },\n",
894
+ " {\n",
895
+ " \"role\": \"user\",\n",
896
+ " \"content\": \"Thanks very much for your help!\"\n",
897
+ " },\n",
898
+ "]"
899
+ ]
900
+ },
901
+ {
902
+ "cell_type": "code",
903
+ "execution_count": 16,
904
+ "metadata": {},
905
+ "outputs": [
906
+ {
907
+ "ename": "TemplateError",
908
+ "evalue": "After the optional system message, conversation roles can only be from user/assistant/tool; After each tool message, the next message must be from the assistant",
909
+ "output_type": "error",
910
+ "traceback": [
911
+ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
912
+ "\u001b[0;31mTemplateError\u001b[0m Traceback (most recent call last)",
913
+ "Cell \u001b[0;32mIn[16], line 5\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 2\u001b[0m \u001b[38;5;124;03mAfter the optional system message, conversation roles can only be from user/assistant/tool; \u001b[39;00m\n\u001b[1;32m 3\u001b[0m \u001b[38;5;124;03mAfter each tool message, the next message must be from the assistant\u001b[39;00m\n\u001b[1;32m 4\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m----> 5\u001b[0m \u001b[43mverify_tokenizer\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmessages_3\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmodel_list\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtools\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mBASE_XLAM_DIR\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mfc_modes\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m \u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mfile_suffix\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mexample_3\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n",
914
+ "Cell \u001b[0;32mIn[7], line 10\u001b[0m, in \u001b[0;36mverify_tokenizer\u001b[0;34m(messages, model_list, tools, BASE_XLAM_DIR, fc_modes, file_suffix)\u001b[0m\n\u001b[1;32m 7\u001b[0m tokenizer \u001b[38;5;241m=\u001b[39m AutoTokenizer\u001b[38;5;241m.\u001b[39mfrom_pretrained(checkpoint)\n\u001b[1;32m 9\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m fc_mode:\n\u001b[0;32m---> 10\u001b[0m model_input \u001b[38;5;241m=\u001b[39m \u001b[43mtokenizer\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mapply_chat_template\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 11\u001b[0m \u001b[43m \u001b[49m\u001b[43mmessages\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 12\u001b[0m \u001b[43m \u001b[49m\u001b[43mtools\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtools\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 13\u001b[0m \u001b[43m \u001b[49m\u001b[43mtokenize\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\n\u001b[1;32m 14\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 15\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 16\u001b[0m model_input \u001b[38;5;241m=\u001b[39m tokenizer\u001b[38;5;241m.\u001b[39mapply_chat_template(\n\u001b[1;32m 17\u001b[0m messages,\n\u001b[1;32m 18\u001b[0m tokenize\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mFalse\u001b[39;00m\n\u001b[1;32m 19\u001b[0m )\n",
915
+ "File \u001b[0;32m/export/agentstudio-family/miniconda3/v2lite-train/lib/python3.10/site-packages/transformers/tokenization_utils_base.py:1867\u001b[0m, in \u001b[0;36mPreTrainedTokenizerBase.apply_chat_template\u001b[0;34m(self, conversation, tools, documents, chat_template, add_generation_prompt, continue_final_message, tokenize, padding, truncation, max_length, return_tensors, return_dict, return_assistant_tokens_mask, tokenizer_kwargs, **kwargs)\u001b[0m\n\u001b[1;32m 1865\u001b[0m all_generation_indices\u001b[38;5;241m.\u001b[39mappend(generation_indices)\n\u001b[1;32m 1866\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m-> 1867\u001b[0m rendered_chat \u001b[38;5;241m=\u001b[39m \u001b[43mcompiled_template\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrender\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 1868\u001b[0m \u001b[43m \u001b[49m\u001b[43mmessages\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mchat\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1869\u001b[0m \u001b[43m \u001b[49m\u001b[43mtools\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtool_schemas\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1870\u001b[0m \u001b[43m \u001b[49m\u001b[43mdocuments\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mdocuments\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1871\u001b[0m \u001b[43m \u001b[49m\u001b[43madd_generation_prompt\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43madd_generation_prompt\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1872\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mtemplate_kwargs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1873\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1874\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m continue_final_message:\n\u001b[1;32m 1875\u001b[0m final_message \u001b[38;5;241m=\u001b[39m chat[\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m1\u001b[39m][\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcontent\u001b[39m\u001b[38;5;124m\"\u001b[39m]\n",
916
+ "File \u001b[0;32m/export/agentstudio-family/miniconda3/v2lite-train/lib/python3.10/site-packages/jinja2/environment.py:1304\u001b[0m, in \u001b[0;36mTemplate.render\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 1302\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39menvironment\u001b[38;5;241m.\u001b[39mconcat(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mroot_render_func(ctx)) \u001b[38;5;66;03m# type: ignore\u001b[39;00m\n\u001b[1;32m 1303\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m:\n\u001b[0;32m-> 1304\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43menvironment\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mhandle_exception\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n",
917
+ "File \u001b[0;32m/export/agentstudio-family/miniconda3/v2lite-train/lib/python3.10/site-packages/jinja2/environment.py:939\u001b[0m, in \u001b[0;36mEnvironment.handle_exception\u001b[0;34m(self, source)\u001b[0m\n\u001b[1;32m 934\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"Exception handling helper. This is used internally to either raise\u001b[39;00m\n\u001b[1;32m 935\u001b[0m \u001b[38;5;124;03mrewritten exceptions or return a rendered traceback for the template.\u001b[39;00m\n\u001b[1;32m 936\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 937\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mdebug\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m rewrite_traceback_stack\n\u001b[0;32m--> 939\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m rewrite_traceback_stack(source\u001b[38;5;241m=\u001b[39msource)\n",
918
+ "File \u001b[0;32m<template>:21\u001b[0m, in \u001b[0;36mtop-level template code\u001b[0;34m()\u001b[0m\n",
919
+ "File \u001b[0;32m/export/agentstudio-family/miniconda3/v2lite-train/lib/python3.10/site-packages/jinja2/sandbox.py:394\u001b[0m, in \u001b[0;36mSandboxedEnvironment.call\u001b[0;34m(_SandboxedEnvironment__self, _SandboxedEnvironment__context, _SandboxedEnvironment__obj, *args, **kwargs)\u001b[0m\n\u001b[1;32m 392\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m __self\u001b[38;5;241m.\u001b[39mis_safe_callable(__obj):\n\u001b[1;32m 393\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m SecurityError(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00m__obj\u001b[38;5;132;01m!r}\u001b[39;00m\u001b[38;5;124m is not safely callable\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m--> 394\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43m__context\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcall\u001b[49m\u001b[43m(\u001b[49m\u001b[43m__obj\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
920
+ "File \u001b[0;32m/export/agentstudio-family/miniconda3/v2lite-train/lib/python3.10/site-packages/transformers/utils/chat_template_utils.py:410\u001b[0m, in \u001b[0;36m_compile_jinja_template.<locals>.raise_exception\u001b[0;34m(message)\u001b[0m\n\u001b[1;32m 409\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mraise_exception\u001b[39m(message):\n\u001b[0;32m--> 410\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m jinja2\u001b[38;5;241m.\u001b[39mexceptions\u001b[38;5;241m.\u001b[39mTemplateError(message)\n",
921
+ "\u001b[0;31mTemplateError\u001b[0m: After the optional system message, conversation roles can only be from user/assistant/tool; After each tool message, the next message must be from the assistant"
922
+ ]
923
+ }
924
+ ],
925
+ "source": [
926
+ "\"\"\"\n",
927
+ "After the optional system message, conversation roles can only be from user/assistant/tool; \n",
928
+ "After each tool message, the next message must be from the assistant\n",
929
+ "\"\"\"\n",
930
+ "verify_tokenizer(messages_3, model_list, tools, BASE_XLAM_DIR, fc_modes = [True], file_suffix = \"example_3\")"
931
+ ]
932
+ },
933
+ {
934
+ "cell_type": "markdown",
935
+ "metadata": {},
936
+ "source": [
937
+ "### Example 4 (add an assistant/user turn after user/assistant/tool)"
938
+ ]
939
+ },
940
+ {
941
+ "cell_type": "code",
942
+ "execution_count": 19,
943
+ "metadata": {},
944
+ "outputs": [],
945
+ "source": [
946
+ "messages_4 = [\n",
947
+ " {\n",
948
+ " \"role\": \"system\",\n",
949
+ " \"content\": \"Based on the previous context and API request history, generate an API request or a response as an AI assistant. The current time is 2039-03-09 18:56:09 Wednesday.\"\n",
950
+ " },\n",
951
+ " {\n",
952
+ " \"role\": \"user\",\n",
953
+ " \"content\": \"User: I need to cancel a virtual yoga class that I booked. The booking ID is YGA123.\"\n",
954
+ " },\n",
955
+ " {\n",
956
+ " \"role\": \"assistant\",\n",
957
+ " \"content\": \"\",\n",
958
+ " \"tool_calls\": [\n",
959
+ " {\n",
960
+ " \"name\": \"cancel_booking\",\n",
961
+ " \"arguments\": {\n",
962
+ " \"booking_id\": \"YGA123\"\n",
963
+ " }\n",
964
+ " }\n",
965
+ " ]\n",
966
+ " },\n",
967
+ " {\n",
968
+ " \"role\": \"tool\",\n",
969
+ " \"name\": \"cancel_booking\",\n",
970
+ " \"content\": {\n",
971
+ " \"data\": {\n",
972
+ " \"class_name\": \"Yoga for Relaxation\",\n",
973
+ " \"class_time\": \"2039-03-10 17:00\",\n",
974
+ " \"instructor_name\": \"Maggie Zhu\",\n",
975
+ " \"cancellation_time\": \"2039-03-09 19:10\"\n",
976
+ " }\n",
977
+ " }\n",
978
+ " },\n",
979
+ " {\n",
980
+ " \"role\": \"assistant\",\n",
981
+ " \"content\": \"AI: Your booking for Yoga for Relaxation with Maggie Zhu on 2039-03-10 at 17:00 has been successfully cancelled and the cancellation time is 2039-03-09 19:10.\"\n",
982
+ " },\n",
983
+ " {\n",
984
+ " \"role\": \"user\",\n",
985
+ " \"content\": \"User: Can you please show me the virtual yoga and meditation classes available on the platform for tomorrow at 10am?\"\n",
986
+ " },\n",
987
+ " {\n",
988
+ " \"role\": \"assistant\",\n",
989
+ " \"content\": \"\",\n",
990
+ " \"tool_calls\": [\n",
991
+ " {\n",
992
+ " \"name\": \"get_classes\",\n",
993
+ " \"arguments\": {\n",
994
+ " \"date\": \"2039-03-10\",\n",
995
+ " \"time\": \"10:00\"\n",
996
+ " }\n",
997
+ " }\n",
998
+ " ]\n",
999
+ " },\n",
1000
+ " {\n",
1001
+ " \"role\": \"tool\",\n",
1002
+ " \"name\": \"get_classes\",\n",
1003
+ " \"content\": {\n",
1004
+ " \"data\": [\n",
1005
+ " {\n",
1006
+ " \"name\": \"Yoga for Relaxation\",\n",
1007
+ " \"instructor\": \"Maggie Zhu\",\n",
1008
+ " \"time\": \"2039-03-10 10:00\",\n",
1009
+ " \"duration\": 60\n",
1010
+ " },\n",
1011
+ " {\n",
1012
+ " \"name\": \"Meditation for Beginners\",\n",
1013
+ " \"instructor\": \"John Lee\",\n",
1014
+ " \"time\": \"2039-03-10 10:30\",\n",
1015
+ " \"duration\": 30\n",
1016
+ " }\n",
1017
+ " ]\n",
1018
+ " }\n",
1019
+ " },\n",
1020
+ " {\n",
1021
+ " \"role\": \"assistant\",\n",
1022
+ " \"content\": \"AI: There are two virtual yoga and meditation classes available on the platform for tomorrow at 10am: Yoga for Relaxation with Maggie Zhu that lasts for 60 minutes starting at 10:00 and Meditation for Beginners with John Lee which lasts for 30 minutes, starting at 10:30.\"\n",
1023
+ " },\n",
1024
+ " {\n",
1025
+ " \"role\": \"user\",\n",
1026
+ " \"content\": \"User: I'd like to book a virtual meditation class called \\\"Meditation for Beginners\\\" tomorrow at 8am.\"\n",
1027
+ " },\n",
1028
+ " {\n",
1029
+ " \"role\": \"assistant\",\n",
1030
+ " \"content\": \"\",\n",
1031
+ " \"tool_calls\": [\n",
1032
+ " {\n",
1033
+ " \"name\": \"get_classes\",\n",
1034
+ " \"arguments\": {\n",
1035
+ " \"date\": \"2039-03-10\",\n",
1036
+ " \"time\": \"08:00\"\n",
1037
+ " }\n",
1038
+ " }\n",
1039
+ " ]\n",
1040
+ " },\n",
1041
+ " {\n",
1042
+ " \"role\": \"tool\",\n",
1043
+ " \"name\": \"get_classes\",\n",
1044
+ " \"content\": {\n",
1045
+ " \"data\": [\n",
1046
+ " {\n",
1047
+ " \"name\": \"Meditation for Beginners\",\n",
1048
+ " \"instructor\": \"John Lee\",\n",
1049
+ " \"time\": \"2039-03-10 08:00\",\n",
1050
+ " \"duration\": 30\n",
1051
+ " }\n",
1052
+ " ]\n",
1053
+ " }\n",
1054
+ " },\n",
1055
+ " {\n",
1056
+ " \"role\": \"assistant\",\n",
1057
+ " \"content\": \"I have booked a meditation class for you!\"\n",
1058
+ " },\n",
1059
+ " {\n",
1060
+ " \"role\": \"user\",\n",
1061
+ " \"content\": \"Thanks very much for your help!\"\n",
1062
+ " },\n",
1063
+ "]"
1064
+ ]
1065
+ },
1066
+ {
1067
+ "cell_type": "code",
1068
+ "execution_count": 20,
1069
+ "metadata": {},
1070
+ "outputs": [
1071
+ {
1072
+ "name": "stdout",
1073
+ "output_type": "stream",
1074
+ "text": [
1075
+ "****************************************************************************************************\n",
1076
+ "Checkpoint: /export/agentstudio-family/checkpoints/xlam_v1/xlam_8x22b_r\n",
1077
+ "----------------------------------------------------------------------------------------------------\n",
1078
+ "FC Mode: True\n",
1079
+ "----------------------------------------------------------------------------------------------------\n",
1080
+ "<s>[INST]\n",
1081
+ "[BEGIN OF TASK INSTRUCTION]\n",
1082
+ "Based on the previous context and API request history, generate an API request or a response as an AI assistant. The current time is 2039-03-09 18:56:09 Wednesday.\n",
1083
+ "[END OF TASK INSTRUCTION]\n",
1084
+ "\n",
1085
+ "[BEGIN OF AVAILABLE_TOOLS]\n",
1086
+ "[{'type': 'function', 'function': {'name': 'get_current_weather', 'description': 'Get the current weather', 'parameters': {'type': 'object', 'properties': {'location': {'type': 'string', 'description': 'The city and state, e.g. San Francisco, CA'}, 'format': {'type': 'string', 'enum': ['celsius', 'fahrenheit'], 'description': 'The temperature unit to use. Infer this from the users location.'}, 'date': {'type': 'integer', 'description': 'a specific date to get the weather for'}}, 'required': ['location', 'format', 'date']}}}, {'type': 'function', 'function': {'name': 'get_current_temperature', 'description': 'Get the current temperature at a location.', 'parameters': {'type': 'object', 'properties': {'location': {'type': 'string', 'description': 'The location to get the temperature for, in the format \"City, Country\"'}, 'unit': {'type': 'string', 'enum': ['celsius', 'fahrenheit'], 'description': 'The unit to return the temperature in.'}, 'longitude': {'type': 'number', 'description': 'the longitude of the location'}, 'latitude': {'type': 'number', 'description': 'the latitude of the location'}}, 'required': ['location', 'unit', 'longitude', 'latitude']}, 'return': {'type': 'number', 'description': 'The current temperature at the specified location in the specified units, as a float.'}}}, {'type': 'function', 'function': {'name': 'get_current_wind_speed', 'description': 'Get the current wind speed in km/h at a given location.', 'parameters': {'type': 'object', 'properties': {'location': {'type': 'string', 'description': 'The location to get the temperature for, in the format \"City, Country\"'}}, 'required': ['location']}, 'return': {'type': 'number', 'description': 'The current wind speed at the given location in km/h, as a float.'}}}]\n",
1087
+ "[END OF AVAILABLE_TOOLS]\n",
1088
+ "\n",
1089
+ "[BEGIN OF FORMAT INSTRUCTION]\n",
1090
+ "Your output should be in the JSON format, which specifies a list of function calls. The example format is as follows. Please make sure the parameter type is correct. If no function call is needed, please make tool_calls an empty list '[]'.\n",
1091
+ "```{\"thought\": \"the thought process, or an empty string\", \"tool_calls\": [{\"name\": \"api_name1\", \"arguments\": {\"argument1\": \"value1\", \"argument2\": \"value2\"}}]}```\n",
1092
+ "[END OF FORMAT INSTRUCTION]\n",
1093
+ "\n",
1094
+ "[BEGIN OF QUERY]\n",
1095
+ "User: I need to cancel a virtual yoga class that I booked. The booking ID is YGA123.\n",
1096
+ "[END OF QUERY]\n",
1097
+ "\n",
1098
+ "[BEGIN OF HISTORY STEPS]\n",
1099
+ "[{'thought':\"\", 'tool_calls':[{\"name\": \"cancel_booking\", \"arguments\": {\"booking_id\": \"YGA123\"}}], 'step_id':1, 'next_observation':{\"data\": {\"class_name\": \"Yoga for Relaxation\", \"class_time\": \"2039-03-10 17:00\", \"instructor_name\": \"Maggie Zhu\", \"cancellation_time\": \"2039-03-09 19:10\"}}}, {'thought':\"AI: Your booking for Yoga for Relaxation with Maggie Zhu on 2039-03-10 at 17:00 has been successfully cancelled and the cancellation time is 2039-03-09 19:10.\", 'tool_calls':[], 'step_id':2, 'next_observation':'', 'user_input':\"User: Can you please show me the virtual yoga and meditation classes available on the platform for tomorrow at 10am?\"}, {'thought':\"\", 'tool_calls':[{\"name\": \"get_classes\", \"arguments\": {\"date\": \"2039-03-10\", \"time\": \"10:00\"}}], 'step_id':3, 'next_observation':{\"data\": [{\"name\": \"Yoga for Relaxation\", \"instructor\": \"Maggie Zhu\", \"time\": \"2039-03-10 10:00\", \"duration\": 60}, {\"name\": \"Meditation for Beginners\", \"instructor\": \"John Lee\", \"time\": \"2039-03-10 10:30\", \"duration\": 30}]}}, {'thought':\"AI: There are two virtual yoga and meditation classes available on the platform for tomorrow at 10am: Yoga for Relaxation with Maggie Zhu that lasts for 60 minutes starting at 10:00 and Meditation for Beginners with John Lee which lasts for 30 minutes, starting at 10:30.\", 'tool_calls':[], 'step_id':4, 'next_observation':'', 'user_input':\"User: I'd like to book a virtual meditation class called \\\"Meditation for Beginners\\\" tomorrow at 8am.\"}, {'thought':\"\", 'tool_calls':[{\"name\": \"get_classes\", \"arguments\": {\"date\": \"2039-03-10\", \"time\": \"08:00\"}}], 'step_id':5, 'next_observation':{\"data\": [{\"name\": \"Meditation for Beginners\", \"instructor\": \"John Lee\", \"time\": \"2039-03-10 08:00\", \"duration\": 30}]}}, {'thought':\"I have booked a meditation class for you!\", 'tool_calls':[], 'step_id':6, 'next_observation':'', 'user_input':\"Thanks very much for your help!\"} ]\n",
1100
+ "[END OF HISTORY STEPS]\n",
1101
+ "[/INST]\n"
1102
+ ]
1103
+ }
1104
+ ],
1105
+ "source": [
1106
+ "verify_tokenizer(messages_4, model_list, tools, BASE_XLAM_DIR, fc_modes = [True], file_suffix = \"example_4\")"
1107
+ ]
1108
+ },
1109
+ {
1110
+ "cell_type": "markdown",
1111
+ "metadata": {},
1112
+ "source": [
1113
+ "### Example 4 (Parallem Function Call)"
1114
+ ]
1115
+ },
1116
+ {
1117
+ "cell_type": "code",
1118
+ "execution_count": 21,
1119
+ "metadata": {},
1120
+ "outputs": [
1121
+ {
1122
+ "name": "stdout",
1123
+ "output_type": "stream",
1124
+ "text": [
1125
+ "****************************************************************************************************\n",
1126
+ "Checkpoint: /export/agentstudio-family/checkpoints/xlam_v1/xlam_8x22b_r\n",
1127
+ "----------------------------------------------------------------------------------------------------\n",
1128
+ "FC Mode: True\n",
1129
+ "----------------------------------------------------------------------------------------------------\n",
1130
+ "<s>[INST]\n",
1131
+ "[BEGIN OF TASK INSTRUCTION]\n",
1132
+ "You are an expert in composing functions. You are given a question and a set of possible functions. \n",
1133
+ "Based on the question, you will need to make one or more function/tool calls to achieve the purpose. \n",
1134
+ "If none of the function can be used, point it out and refuse to answer. \n",
1135
+ "If the given question lacks the parameters required by the function, also point it out.\n",
1136
+ "[END OF TASK INSTRUCTION]\n",
1137
+ "\n",
1138
+ "[BEGIN OF AVAILABLE_TOOLS]\n",
1139
+ "[{'name': 'sticker_trending', 'description': 'Fetches the latest trending stickers from Giphy using the specified parameters.', 'parameters': {'s': {'description': 'The term or phrase to translate into a sticker.', 'type': 'str', 'default': 'hungry'}, 'limit': {'description': 'The number of results to return, with a maximum of 100. Defaults to 25.', 'type': 'str, optional', 'default': ''}, 'offset': {'description': 'The results offset, defaults to 0.', 'type': 'str, optional', 'default': ''}, 'fmt': {'description': \"The format in which to return results, either 'html' or 'json'.\", 'type': 'str, optional', 'default': ''}, 'rating': {'description': \"The content rating to limit results to, one of 'y', 'g', 'pg', 'pg-13', or 'r'.\", 'type': 'str, optional', 'default': ''}}}, {'name': 'reels_downloader', 'description': 'Downloads Instagram reels or posts using a given link and RapidAPI key.', 'parameters': {'link': {'description': 'The URL of the Instagram media (reel or post) to be downloaded.', 'type': 'str', 'default': 'https://www.instagram.com/reels/CsinDvAgoYA/'}}}]\n",
1140
+ "[END OF AVAILABLE_TOOLS]\n",
1141
+ "\n",
1142
+ "[BEGIN OF FORMAT INSTRUCTION]\n",
1143
+ "Your output should be in the JSON format, which specifies a list of function calls. The example format is as follows. Please make sure the parameter type is correct. If no function call is needed, please make tool_calls an empty list '[]'.\n",
1144
+ "```{\"thought\": \"the thought process, or an empty string\", \"tool_calls\": [{\"name\": \"api_name1\", \"arguments\": {\"argument1\": \"value1\", \"argument2\": \"value2\"}}]}```\n",
1145
+ "[END OF FORMAT INSTRUCTION]\n",
1146
+ "\n",
1147
+ "[BEGIN OF QUERY]\n",
1148
+ "Get trending stickers for the term 'cat' in HTML format. Also, find trending stickers for 'dog' with a G rating and limit of 20.\n",
1149
+ "[END OF QUERY]\n",
1150
+ "\n",
1151
+ "[BEGIN OF HISTORY STEPS]\n",
1152
+ "[{'thought':\"Two requests are formulated: one for 'cat' stickers with a specific format, and another for 'dog' stickers with rating and limit.\", 'tool_calls':[{\"name\": \"sticker_trending\", \"arguments\": {\"s\": \"cat\", \"fmt\": \"html\"}}, {\"name\": \"sticker_trending\", \"arguments\": {\"s\": \"dog\", \"rating\": \"g\", \"limit\": \"20\"}}], 'step_id':1, 'next_observation':''}]\n",
1153
+ "[END OF HISTORY STEPS]\n",
1154
+ "[/INST]\n"
1155
+ ]
1156
+ }
1157
+ ],
1158
+ "source": [
1159
+ "messages_5 = [\n",
1160
+ " {\n",
1161
+ " \"role\": \"system\",\n",
1162
+ " \"content\": \"You are an expert in composing functions. You are given a question and a set of possible functions. \\nBased on the question, you will need to make one or more function/tool calls to achieve the purpose. \\nIf none of the function can be used, point it out and refuse to answer. \\nIf the given question lacks the parameters required by the function, also point it out.\"\n",
1163
+ " },\n",
1164
+ " {\n",
1165
+ " \"role\": \"user\",\n",
1166
+ " \"content\": \"Get trending stickers for the term 'cat' in HTML format. Also, find trending stickers for 'dog' with a G rating and limit of 20.\"\n",
1167
+ " },\n",
1168
+ " {\n",
1169
+ " \"role\": \"assistant\",\n",
1170
+ " \"content\": \"Two requests are formulated: one for 'cat' stickers with a specific format, and another for 'dog' stickers with rating and limit.\",\n",
1171
+ " \"tool_calls\": [\n",
1172
+ " {\n",
1173
+ " \"name\": \"sticker_trending\",\n",
1174
+ " \"arguments\": {\n",
1175
+ " \"s\": \"cat\",\n",
1176
+ " \"fmt\": \"html\"\n",
1177
+ " }\n",
1178
+ " },\n",
1179
+ " {\n",
1180
+ " \"name\": \"sticker_trending\",\n",
1181
+ " \"arguments\": {\n",
1182
+ " \"s\": \"dog\",\n",
1183
+ " \"rating\": \"g\",\n",
1184
+ " \"limit\": \"20\"\n",
1185
+ " }\n",
1186
+ " }\n",
1187
+ " ]\n",
1188
+ " }\n",
1189
+ "]\n",
1190
+ "\n",
1191
+ "tools_5 = [\n",
1192
+ " {\n",
1193
+ " \"name\": \"sticker_trending\",\n",
1194
+ " \"description\": \"Fetches the latest trending stickers from Giphy using the specified parameters.\",\n",
1195
+ " \"parameters\": {\n",
1196
+ " \"s\": {\n",
1197
+ " \"description\": \"The term or phrase to translate into a sticker.\",\n",
1198
+ " \"type\": \"str\",\n",
1199
+ " \"default\": \"hungry\"\n",
1200
+ " },\n",
1201
+ " \"limit\": {\n",
1202
+ " \"description\": \"The number of results to return, with a maximum of 100. Defaults to 25.\",\n",
1203
+ " \"type\": \"str, optional\",\n",
1204
+ " \"default\": \"\"\n",
1205
+ " },\n",
1206
+ " \"offset\": {\n",
1207
+ " \"description\": \"The results offset, defaults to 0.\",\n",
1208
+ " \"type\": \"str, optional\",\n",
1209
+ " \"default\": \"\"\n",
1210
+ " },\n",
1211
+ " \"fmt\": {\n",
1212
+ " \"description\": \"The format in which to return results, either 'html' or 'json'.\",\n",
1213
+ " \"type\": \"str, optional\",\n",
1214
+ " \"default\": \"\"\n",
1215
+ " },\n",
1216
+ " \"rating\": {\n",
1217
+ " \"description\": \"The content rating to limit results to, one of 'y', 'g', 'pg', 'pg-13', or 'r'.\",\n",
1218
+ " \"type\": \"str, optional\",\n",
1219
+ " \"default\": \"\"\n",
1220
+ " }\n",
1221
+ " }\n",
1222
+ " },\n",
1223
+ " {\n",
1224
+ " \"name\": \"reels_downloader\",\n",
1225
+ " \"description\": \"Downloads Instagram reels or posts using a given link and RapidAPI key.\",\n",
1226
+ " \"parameters\": {\n",
1227
+ " \"link\": {\n",
1228
+ " \"description\": \"The URL of the Instagram media (reel or post) to be downloaded.\",\n",
1229
+ " \"type\": \"str\",\n",
1230
+ " \"default\": \"https://www.instagram.com/reels/CsinDvAgoYA/\"\n",
1231
+ " }\n",
1232
+ " }\n",
1233
+ " }\n",
1234
+ "]\n",
1235
+ "verify_tokenizer(messages_5, model_list, tools_5, BASE_XLAM_DIR, fc_modes = [True], file_suffix = \"example_5\")"
1236
+ ]
1237
+ },
1238
+ {
1239
+ "cell_type": "markdown",
1240
+ "metadata": {},
1241
+ "source": [
1242
+ "### Example 5 (General Chat with a System Message at the Beginning)"
1243
+ ]
1244
+ },
1245
+ {
1246
+ "cell_type": "code",
1247
+ "execution_count": 22,
1248
+ "metadata": {},
1249
+ "outputs": [
1250
+ {
1251
+ "name": "stdout",
1252
+ "output_type": "stream",
1253
+ "text": [
1254
+ "****************************************************************************************************\n",
1255
+ "Checkpoint: /export/agentstudio-family/checkpoints/xlam_v1/xlam_8x22b_r\n",
1256
+ "----------------------------------------------------------------------------------------------------\n",
1257
+ "FC Mode: True\n",
1258
+ "----------------------------------------------------------------------------------------------------\n",
1259
+ "<s>[INST]\n",
1260
+ "[BEGIN OF TASK INSTRUCTION]\n",
1261
+ "You are a help AI assistant developed by the xLAM team in Salesforce AI Research.\n",
1262
+ "[END OF TASK INSTRUCTION]\n",
1263
+ "\n",
1264
+ "[BEGIN OF AVAILABLE_TOOLS]\n",
1265
+ "[{'type': 'function', 'function': {'name': 'get_current_weather', 'description': 'Get the current weather', 'parameters': {'type': 'object', 'properties': {'location': {'type': 'string', 'description': 'The city and state, e.g. San Francisco, CA'}, 'format': {'type': 'string', 'enum': ['celsius', 'fahrenheit'], 'description': 'The temperature unit to use. Infer this from the users location.'}, 'date': {'type': 'integer', 'description': 'a specific date to get the weather for'}}, 'required': ['location', 'format', 'date']}}}, {'type': 'function', 'function': {'name': 'get_current_temperature', 'description': 'Get the current temperature at a location.', 'parameters': {'type': 'object', 'properties': {'location': {'type': 'string', 'description': 'The location to get the temperature for, in the format \"City, Country\"'}, 'unit': {'type': 'string', 'enum': ['celsius', 'fahrenheit'], 'description': 'The unit to return the temperature in.'}, 'longitude': {'type': 'number', 'description': 'the longitude of the location'}, 'latitude': {'type': 'number', 'description': 'the latitude of the location'}}, 'required': ['location', 'unit', 'longitude', 'latitude']}, 'return': {'type': 'number', 'description': 'The current temperature at the specified location in the specified units, as a float.'}}}, {'type': 'function', 'function': {'name': 'get_current_wind_speed', 'description': 'Get the current wind speed in km/h at a given location.', 'parameters': {'type': 'object', 'properties': {'location': {'type': 'string', 'description': 'The location to get the temperature for, in the format \"City, Country\"'}}, 'required': ['location']}, 'return': {'type': 'number', 'description': 'The current wind speed at the given location in km/h, as a float.'}}}]\n",
1266
+ "[END OF AVAILABLE_TOOLS]\n",
1267
+ "\n",
1268
+ "[BEGIN OF FORMAT INSTRUCTION]\n",
1269
+ "Your output should be in the JSON format, which specifies a list of function calls. The example format is as follows. Please make sure the parameter type is correct. If no function call is needed, please make tool_calls an empty list '[]'.\n",
1270
+ "```{\"thought\": \"the thought process, or an empty string\", \"tool_calls\": [{\"name\": \"api_name1\", \"arguments\": {\"argument1\": \"value1\", \"argument2\": \"value2\"}}]}```\n",
1271
+ "[END OF FORMAT INSTRUCTION]\n",
1272
+ "\n",
1273
+ "[BEGIN OF QUERY]\n",
1274
+ "My girlfriend Mary and I want to go to Disney in LA. Can you help us plan the trip?\n",
1275
+ "[END OF QUERY]\n",
1276
+ "\n",
1277
+ "[BEGIN OF HISTORY STEPS]\n",
1278
+ "[{'thought':\"Sure! I can help with booking flights, finding weather information, and checking Disney details. First, let's choose a good date. Do you want to check the weather to find a sunny and warm day?\", 'tool_calls':[], 'step_id':1, 'next_observation':'', 'user_input':\"Yes, we'd love that. We prefer sunny days with warm temperatures.\"}, {'thought':\"Got it. Let me check the weather forecast for Los Angeles to help you find the best date.\", 'tool_calls':[], 'step_id':2, 'next_observation':'', 'user_input':\"Sounds great! Thanks for your help.\"} ]\n",
1279
+ "[END OF HISTORY STEPS]\n",
1280
+ "[/INST]\n",
1281
+ "****************************************************************************************************\n",
1282
+ "Checkpoint: /export/agentstudio-family/checkpoints/xlam_v1/xlam_8x22b_r\n",
1283
+ "----------------------------------------------------------------------------------------------------\n",
1284
+ "FC Mode: False\n",
1285
+ "----------------------------------------------------------------------------------------------------\n",
1286
+ "<s>[INST] You are a help AI assistant developed by the xLAM team in Salesforce AI Research.\n",
1287
+ "\n",
1288
+ "My girlfriend Mary and I want to go to Disney in LA. Can you help us plan the trip?[/INST] Sure! I can help with booking flights, finding weather information, and checking Disney details. First, let's choose a good date. Do you want to check the weather to find a sunny and warm day?</s>[INST] Yes, we'd love that. We prefer sunny days with warm temperatures.[/INST] Got it. Let me check the weather forecast for Los Angeles to help you find the best date.</s>[INST] Sounds great! Thanks for your help.[/INST]\n"
1289
+ ]
1290
+ }
1291
+ ],
1292
+ "source": [
1293
+ "messages_6 = [\n",
1294
+ " {\"role\": \"system\", \"content\": \"You are a help AI assistant developed by the xLAM team in Salesforce AI Research.\"},\n",
1295
+ " \n",
1296
+ " {\"role\": \"user\", \"content\": \"My girlfriend Mary and I want to go to Disney in LA. Can you help us plan the trip?\"},\n",
1297
+ " \n",
1298
+ " {\"role\": \"assistant\", \"content\": \"Sure! I can help with booking flights, finding weather information, and checking Disney details. First, let's choose a good date. Do you want to check the weather to find a sunny and warm day?\"},\n",
1299
+ " \n",
1300
+ " {\"role\": \"user\", \"content\": \"Yes, we'd love that. We prefer sunny days with warm temperatures.\"},\n",
1301
+ " \n",
1302
+ " {\"role\": \"assistant\", \"content\": \"Got it. Let me check the weather forecast for Los Angeles to help you find the best date.\"},\n",
1303
+ " \n",
1304
+ " {\"role\": \"user\", \"content\": \"Sounds great! Thanks for your help.\"},\n",
1305
+ "]\n",
1306
+ "\n",
1307
+ "model_list_2 = [\n",
1308
+ " # \"xlam_7b_r\", \n",
1309
+ " \"xlam_8x7b_r\",\n",
1310
+ " \"xlam_8x22b_r\"\n",
1311
+ "]\n",
1312
+ "\"\"\"\n",
1313
+ "The mistral-v0.2 old tokenizer does not support system message. \n",
1314
+ "We need to update it to align with their latest changes. \n",
1315
+ "\"\"\"\n",
1316
+ "verify_tokenizer(messages_6, model_list_2, tools, BASE_XLAM_DIR, fc_modes = [True, False], file_suffix = \"example_6\")"
1317
+ ]
1318
+ }
1319
+ ],
1320
+ "metadata": {
1321
+ "kernelspec": {
1322
+ "display_name": "Python 3",
1323
+ "language": "python",
1324
+ "name": "python3"
1325
+ },
1326
+ "language_info": {
1327
+ "codemirror_mode": {
1328
+ "name": "ipython",
1329
+ "version": 3
1330
+ },
1331
+ "file_extension": ".py",
1332
+ "mimetype": "text/x-python",
1333
+ "name": "python",
1334
+ "nbconvert_exporter": "python",
1335
+ "pygments_lexer": "ipython3",
1336
+ "version": "3.10.14"
1337
+ }
1338
+ },
1339
+ "nbformat": 4,
1340
+ "nbformat_minor": 2
1341
+ }