使用 tools 參數
你正在為一家房仲公司開發 AI 應用,需要從物件列表中擷取關鍵資料:屋型、地點、價格、臥室數量。請使用 Chat Completions 端點搭配 function calling 來擷取這些資訊。
已預先載入包含房地產物件內容的訊息 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(____)