結合 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(____)