资讯动态

Agent如何进行动态API调用?Function Calling?插件?

发布时间:2026/10/8 12:57:20 来源:尧图企业网站定制
1.基本思路以OpenAI的Function Calling为例调用流程如下import openai # 1. 定义可用的工具 tools [{ type: function, function: { name: get_weather, description: 获取指定城市的天气信息, parameters: { type: object, properties: { city: {type: string, description: 城市名称} }, required: [city] } } }] # 2. 发送请求模型判断是否需要调用工具 response openai.chat.completions.create( modelgpt-4-turbo, messages[{role: user, content: 北京今天天气怎么样}], toolstools ) # 3. 如果模型返回 tool_calls解析并执行真实 API if response.choices[0].message.tool_calls: tool_call response.choices[0].message.tool_calls[0] # 解析参数调用真实的天气 API拿到结果后继续对话2.Function Calling的工作原理3.插件与Function Calling4.进阶方案5.追问

读完文章,也想定制专属网站?

尧图设计师 24 小时内与您沟通定制方案

免费获取报价 →
↑