函数调用 (Tool Use) 指南
函数调用让模型输出结构化的工具调用参数,而非自由文本。Starsg 上所有支持 Tool Use 的模型 (GPT、Claude、Qwen、Mistral) 均使用 OpenAI 标准格式。
tools = [{
"type": "function",
"function": {
"name": "create_order",
"description": "Create an order",
"parameters": {
"type": "object",
"properties": {
"sku": {"type": "string"},
"qty": {"type": "integer"}
},
"required": ["sku", "qty"]
}
}
}]
resp = client.chat.completions.create(
model="qwen/qwen3-72b",
messages=[...],
tools=tools,
)扩展阅读:API 文档 › 函数调用