客户支持聊天机器人的行为控制
当公司开始使用您在上一个练习中构建的聊天机器人后,他们意识到需要加入两个条件来改进交互:如果用户未提供订单号,则让客户支持聊天机器人向其索要订单号;当用户遇到技术问题时,向其表达同理心。
这项更新已分配给您。您需要将这些条件追加到 base_system_prompt(即您在上一个练习中设计的提示)上,从而得到 refined_system_prompt。您将用两个查询来测试该聊天机器人。
OpenAI 包、上一练习中开发的 base_system_prompt 字符串,以及 get_response() 函数都已为您预先加载。
本练习是课程的一部分
使用 OpenAI API 的 Prompt Engineering
练习说明
- 当用户提交与订单相关的查询但未给出订单号时,请向其索要其订单号;将该条件保存为
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)