工具呼叫
本頁彙整聊天、工具呼叫和用量統計中常見的物件。
工具定義
工具定義通常包含 type 和 function。函式物件包含 name、description 和 parameters。模型返回工具呼叫後,應用程式需要執行工具,並將結果作為 tool 訊息繼續傳送。
json
{
"type": "function",
"function": {
"name": "get_weather",
"description": "查詢城市天氣",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"]
}
}
}應用程式必須自行驗證模型返回的函式名稱和參數,不能直接執行未經驗證的參數。執行結果應帶上對應的 tool_call_id,再作為工具訊息傳送回模型。
