File size: 12,204 Bytes
5e72b35
 
 
89acc5c
 
ed8b0c6
 
5e72b35
 
 
 
 
 
 
 
ed8b0c6
 
 
 
89acc5c
ed8b0c6
89acc5c
5e72b35
ed8b0c6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5e72b35
 
 
 
 
 
 
 
89acc5c
 
 
 
 
 
 
 
 
5e72b35
89acc5c
 
 
 
 
 
 
5e72b35
89acc5c
d3ba21b
 
89acc5c
 
 
 
 
 
 
 
 
d3ba21b
89acc5c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5e72b35
 
89acc5c
5e72b35
89acc5c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d3ba21b
 
 
 
 
 
5e72b35
 
 
 
 
 
89acc5c
 
 
5e72b35
89acc5c
 
 
 
982d6e8
 
 
 
 
 
89acc5c
 
 
 
 
 
 
 
 
 
 
5e72b35
 
89acc5c
d3ba21b
5e72b35
a21f3cd
89acc5c
2d7d5b2
5e72b35
 
 
89acc5c
5e72b35
d3ba21b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ed8b0c6
5e72b35
 
89acc5c
5e72b35
89acc5c
 
 
 
 
 
 
2d7d5b2
 
 
89acc5c
 
5e72b35
d3ba21b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a21f3cd
d3ba21b
 
5e72b35
 
 
ed8b0c6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e584a13
ed8b0c6
e584a13
ed8b0c6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
---
title: 支持的工具列表 & llm返回的工具调用
---


- [tools调用](#tools调用)
- [LLM入参 = messages + tools](#llm入参--messages--tools)
- [LLM出参 = 工具名 + 参数](#llm出参--工具名--参数)
- [LLM入参示例:messages and tools](#llm入参示例messages-and-tools)
- [LLM入参示例:转化为 prompt 字符串](#llm入参示例转化为-prompt-字符串)
  - [llama3.1-405b ⭐️⭐️](#llama31-405b-️️)
  - [Hermes-3-Llama-3.1-405B ⭐️⭐️⭐️](#hermes-3-llama-31-405b-️️️)
  - [llama4 ⭐️⭐️⭐️](#llama4-️️️)
  - [mistralai/Ministral-8B-Instruct-2410](#mistralaiministral-8b-instruct-2410)
  - [qwen3 ⭐️⭐️⭐️⭐️⭐️](#qwen3-️️️️️)
  - [deepseek-r1 ⭐️⭐️](#deepseek-r1-️️)
  - [deepseek-v3.1 ⭐️⭐️](#deepseek-v31-️️)
  - [gemma-3-27b-it ⭐️](#gemma-3-27b-it-️)
  - [grok-2 ⭐️](#grok-2-️)

## tools调用


```py
# openai chat api
    completion = client.chat.completions.create(
        model=model_name,
        messages=messages,
        tools=tools,          # tool list defined above
        tool_choice="auto"
    )
# open response api

```


## LLM入参 = messages + tools

tools是支持的工具列表

一般都是json格式,也有非json格式

- json格式: s
- 非json格式: s

## LLM出参 = 工具名 + 参数

llm返回格式通常有两种,`pythonic``json` 格式


json response 示例 [llama3.2_json](https://github.com/vllm-project/vllm/blob/v0.10.1/examples/tool_chat_template_llama3.2_json.jinja)
```sh
please respond with JSON for a function call.
Respond in the format {"name": function name, "parameters": dictionary of argument name and its value}.
```

pythonic response 示例 [llama3.2_pythonic 非官方](https://github.com/vllm-project/vllm/blob/v0.10.1/examples/tool_chat_template_llama3.2_pythonic.jinja)
```sh
Please respond with a python list of the calls. 
Respond in the format [func_name1(params_name1=params_value1, params_name2=params_value2...), func_name2(params)]
```

多数都采用的json返回格式。

## LLM入参示例:messages and tools

```py
messages = [
  {
    "role": "system",
    "content": "You are a bot that responds to weather queries."
  },
  {
    "role": "user",
    "content": "Hey, what's the temperature in Paris right now?"
  }
]
# chat_completion = client.chat.completions.create(messages=messages, model=model, tools=tools)  # 可以这样调用 LLM
```

`json_schema` of tools

```json
{
  "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\""
        }
      },
      "required": [
        "location"
      ]
    },
    "return": {
      "type": "number",
      "description": "The current temperature at the specified location in the specified units, as a float."
    }
  }
}
```

## LLM入参示例:转化为 prompt 字符串


### llama3.1-405b ⭐️⭐️



```sh
<|begin_of_text|><|start_header_id|>system<|end_header_id|>

Environment: ipython
Cutting Knowledge Date: December 2023
Today Date: 26 Jul 2024

You are a bot that responds to weather queries.<|eot_id|><|start_header_id|>user<|end_header_id|>

Given the following functions, please respond with a JSON for a function call with its proper arguments that best answers the given prompt.

Respond in the format {"name": function name, "parameters": dictionary of argument name and its value}.Do not use variables.

{
    "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\""
                }
            },
            "required": [
                "location"
            ]
        },
        "return": {
            "type": "number",
            "description": "The current temperature at the specified location in the specified units, as a float."
        }
    }
}

Hey, what's the temperature in Paris right now?<|eot_id|><|start_header_id|>assistant<|end_header_id|>
```

- **入参**: 
  - **tools格式**: 支持的工具列表(`tools`) 是基于 json-schema 的,因为chat_template中采用的是 [`tojson(indent=4)`](https://github.com/vllm-project/vllm/blob/v0.10.1/examples/tool_chat_template_llama3.1_json.jinja#L48)
  - **tools在prompt中的位置**: 拼在第一个user轮内容的前面。(system不变,其他轮message也不变)
- **出参**: 
  - **出参格式**: 返回的`respone` 要求是 json 格式,`respond with a JSON ... Respond in the format {"name": function name, "parameters": dictionary of argument name and its value}`
  - **出参的工具解析**: ?
- **评价**
  - 扣分项: 
    - 入参: `Environment: ipython`
    - 入参: `Today Date`
    - 出参格式: 返回内容没有 `<tool>` 包裹,不方便结果的解析。
- **推荐指数**: ⭐️⭐️



### Hermes-3-Llama-3.1-405B ⭐️⭐️⭐️


```sh
<|begin_of_text|><|im_start|>system
You are a function calling AI model. You are provided with function signatures within <tools></tools> XML tags. You may call one or more functions to assist with the user query. Don't make assumptions about what values to plug into functions. Here are the available tools: <tools> {"type": "function", "function": {"name": "get_current_temperature", "description": "get_current_temperature(location: str) -> float - Get the current temperature at a location.

    Args:
        location(str): The location to get the temperature for, in the format "City, Country"
    Returns:
        The current temperature at the specified location in the specified units, as a float.", "parameters": {"type": "object", "properties": {"location": {"type": "string", "description": "The location to get the temperature for, in the format \"City, Country\""}}, "required": ["location"]}} </tools>Use the following pydantic model json schema for each tool call you will make: {"properties": {"name": {"title": "Name", "type": "string"}, "arguments": {"title": "Arguments", "type": "object"}}, "required": ["name", "arguments"], "title": "FunctionCall", "type": "object"}}
For each function call return a json object with function name and arguments within <tool_call></tool_call> XML tags as follows:
<tool_call>
{"name": <function-name>, "arguments": <args-dict>}
</tool_call><|im_end|>
<|im_start|>system
You are a bot that responds to weather queries.<|im_end|>
<|im_start|>user
Hey, what's the temperature in Paris right now?<|im_end|>
<|im_start|>assistant
```

> 为方便查看,以上prompt手动变化了缩进。


- **入参**: 
  - **tools格式**: 支持的工具列表(`tools`) 是基于自定义格式的(类json-schema),详见 [chat_template](https://huggingface.co/spaces/xu-song/tokenizer-arena/blob/main/docs/chat-template/Hermes-3-Llama-3.1-405B/chat_template.tool_use.jinja#L42)
  - **tools在prompt中的位置**: 额外增加了一个`system`轮,放在最前面。(用户设置的`system`保持不变),这个额外的system轮告诉大模型可以使用tools中的工具,并且指定返回格式
- **出参**: 返回的`respone` 要求是 `<tool_call>` 包裹的json
`return a json object with function name and arguments within <tool_call></tool_call> XML tags as follows: <tool_call>{"name": <function-name>, "arguments": <args-dict>}</tool_call>`
- **评价**: 
  - 扣分项: 入参的`tools格式`与json-schema的字段虽然一样,也类似json,但不是严格的json格式,通用性差。
- **推荐指数**: ⭐️⭐️⭐️

### llama4 ⭐️⭐️⭐️

```sh
<|begin_of_text|><|header_start|>system<|header_end|>

Environment: ipython
You are a bot that responds to weather queries.<|eot|><|header_start|>user<|header_end|>

Given the following functions, please respond with a JSON for a function call with its proper arguments that best answers the given prompt.

Respond in the format {"name": function name, "parameters": dictionary of argument name and its value}.Do not use variables.

{
    "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\""
                }
            },
            "required": [
                "location"
            ]
        },
        "return": {
            "type": "number",
            "description": "The current temperature at the specified location in the specified units, as a float."
        }
    }
}

Hey, what's the temperature in Paris right now?<|eot|><|header_start|>assistant<|header_end|>
```

跟 llama3.1差不多,只是少了`date`,并且换了`special_token`。(同样拼在第一个user轮)

- **评价**: 同 llama3.1
- **推荐指数**: ⭐️⭐️⭐️


### mistralai/Ministral-8B-Instruct-2410

```sh
<s>[AVAILABLE_TOOLS][{"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\""}}, "required": ["location"]}}}][/AVAILABLE_TOOLS][INST]You are a bot that responds to weather queries.

Hey, what's the temperature in Paris right now?[/INST]
```

- **入参**: 支持的工具列表(`tools`) 是基于  的,
- **出参**: 返回的`respone` 要求是 



### qwen3 ⭐️⭐️⭐️⭐️⭐️

```sh
<|im_start|>system
You are a bot that responds to weather queries.

# Tools

You may call one or more functions to assist with the user query.

You are provided with function signatures within <tools></tools> XML tags:
<tools>
{"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\""}}, "required": ["location"]}, "return": {"type": "number", "description": "The current temperature at the specified location in the specified units, as a float."}}}
</tools>

For each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:
<tool_call>
{"name": <function-name>, "arguments": <args-json-object>}
</tool_call><|im_end|>
<|im_start|>user
Hey, what's the temperature in Paris right now?<|im_end|>
<|im_start|>assistant
```


- **入参**: 
  - **tools格式**: 支持的工具列表(`tools`) 是基于 json-schema 的.
  - **tools在prompt中的位置**: 拼接到原始`system`的结尾 + 额外的prompt (告诉大模型可以使用tools中的工具,并且指定返回格式)
- **出参**: 返回的`respone` 要求是 `<tool_call>` 包裹的json
`return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n{"name": <function-name>, "arguments": <args-json-object>}\n</tool_call>`
- **推荐指数**: ⭐️⭐️⭐️⭐️⭐️


### deepseek-r1 ⭐️⭐️


```sh
<|begin▁of▁sentence|>You are a bot that responds to weather queries.<|User|>Hey, what's the temperature in Paris right now?<|Assistant|><think>
```

- **评价**: 
  - 扣分项: 不支持tools,tool_calls也有问题
- **推荐指数**: ⭐️⭐️


### deepseek-v3.1 ⭐️⭐️

与 deepseek-r1 一样


### gemma-3-27b-it ⭐️

不支持任何tool

### grok-2 ⭐️

不支持任何tool