使用 tools 参数
您正在为一家房产中介开发 AI 应用,被要求从房源信息中提取关键信息:房屋类型、位置、价格、卧室数量。请使用 Chat Completions 端点及函数调用来提取这些信息。
已预加载包含房源信息的 message_listing 消息,以及包含需作为工具传给模型的待调用函数的 function_definition。
本练习是课程的一部分
使用 OpenAI API 构建 AI 系统
练习说明
- 添加预加载的消息
message_listing。 - 添加函数定义
function_definition。 - 打印响应。
交互式实操练习
通过完成这段示例代码来试试这个练习。
client = OpenAI(api_key="")
response= client.chat.completions.create(
model="gpt-4o-mini",
# Add the message
____,
# Add your function definition
____
)
# Print the response
print(____)