開始使用免費開始

建立函式字典

你正在進行一個研究專案,需要從一系列科學研究論文中擷取關鍵資訊。目標是為給定的論文建立一份重點摘要,內容包含論文標題與發表年份。為了彙整這些資訊,你決定使用 OpenAI API 的函式呼叫(function calling)來擷取關鍵資訊。

get_response() 函式與 messages(內含研究論文的文字)已預先載入。function_definition 變數也已部分填寫。

本練習屬於課程

使用 OpenAI API 開發 AI 系統

檢視課程

練習說明

  • 定義函式的 'type' 參數。
  • 定義 'properties' 參數,以從研究論文中擷取「標題」與「發表年份」。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

client = OpenAI(api_key="")

# Define the function parameter type
function_definition[0]['function']['parameters']['type'] = ____

# Define the function properties
function_definition[0]['function']['parameters']['properties'] = ____

response = get_response(messages, function_definition)
print(response)
編輯並執行程式碼