平行函式呼叫
在你替行銷團隊從顧客評論中擷取資料之後,你任職的公司詢問是否也能產生一則可發布在評論平台上的顧客回覆。你決定使用平行函式呼叫,同時套用兩個函式,既產生結構化資料,也生成回覆內容。你會使用名為 reply_to_review 的函式,並要求將評論回覆作為 reply 屬性回傳。
在本練習中,get_response() 函式、messages 與 function_definition 變數都已預先載入。messages 已包含使用者的評論,而 function_definition 則包含用來擷取結構化資料的函式定義。
本練習屬於課程
使用 OpenAI API 開發 AI 系統
練習說明
- 在函式定義中新增設定,以回傳一則回應顧客評論的額外訊息:函式需包含
name、description與parameters,且parameters需包含type與properties。 - 列印輸出結果。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
client = OpenAI(api_key="")
# Append the second function
function_definition.append({'type': 'function', 'function':{'name': ____, ____, ____: {'type': ____, 'properties': {'reply': {____}}}}})
response = get_response(messages, function_definition)
# Print the response
____