客服聊天機器人的行為控制
公司開始使用你在上一個練習中建立的聊天機器人後,發現還想加入兩個條件來改善互動:如果使用者沒有提供訂單編號,就請客服機器人主動詢問;當使用者遇到技術問題時,機器人需要表達同理心。
他們把這次更新交給你。你需要把這兩個條件附加到代表你上一題設計成果的 base_system_prompt,並產生一個 refined_system_prompt。接著,你會用兩個查詢來測試這個聊天機器人。
OpenAI 套件、上一個練習中建立的字串 base_system_prompt,以及 get_response() 函式都已為你預先載入。
本練習屬於課程
使用 OpenAI API 的提示工程
練習說明
- 當使用者對訂單提出查詢但未提供訂單編號時,請要求他們提供「訂單編號」;將此條件儲存為
order_number_condition。 - 定義
technical_issue_condition:當使用者回報技術問題時,指示模型以I'm sorry to hear about your issue with ...作為回應開頭。 - 建立
refined_system_prompt,將base_system_prompt與上述兩個新條件合併。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
client = OpenAI(api_key="")
# Define the order number condition
order_number_condition = "____"
# Define the technical issue condition
technical_issue_condition = "____"
# Create the refined system prompt
refined_system_prompt = ____
response_1 = get_response(refined_system_prompt, "My laptop screen is flickering. What should I do?")
response_2 = get_response(refined_system_prompt, "Can you help me track my recent order?")
print("Response 1: ", response_1)
print("Response 2: ", response_2)