微信扫码
添加专属顾问
我要投稿
昨天OpenAI发布了全新的Function Calling指南,这次更新不仅让文档缩短了50%,还带来了一些重要的最佳实践。作为Agent的核心能力之一,Function Calling的正确使用对于构建强大的AI Agents应用至关重要。所以今天给家人们分享一下这次更新的重点内容!
文中明确指出,Function Calling主要有两个核心应用场景:
获取数据(Fetching Data)
执行动作(Taking Action)
这次更新最重要的是提供了一系列实用的最佳实践,让我们重点来看几个:
# 好的示例
def get_weather(location: str):
"""获取指定位置的当前温度
Args:
location: 城市和国家,例如:'北京, 中国'
"""
pass
# 糟糕的示例
def toggle_light_switch(on: bool, off: bool):
"""这个设计允许无效状态的存在"""
pass
# 不推荐
def get_orders(user_id: str):
pass
# 推荐
def get_orders():
# 在代码中传递user_id
pass
# 自动模式(默认)
tool_choice="auto" # 可以调用零个、一个或多个函数
# 强制模式
tool_choice="required" # 必须调用至少一个函数
# 指定函数
tool_choice={
"type": "function",
"function": {"name": "get_weather"}
} # 强制调用特定函数
{
"type": "function",
"function": {
"name": "get_weather",
"strict": True, # 启用严格模式
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string"
},
"units": {
"type": ["string", "null"], # 可选参数
"enum": ["celsius", "fahrenheit"]
}
},
"required": ["location", "units"],
"additionalProperties": false
}
}
}
OpenAI还优化了流式处理的支持,让你能实时展示函数调用的过程:
stream = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "北京今天天气如何?"}],
tools=tools,
stream=True
)
for chunk in stream:
delta = chunk.choices[0].delta
print(delta.tool_calls) # 实时显示函数调用进度
这次的更新,主要是提供了一些的最佳实践。随着o1-mini即将支持Function Calling(官方确认),昨天还开始发布了tasks的功能,可以期待在2025年看到真正的Agents
53AI,企业落地大模型首选服务商
产品:场景落地咨询+大模型应用平台+行业解决方案
承诺:免费场景POC验证,效果验证后签署服务协议。零风险落地应用大模型,已交付160+中大型企业
2025-02-15
单卡复现 DeepSeek R1 Zero教程来了!
2025-02-15
申请API-KEY,通过接口使用DeepSeek服务
2025-02-15
DeepSeek零门槛三步极速部署指南,注册秒过,对话零延迟!
2025-02-15
大模型应用部署过程中流量管控的常见需求和应对方案
2025-02-15
AI应用开发先了解这些概念:智能体、LLM、RAG、提示词工程
2025-02-15
腾讯云TI平台和HAI部署DeepSeek的步骤及其区别
2025-02-15
Chain-of-Action (行动链):从Agent工作流到Agent模型
2025-02-14
使用 Apache Dubbo 释放 DeepSeek R1 的全部潜力
2025-02-04
2025-02-04
2024-09-18
2024-07-11
2024-07-11
2024-07-26
2024-07-09
2025-01-27
2024-12-29
2025-02-01
2025-02-10
2025-02-10
2025-02-09
2025-02-05
2025-01-24
2025-01-22
2025-01-14
2025-01-12