update functioncall

#16
docs/function_call_guide.md CHANGED
@@ -18,21 +18,19 @@ from transformers import AutoTokenizer
18
  def get_default_tools():
19
  return [
20
  {
21
- {
22
- "name": "get_current_weather",
23
- "description": "Get the latest weather for a location",
24
- "parameters": {
25
- "type": "object",
26
- "properties": {
27
- "location": {
28
- "type": "string",
29
- "description": "A certain city, such as Beijing, Shanghai"
30
- }
31
- },
32
- }
33
- "required": ["location"],
34
- "type": "object"
35
  }
 
 
36
  }
37
  ]
38
 
@@ -54,6 +52,22 @@ text = tokenizer.apply_chat_template(
54
  add_generation_prompt=True,
55
  tools=tools
56
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  ```
58
 
59
  ## 🛠️ Function Call Definition
@@ -102,9 +116,9 @@ Function calls need to be defined in the `tools` field of the request body. Each
102
  When processed internally by the model, function definitions are converted to a special format and concatenated to the input text:
103
 
104
  ```
105
- ]~!b[]~b]system ai_setting=MiniMax AI
106
- MiniMax AI is an AI assistant independently developed by MiniMax. [e~[
107
- ]~b]system tool_setting=tools
108
  You are provided with these tools:
109
  <tools>
110
  {"name": "search_web", "description": "Search function.", "parameters": {"properties": {"query_list": {"description": "Keywords for search, with list element count of 1.", "items": {"type": "string"}, "type": "array"}, "query_tag": {"description": "Classification of the query", "items": {"type": "string"}, "type": "array"}}, "required": ["query_list", "query_tag"], "type": "object"}}
@@ -114,10 +128,10 @@ If you need to call tools, please respond with <tool_calls></tool_calls> XML tag
114
  <tool_calls>
115
  {"name": <tool-name>, "arguments": <args-json-object>}
116
  ...
117
- </tool_calls>[e~[
118
- ]~b]user name=User
119
- When were the most recent launch events for OpenAI and Gemini?[e~[
120
- ]~b]ai name=MiniMax AI
121
  ```
122
 
123
  ### Model Output Format
@@ -193,23 +207,33 @@ def execute_function_call(function_name: str, arguments: dict):
193
  # Build function execution result
194
  return {
195
  "role": "tool",
196
- "name": function_name,
197
- "content": json.dumps({
198
- "location": location,
199
- "temperature": "25",
200
- "unit": "celsius",
201
- "weather": "Sunny"
202
- }, ensure_ascii=False)
203
- }
 
 
 
 
 
204
  elif function_name == "search_web":
205
  query_list = arguments.get("query_list", [])
206
  query_tag = arguments.get("query_tag", [])
207
  # Simulate search results
208
  return {
209
  "role": "tool",
210
- "name": function_name,
211
- "content": f"Search keywords: {query_list}, Categories: {query_tag}\nSearch results: Relevant information found"
212
- }
 
 
 
 
 
213
 
214
  return None
215
  ```
@@ -224,47 +248,56 @@ If the model decides to call `search_web`, we suggest you to return the function
224
 
225
  ```json
226
  {
227
- "data": [
228
- {
229
- "role": "tool",
230
- "name": "search_web",
231
- "content": "search_result"
232
- }
 
233
  ]
234
  }
235
  ```
236
 
237
  Corresponding model input format:
238
  ```
239
- ]~b]tool name=search_web
240
- search_result[e~[
 
 
241
  ```
242
 
243
 
244
  #### Multiple Result
245
- If the model decides to call `search_web` and `get_current_weather` at the same time, we suggest you to return the multiple function results in the following format, with the `name` field set to "tools", and use the `content` field to contain multiple results.
246
 
247
 
248
  ```json
249
  {
250
- "data": [
251
- {
252
- "role": "tool",
253
- "name": "tools",
254
- "content": "Tool name: search_web\nTool result: test_result1\n\nTool name: get_current_weather\nTool result: test_result2"
255
- }
 
 
 
 
 
 
256
  ]
257
  }
258
  ```
259
 
260
  Corresponding model input format:
261
  ```
262
- ]~b]tool name=tools
263
- Tool name: search_web
264
- Tool result: test_result1
265
 
266
- Tool name: get_current_weather
267
- Tool result: test_result2[e~[
268
  ```
269
 
270
- While we suggest following the above formats, as long as the model input is easy to understand, the specific values of `name` and `content` is entirely up to the caller.
 
18
  def get_default_tools():
19
  return [
20
  {
21
+ "name": "get_current_weather",
22
+ "description": "Get the latest weather for a location",
23
+ "parameters": {
24
+ "type": "object",
25
+ "properties": {
26
+ "location": {
27
+ "type": "string",
28
+ "description": "A certain city, such as Beijing, Shanghai"
29
+ }
30
+ },
 
 
 
 
31
  }
32
+ "required": ["location"],
33
+ "type": "object"
34
  }
35
  ]
36
 
 
52
  add_generation_prompt=True,
53
  tools=tools
54
  )
55
+
56
+ # Post request
57
+ import requests
58
+ payload = {
59
+ "model": "MiniMaxAI/MiniMax-M1-40k",
60
+ "prompt": text,
61
+ "max_tokens": 4000
62
+ }
63
+
64
+ response = requests.post(
65
+ "http://localhost:8000/v1/completions",
66
+ headers={"Content-Type": "application/json"},
67
+ json=payload,
68
+ stream=False,
69
+ )
70
+ print(response.json()["choices"][0]["text"])
71
  ```
72
 
73
  ## 🛠️ Function Call Definition
 
116
  When processed internally by the model, function definitions are converted to a special format and concatenated to the input text:
117
 
118
  ```
119
+ <begin_of_document><beginning_of_sentence>system ai_setting=MiniMax AI
120
+ MiniMax AI is an AI assistant independently developed by MiniMax. <end_of_sentence>
121
+ <beginning_of_sentence>system tool_setting=tools
122
  You are provided with these tools:
123
  <tools>
124
  {"name": "search_web", "description": "Search function.", "parameters": {"properties": {"query_list": {"description": "Keywords for search, with list element count of 1.", "items": {"type": "string"}, "type": "array"}, "query_tag": {"description": "Classification of the query", "items": {"type": "string"}, "type": "array"}}, "required": ["query_list", "query_tag"], "type": "object"}}
 
128
  <tool_calls>
129
  {"name": <tool-name>, "arguments": <args-json-object>}
130
  ...
131
+ </tool_calls><end_of_sentence>
132
+ <beginning_of_sentence>user name=User
133
+ When were the most recent launch events for OpenAI and Gemini?<end_of_sentence>
134
+ <beginning_of_sentence>ai name=MiniMax AI
135
  ```
136
 
137
  ### Model Output Format
 
207
  # Build function execution result
208
  return {
209
  "role": "tool",
210
+ "content": [
211
+ {
212
+ "name": function_name,
213
+ "type": "text",
214
+ "text": json.dumps({
215
+ "location": location,
216
+ "temperature": "25",
217
+ "unit": "celsius",
218
+ "weather": "Sunny"
219
+ }, ensure_ascii=False)
220
+ }
221
+ ]
222
+ }
223
  elif function_name == "search_web":
224
  query_list = arguments.get("query_list", [])
225
  query_tag = arguments.get("query_tag", [])
226
  # Simulate search results
227
  return {
228
  "role": "tool",
229
+ "content": [
230
+ {
231
+ "name": function_name,
232
+ "type": "text",
233
+ "text": f"Search keywords: {query_list}, Categories: {query_tag}\nSearch results: Relevant information found"
234
+ }
235
+ ]
236
+ }
237
 
238
  return None
239
  ```
 
248
 
249
  ```json
250
  {
251
+ "role": "tool",
252
+ "content": [
253
+ {
254
+ "name": "search_web",
255
+ "type": "text",
256
+ "text": "test_result"
257
+ }
258
  ]
259
  }
260
  ```
261
 
262
  Corresponding model input format:
263
  ```
264
+ <beginning_of_sentence>tool name=tools
265
+ tool name: search_web
266
+ tool result: test_result
267
+ <end_of_sentence>
268
  ```
269
 
270
 
271
  #### Multiple Result
272
+ If the model decides to call `search_web` and `get_current_weather` at the same time, we suggest you to return the multiple function results in the following format, use the `content` field to contain multiple results.
273
 
274
 
275
  ```json
276
  {
277
+ "role": "tool",
278
+ "content": [
279
+ {
280
+ "name": "search_web",
281
+ "type": "text",
282
+ "text": "test_result1"
283
+ },
284
+ {
285
+ "name": "get_current_weather",
286
+ "type": "text",
287
+ "text": "test_result2"
288
+ }
289
  ]
290
  }
291
  ```
292
 
293
  Corresponding model input format:
294
  ```
295
+ <beginning_of_sentence>tool name=tools
296
+ tool name: search_web
297
+ tool result: test_result1
298
 
299
+ tool name: get_current_weather
300
+ tool result: test_result2<end_of_sentence>
301
  ```
302
 
303
+ While we suggest following the above formats, as long as the model input is easy to understand, the specific values of `name` and `text` is entirely up to the caller.
docs/function_call_guide_cn.md CHANGED
@@ -16,21 +16,19 @@ from transformers import AutoTokenizer
16
  def get_default_tools():
17
  return [
18
  {
19
- {
20
- "name": "get_current_weather",
21
- "description": "Get the latest weather for a location",
22
- "parameters": {
23
- "type": "object",
24
- "properties": {
25
- "location": {
26
- "type": "string",
27
- "description": "A certain city, such as Beijing, Shanghai"
28
- }
29
- },
30
- }
31
- "required": ["location"],
32
- "type": "object"
33
  }
 
 
34
  }
35
  ]
36
 
@@ -52,6 +50,22 @@ text = tokenizer.apply_chat_template(
52
  add_generation_prompt=True,
53
  tools=tools
54
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  ```
56
 
57
  ## 🛠️ 函数调用的定义
@@ -100,9 +114,9 @@ text = tokenizer.apply_chat_template(
100
  在模型内部处理时,函数定义会被转换为特殊格式并拼接到输入文本中:
101
 
102
  ```
103
- ]~!b[]~b]system ai_setting=MiniMax AI
104
- MiniMax AI是由上海稀宇科技有限公司(MiniMax)自主研发的AI助理。[e~[
105
- ]~b]system tool_setting=tools
106
  You are provided with these tools:
107
  <tools>
108
  {"name": "search_web", "description": "搜索函数。", "parameters": {"properties": {"query_list": {"description": "进行搜索的关键词,列表元素个数为1。", "items": {"type": "string"}, "type": "array"}, "query_tag": {"description": "query的分类", "items": {"type": "string"}, "type": "array"}}, "required": ["query_list", "query_tag"], "type": "object"}}
@@ -112,10 +126,10 @@ If you need to call tools, please respond with <tool_calls></tool_calls> XML tag
112
  <tool_calls>
113
  {"name": <tool-name>, "arguments": <args-json-object>}
114
  ...
115
- </tool_calls>[e~[
116
- ]~b]user name=用户
117
- OpenAI 和 Gemini 的最近一次发布会都是什么时候?[e~[
118
- ]~b]ai name=MiniMax AI
119
  ```
120
 
121
  ### 模型输出格式
@@ -191,23 +205,33 @@ def execute_function_call(function_name: str, arguments: dict):
191
  # 构建函数执行结果
192
  return {
193
  "role": "tool",
194
- "name": function_name,
195
- "content": json.dumps({
196
- "location": location,
197
- "temperature": "25",
198
- "unit": "celsius",
199
- "weather": "晴朗"
200
- }, ensure_ascii=False)
201
- }
 
 
 
 
 
202
  elif function_name == "search_web":
203
  query_list = arguments.get("query_list", [])
204
  query_tag = arguments.get("query_tag", [])
205
  # 模拟搜索结果
206
  return {
207
  "role": "tool",
208
- "name": function_name,
209
- "content": f"搜索关键词: {query_list}, 分类: {query_tag}\n搜索结果: 相关信息已找到"
210
- }
 
 
 
 
 
211
 
212
  return None
213
  ```
@@ -222,46 +246,55 @@ def execute_function_call(function_name: str, arguments: dict):
222
 
223
  ```json
224
  {
225
- "data": [
226
- {
227
- "role": "tool",
228
- "name": "search_web",
229
- "content": "search_result"
230
- }
 
231
  ]
232
  }
233
  ```
234
 
235
  对应如下的模型输入格式:
236
  ```
237
- ]~b]tool name=search_web
238
- search_result[e~[
 
 
239
  ```
240
 
241
 
242
  #### 多个结果
243
- 假如模型同时调用了 `search_web` 和 `get_current_weather` 函数,您可以参考如下格式添加执行结果,`name` 字段为"tools",`content`包含多个结果。
244
 
245
  ```json
246
  {
247
- "data": [
248
- {
249
- "role": "tool",
250
- "name": "tools",
251
- "content": "Tool name: search_web\nTool result: test_result1\n\nTool name: get_current_weather\nTool result: test_result2"
252
- }
 
 
 
 
 
 
253
  ]
254
  }
255
  ```
256
 
257
  对应如下的模型输入格式:
258
  ```
259
- ]~b]tool name=tools
260
- Tool name: search_web
261
- Tool result: test_result1
262
 
263
- Tool name: get_current_weather
264
- Tool result: test_result2[e~[
265
  ```
266
 
267
- 虽然我们建议您参考以上格式,但只要返回给模型的输入易于理解,`name` 和 `content` 的具体内容完全由您自主决定。
 
16
  def get_default_tools():
17
  return [
18
  {
19
+ "name": "get_current_weather",
20
+ "description": "Get the latest weather for a location",
21
+ "parameters": {
22
+ "type": "object",
23
+ "properties": {
24
+ "location": {
25
+ "type": "string",
26
+ "description": "A certain city, such as Beijing, Shanghai"
27
+ }
28
+ },
 
 
 
 
29
  }
30
+ "required": ["location"],
31
+ "type": "object"
32
  }
33
  ]
34
 
 
50
  add_generation_prompt=True,
51
  tools=tools
52
  )
53
+
54
+ # 发送请求
55
+ import requests
56
+ payload = {
57
+ "model": "MiniMaxAI/MiniMax-M1-40k",
58
+ "prompt": text,
59
+ "max_tokens": 4000
60
+ }
61
+
62
+ response = requests.post(
63
+ "http://localhost:8000/v1/completions",
64
+ headers={"Content-Type": "application/json"},
65
+ json=payload,
66
+ stream=False,
67
+ )
68
+ print(response.json()["choices"][0]["text"])
69
  ```
70
 
71
  ## 🛠️ 函数调用的定义
 
114
  在模型内部处理时,函数定义会被转换为特殊格式并拼接到输入文本中:
115
 
116
  ```
117
+ <begin_of_document><beginning_of_sentence>system ai_setting=MiniMax AI
118
+ MiniMax AI是由上海稀宇科技有限公司(MiniMax)自主研发的AI助理。<end_of_sentence>
119
+ <beginning_of_sentence>system tool_setting=tools
120
  You are provided with these tools:
121
  <tools>
122
  {"name": "search_web", "description": "搜索函数。", "parameters": {"properties": {"query_list": {"description": "进行搜索的关键词,列表元素个数为1。", "items": {"type": "string"}, "type": "array"}, "query_tag": {"description": "query的分类", "items": {"type": "string"}, "type": "array"}}, "required": ["query_list", "query_tag"], "type": "object"}}
 
126
  <tool_calls>
127
  {"name": <tool-name>, "arguments": <args-json-object>}
128
  ...
129
+ </tool_calls><end_of_sentence>
130
+ <beginning_of_sentence>user name=用户
131
+ OpenAI 和 Gemini 的最近一次发布会都是什么时候?<end_of_sentence>
132
+ <beginning_of_sentence>ai name=MiniMax AI
133
  ```
134
 
135
  ### 模型输出格式
 
205
  # 构建函数执行结果
206
  return {
207
  "role": "tool",
208
+ "content": [
209
+ {
210
+ "name": function_name,
211
+ "type": "text",
212
+ "text": json.dumps({
213
+ "location": location,
214
+ "temperature": "25",
215
+ "unit": "celsius",
216
+ "weather": "晴朗"
217
+ }, ensure_ascii=False)
218
+ }
219
+ ]
220
+ }
221
  elif function_name == "search_web":
222
  query_list = arguments.get("query_list", [])
223
  query_tag = arguments.get("query_tag", [])
224
  # 模拟搜索结果
225
  return {
226
  "role": "tool",
227
+ "content": [
228
+ {
229
+ "name": function_name,
230
+ "type": "text",
231
+ "text": f"搜索关键词: {query_list}, 分类: {query_tag}\n搜索结果: 相关信息已找到"
232
+ }
233
+ ]
234
+ }
235
 
236
  return None
237
  ```
 
246
 
247
  ```json
248
  {
249
+ "role": "tool",
250
+ "content": [
251
+ {
252
+ "name": "search_web",
253
+ "type": "text",
254
+ "text": "test_result"
255
+ }
256
  ]
257
  }
258
  ```
259
 
260
  对应如下的模型输入格式:
261
  ```
262
+ <beginning_of_sentence>tool name=tools
263
+ tool name: search_web
264
+ tool result: test_result
265
+ <end_of_sentence>
266
  ```
267
 
268
 
269
  #### 多个结果
270
+ 假如模型同时调用了 `search_web` 和 `get_current_weather` 函数,您可以参考如下格式添加执行结果,`content`包含多个结果。
271
 
272
  ```json
273
  {
274
+ "role": "tool",
275
+ "content": [
276
+ {
277
+ "name": "search_web",
278
+ "type": "text",
279
+ "text": "test_result1"
280
+ },
281
+ {
282
+ "name": "get_current_weather",
283
+ "type": "text",
284
+ "text": "test_result2"
285
+ }
286
  ]
287
  }
288
  ```
289
 
290
  对应如下的模型输入格式:
291
  ```
292
+ <beginning_of_sentence>tool name=tools
293
+ tool name: search_web
294
+ tool result: test_result1
295
 
296
+ tool name: get_current_weather
297
+ tool result: test_result2<end_of_sentence>
298
  ```
299
 
300
+ 虽然我们建议您参考以上格式,但只要返回给模型的输入易于理解,`name` 和 `text` 的具体内容完全由您自主决定。
tokenizer_config.json CHANGED
@@ -6,5 +6,5 @@
6
  "model_max_length": 40960000,
7
  "tokenizer_class": "GPT2Tokenizer",
8
  "unk_token": "<end_of_document>",
9
- "chat_template": "{{ '<begin_of_document>' -}}{% set ns = namespace(system_prompt='') -%}{% for message in messages -%}{% if message['role'] == 'system' -%}{% set ns.system_prompt = ns.system_prompt + message['content'][0]['text'] -%}{% endif -%}{%- endfor -%}{% if ns.system_prompt != '' -%}{{ '<beginning_of_sentence>system ai_setting=assistant\n' + ns.system_prompt + '<end_of_sentence>\n' -}}{%- endif -%}{% if tools -%}{{ '<beginning_of_sentence>system tool_setting=tools\nYou are provided with these tools:\n<tools>\n' -}}{% for tool in tools -%}{{ tool | tojson ~ '\n' -}}{%- endfor -%}{{ '</tools>\n\nIf you need to call tools, please respond with <tool_calls></tool_calls> XML tags, and provide tool-name and json-object of arguments, following the format below:\n<tool_calls>\n{''name'': <tool-name-1>, ''arguments'': <args-json-object-1>}\n...\n</tool_calls><end_of_sentence>\n' -}}{%- endif -%}{% for message in messages -%}{% if message['role'] == 'user' -%}{{ '<beginning_of_sentence>user name=user\n' + message['content'][0]['text'] + '<end_of_sentence>\n' -}}{% elif message['role'] == 'assistant' -%}{{ '<beginning_of_sentence>ai name=assistant\n' -}}{% for content in message['content'] | selectattr('type', 'equalto', 'text') -%}{{ content['text'] -}}{%- endfor -%}{{ '<end_of_sentence>\n' -}}{% elif message['role'] == 'tool' -%}{{ '<beginning_of_sentence>tool name=tools\n' }} {%- for content in message['content'] -%}{{- 'tool name: ' + content['name'] + '\n' + 'tool result: ' + content['text'] + '\n\n' -}} {%- endfor -%}{{- '<end_of_sentence>\n' -}}{% endif -%}{%- endfor -%}{% if add_generation_prompt -%}{{ '<beginning_of_sentence>ai name=assistant\n' -}}{%- endif -%}"
10
  }
 
6
  "model_max_length": 40960000,
7
  "tokenizer_class": "GPT2Tokenizer",
8
  "unk_token": "<end_of_document>",
9
+ "chat_template": "{{ '<begin_of_document>' -}}{% set ns = namespace(system_prompt='') -%}{% for message in messages -%}{% if message['role'] == 'system' -%}{% set ns.system_prompt = ns.system_prompt + message['content'][0]['text'] -%}{% endif -%}{%- endfor -%}{% if ns.system_prompt != '' -%}{{ '<beginning_of_sentence>system ai_setting=assistant\n' + ns.system_prompt + '<end_of_sentence>\n' -}}{%- endif -%}{% if tools -%}{{ '<beginning_of_sentence>system tool_setting=tools\nYou are provided with these tools:\n<tools>\n' -}}{% for tool in tools -%}{{ tool | tojson ~ '\n' -}}{%- endfor -%}{{ '</tools>\n\nIf you need to call tools, please respond with <tool_calls></tool_calls> XML tags, and provide tool-name and json-object of arguments, following the format below:\n<tool_calls>\n{''\"name\"'': <tool-name-1>, ''\"arguments\"'': <args-json-object-1>}\n...\n</tool_calls><end_of_sentence>\n' -}}{%- endif -%}{% for message in messages -%}{% if message['role'] == 'user' -%}{{ '<beginning_of_sentence>user name=user\n' + message['content'][0]['text'] + '<end_of_sentence>\n' -}}{% elif message['role'] == 'assistant' -%}{{ '<beginning_of_sentence>ai name=assistant\n' -}}{% for content in message['content'] | selectattr('type', 'equalto', 'text') -%}{{ content['text'] -}}{%- endfor -%}{{ '<end_of_sentence>\n' -}}{% elif message['role'] == 'tool' -%}{{ '<beginning_of_sentence>tool name=tools\n' }} {%- for content in message['content'] -%}{{- 'tool name: ' + content['name'] + '\n' + 'tool result: ' + content['text'] + '\n\n' -}} {%- endfor -%}{{- '<end_of_sentence>\n' -}}{% endif -%}{%- endfor -%}{% if add_generation_prompt -%}{{ '<beginning_of_sentence>ai name=assistant\n' -}}{%- endif -%}"
10
  }