kamuy-shennai commited on
Commit
93b2da3
·
verified ·
1 Parent(s): 5ea45df

Update docs/function_call_guide_cn.md

Browse files
Files changed (1) hide show
  1. docs/function_call_guide_cn.md +39 -25
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
  ### 模型输出格式
@@ -234,8 +248,8 @@ def execute_function_call(function_name: str, arguments: dict):
234
 
235
  对应如下的模型输入格式:
236
  ```
237
- ]~b]tool name=search_web
238
- search_result[e~[
239
  ```
240
 
241
 
@@ -256,12 +270,12 @@ search_result[e~[
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
+ f"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
  ### 模型输出格式
 
248
 
249
  对应如下的模型输入格式:
250
  ```
251
+ <beginning_of_sentence>tool name=search_web
252
+ search_result<end_of_sentence>
253
  ```
254
 
255
 
 
270
 
271
  对应如下的模型输入格式:
272
  ```
273
+ <beginning_of_sentence>tool name=tools
274
  Tool name: search_web
275
  Tool result: test_result1
276
 
277
  Tool name: get_current_weather
278
+ Tool result: test_result2<end_of_sentence>
279
  ```
280
 
281
  虽然我们建议您参考以上格式,但只要返回给模型的输入易于理解,`name` 和 `content` 的具体内容完全由您自主决定。