将 LLM 与网页搜索结合
您正在构建一个旅行助理聊天机器人,需要为计划行程的用户提供当前天气信息。您使用的 LLM 的知识截止于几个月前,如果不借助其他工具,就无法获取实时天气数据。
本练习是课程的一部分
使用 OpenAI Responses API
练习说明
- 向
'gpt-5.4-mini'模型发起请求,询问德国柏林当前气温,并启用'web_search'工具。 - 打印响应中的文本输出。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Create a response with web search enabled
response = client.responses.create(
model="____",
tools=____,
input="What is the current temperature in Berlin, Germany?"
)
# Print the output text
print(____)