对话能力
工具调用
用 tools 让模型调用你的函数,以及多轮执行的流程。
工具调用(Function Calling)让模型在需要时返回一个“调用某个函数”的请求,由你的程序执行后再把结果发回去。平台只转发,不会替你执行任何工具。
第一步:声明工具
import json
tools = [{
"type": "function",
"function": {
"name": "get_weather",
"description": "查询城市当前天气",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string", "description": "城市名,例如北京"}},
"required": ["city"],
},
},
}]
res = client.chat.completions.create(
model="qwen3.7-plus",
messages=[{"role": "user", "content": "北京现在天气怎么样?"}],
tools=tools,
)第二步:执行并回传结果
模型返回 finish_reason: "tool_calls" 时,读取 tool_calls,执行函数,再把结果以 role: "tool" 的消息发回:
call = res.choices[0].message.tool_calls[0]
result = get_weather(**json.loads(call.function.arguments))
followup = client.chat.completions.create(
model="qwen3.7-plus",
messages=[
{"role": "user", "content": "北京现在天气怎么样?"},
res.choices[0].message,
{"role": "tool", "tool_call_id": call.id, "content": json.dumps(result, ensure_ascii=False)},
],
tools=tools,
)每一轮都是一次独立的计费请求,回传的历史消息会计入下一轮的输入 tokens。
支持工具调用的模型
| 模型 ID | 类型 | 输入 / 1M | 输出 / 1M | 上下文 | 线路 |
|---|---|---|---|---|---|
| doubao-seed-2.1-pro | 多模态 | ¥6.00 | ¥30.00 | 1M | 火山方舟 |
| doubao-seed-2.1-lite | 全模态 | ¥0.80 | ¥2.70 | 1M | 火山方舟 |
| doubao-seed-2.1-turbo | 多模态 | ¥3.00 | ¥15.00 | 256K | 火山方舟 |
| doubao-seed-evolving | 多模态 | ¥6.00 | ¥30.00 | 1M | 火山方舟 |
| doubao-seed-2.0-lite | 全模态 | ¥0.60 起 | ¥3.60 起 | 256K | 火山方舟 |
| doubao-seed-2.0-mini | 全模态 | ¥0.20 起 | ¥2.00 起 | 256K | 火山方舟 |
| doubao-seed-character | 多模态 | ¥0.80 起 | ¥2.00 起 | 128K | 火山方舟 |
| qwen3.8-max | 多模态 | ¥12.00 | ¥36.00 | 1M | 阿里云百炼 |
| qwen3.7-plus | 多模态 | ¥2.00 起 | ¥8.00 起 | 1M | 阿里云百炼 |
| qwen3.8-flash | 多模态 | ¥0.80 | ¥2.70 | 1M | 阿里云百炼 |
| qwen3.7-flash | 多模态 | ¥0.20 起 | ¥0.80 起 | 1M | 阿里云百炼 |
| qwen3.8-omni-flash | 全模态 | ¥0.80 | ¥2.70 | 1M | 阿里云百炼 |
| qwen3.5-omni-plus | 全模态 | ¥7.00 | ¥40.00 | 256K | 阿里云百炼 |
| qwen3.5-omni-flash | 全模态 | ¥2.20 | ¥13.30 | — | 阿里云百炼 |
| qwen3-vl-plus | 多模态 | ¥1.00 起 | ¥10.00 起 | — | 阿里云百炼 |
| qwen3-coder-flash | 文本对话 | ¥1.00 起 | ¥4.00 起 | 1M | 阿里云百炼 |
| deepseek-v4.1-flash | 多模态 | ¥1.00 起 | ¥4.00 起 | 1M | 火山方舟 · 阿里云百炼 |
| deepseek-v4-pro | 文本对话 | ¥4.50 起 | ¥13.50 起 | 1M | 火山方舟 · 阿里云百炼 |
| deepseek-v4-flash | 文本对话 | ¥1.50 起 | ¥4.50 起 | 1M | 火山方舟 · 阿里云百炼 |
| glm-5.2 | 文本对话 | ¥8.00 起 | ¥28.00 起 | 1M | 火山方舟 · 阿里云百炼 |
| glm-5.3-flash | 多模态 | ¥0.80 起 | ¥2.80 起 | 1M | 火山方舟 · 阿里云百炼 |
| kimi-k3 | 多模态 | ¥20.00 | ¥100.00 | — | 阿里云百炼 |
| minimax-m3 | 文本对话 | ¥4.20 | ¥16.80 | 192K | 阿里云百炼 |
| mimo-v2.5-pro | 文本对话 | ¥7.00 起 | ¥21.00 起 | 1M | 阿里云百炼 |