工具调用
本页汇总聊天、工具调用和用量统计中常见对象。
工具定义
工具定义通常包含 type 和 function。函数对象包含 name、description 和 parameters。模型返回工具调用后,应用需要执行工具并把结果作为 tool 消息继续发送。
json
{
"type": "function",
"function": {
"name": "get_weather",
"description": "查询城市天气",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"]
}
}
}应用必须自行校验模型返回的函数名和参数,不能直接执行未经验证的参数。执行结果应带上对应的 tool_call_id,再作为工具消息发送回模型。
