本指南将介绍如何使用 playbook 构建一个简单的衬衫订购代理并进行测试。 与此代理互动时,您可以查询商店位置、获取商店营业时间或创建衬衫订单。
准备工作
在阅读本指南之前,请先完成以下事项:
- 如果您尚未进行初始配置,请按照 设置 说明操作。
关于 playbook
代理由一个或多个 playbook 组成。 每个 playbook 都有明确定义的有限范围。 playbook 包含以下数据:
| X | 推荐项 |
|---|---|
| 名称 | 用于标识 playbook 的名称。 |
| 目标 | 目标是对 playbook 应实现的目标的简要说明。 |
| 说明 | 说明是为实现 playbook 的目标而应采取的概要步骤。 |
| 示例 | 示例是最终用户与代理之间的对话示例。这些示例实际上是大语言模型的少样本提示示例。 |
创建智能体
如需创建代理,请执行以下操作:
前往 Conversational Agents 控制台:
选择或创建项目(如果您尚未执行此操作)。
点击 Create agent 。
点击自行构建 。
为代理名称提供“衬衫订购 - Playbook”。
提供 位置。
提供时区。
提供 默认语言。
对于对话发起 选项,选择 Playbook 。
点击创建 。
用户界面会将您带到名为 Default Generative Playbook 的默认 playbook。
点击返回按钮,查看 playbook 列表。
创建订单 playbook
Order playbook 用于处理衬衫订单。如需创建此 playbook,请执行以下操作:
- 点击创建 。
- 选择任务 playbook 选项。
- 输入 playbook 名称:
Order。 输入以下目标:
You are a shirt store ordering assistant. Help customers purchase shirts. Help the customer choose a size and color. The shirts come in small, medium, and large. The shirts can be red, green, or blue.输入以下说明:
- If the customer has not provided a size, ask them to choose a size. - If the customer has not provided a color, ask them to choose a color. - Once the customer has selected a size and color for the shirt, repeat the selection to the customer, and ask them to confirm the selection. - Once the customer has confirmed their selection, let them know that the shirt is now ordered. - Do not provide prices or collect payment. - Do not collect the customer's name or address.点击保存 。
点击返回按钮,返回到 playbook 列表。
创建信息 playbook
Information playbook 用于处理有关商店的问题。如需创建此 playbook,请执行以下操作:
- 点击创建 。
- 选择任务 playbook 选项。
- 输入 playbook 名称:
Information。 输入以下目标:
You provide information about a shirt store. The store is open between 8 AM and 6 PM every day. The store is located at 1007 Mountain Drive, Gotham City, NJ.输入以下说明:
- If the customer asks for the store location, provide them with the address. - If the customer asks for the store hours, provide them with the hours.点击保存 。
点击返回按钮,返回到 playbook 列表。
更新默认 playbook
首次创建应用时,系统会为您创建一个默认 playbook。 此 playbook 应将对话引导至具有特定目标的相应 playbook。在下面的说明中,您可以看到默认 playbook 如何引用其他 playbook。 如需更新此 playbook,请执行以下操作:
- 点击默认 playbook。此 playbook 带有突出显示的星形图标。
输入以下目标:
You are an assistant for a shirt store. Your name is "Samantha". Your job is to direct customers to other playbooks based on the customer's questions.输入以下说明:
- If the customer hasn't been greeted yet, greet the customer, introduce yourself, and ask the user how you can help. - If the customer wants information about the store, route them to ${PLAYBOOK: Information} - If the customer wants to purchase a shirt, route them to ${PLAYBOOK: Order}点击保存 。
请注意,由于还没有示例,因此 playbook 引用会突出显示。 这些内容将在下一部分中添加。
点击返回按钮,返回到 playbook 列表。
举例说明
此时,您的 playbook 已可正常运行。 不过,您必须提供 示例 ,以确保回答的质量。
当您打开 playbook 时,可以在示例 标签页中手动提供示例。 不过,通常更简单的方法是与正常运行的 playbook 进行对话,并将对话保存为示例。
与默认 playbook 的对话示例很短。 此 playbook 只需要将您引导至另一个 playbook。 如需与默认 playbook 进行对话,请执行以下操作:
- 关闭或取消屏幕右侧可能显示的任何面板。
- 点击顶部导航栏中的模拟器 按钮。
- 对于资源,选择默认 playbook。
- 使用默认模型或选择其他模型。
- 在显示输入用户输入内容的文本框中,
输入
Hello,然后按 Enter 键。 - playbook 会做出问候响应。
如需将此对话保存为示例,请执行以下操作:
- 在调用 下拉菜单中选择默认 playbook。
- 点击界面右上角附近的另存为示例 按钮。
- 此时会打开示例编辑器面板。 您可以使用此编辑器添加、修改、删除或重新排序操作。
- 提供示例名称:
Greeting。 - 根据需要更新 playbook 响应。
- 向下滚动到以输出信息结束示例 部分,然后在摘要 部分中输入
The user is greeted.。 - 点击保存图标。
为信息 playbook 添加位置示例:
- 关闭或取消屏幕右侧可能显示的任何面板。
- 如有必要,使用 重置 restart_alt 按钮重置话题。
- 在模拟器的 Start Resource 下拉菜单中选择信息 playbook。
- 输入消息:
Where are you located?。 - playbook 会做出位置响应。
- 在调用 下拉菜单中选择信息 playbook。
- 点击另存为示例 按钮。
- 提供示例名称:
Location。 - 在将此对话保存为示例之前,您必须删除包含“Where are you located”的操作。 只有默认 playbook 示例可以从用户操作开始。
- 如需为示例提供启动对话的上下文,
请展开 前一个对话的摘要… 部分,
然后在 以输入信息开始示例 字段中输入以下内容:
The customer asked "Where are you located?"。 - 如需为示例提供完成对话的上下文,请展开 playbook 执行的摘要… 部分,然后在以输出信息结束示例 字段中输入以下内容:
The store is located at 1007 Mountain Drive, Gotham City, NJ.。 - 点击保存图标。
为信息 playbook 添加营业时间示例:
- 与上述步骤类似,但输入消息:
What are your hours?,并将示例命名为:Hours。
为订单 playbook 添加选择示例:
与上述步骤类似,但将示例命名为
Selection,选择订单 playbook,然后发送以下消息:I want to buy a shirtLargeGreenYes
测试代理
您的代理现在已准备就绪,可以进行测试。 打开模拟器面板,与代理进行对话。 您无需进行与上述相同的对话。 例如,您可以询问此代理衬衫有哪些颜色可供选择。 如果您没有获得所需的行为,则优化示例并创建新示例将有助于改进响应。
使用 API 与代理互动
请参阅 通过 API 进行互动。