工具调用
格式
与 OpenAI function calling 完全一致。
请求
{
"model": "glm-5.3",
"messages": [{"role":"user","content":"北京天气怎么样"}],
"tools": [{
"type": "function",
"function": {
"name": "get_weather",
"description": "查询城市天气",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"]
}
}
}]
}流程
- 带 tools 发请求,模型返回
tool_calls - 你执行本地函数,把结果作为
role: tool的消息发回去 - 模型基于结果生成最终回答
哪些模型支持
模型广场里带「工具」标签的才支持。不支持的就用提示词约束输出 JSON。