stories
1 Format
以下是一个 Rasa story 格式的对话示例:
stories:
- story: collect restaurant booking info # name of the story - just for debugging
steps:
- intent: greet # user message with no entities
- action: utter_ask_howcanhelp
- intent: inform # user message with entities
entities:
- location: "rome"
- price: "cheap"
- action: utter_on_it # action that the bot should execute
- action: utter_ask_cuisine
- intent: inform
entities:
- cuisine: "spanish"
- action: utter_ask_num_people
1.1 User Messages
根据用户意图和实体的组合来预测下一个动作,你可以使用 use_entities 属性来更改此行为
1.2 Actions
在设计 stories 时,有两种类型的动作:话术和自定义动作。话术是机器人硬编码的响应消息,自定义动作是正在执行的自定义代码。
1.3 Events
像设置槽位、激活或取消表单之类的事件必须在 stories 中明确地写出。当自定义动作已经是 stories 的一部分时,必须单独包含自定义动作要返回的事件,看上去这是多余的,但是由于 Rasa 在训练期间无法确定这一事实,因此此步骤是必须的。
1.3.1 Slot Events
如果要在自定义动作中设置该槽位,则将其写在自定义动作事件的下一行。如果在自定义动作中的槽位值为 None,则对应的槽位事件为:- slot(“slot_name”: null)。
stories:
- story: set slot to none
steps:
# ... other story steps
- action: my_custom_action
- slot_was_set:
- my_slot: null
1.3.2 Form Events
处理 stories 中的表单事件时,需要牢记三种事件:
表单动作事件(例如:- action: restaurant_form):在第一次启动表单时使用,并且在表单已经处于激活状态时又继续使用表单动作。
表单激活事件(例如:- active_loop: restaurant_form")):在第一个表单动作事件之后立即激活使用。
表单停用事件(例如:- active_loop: null)):用于停用表单事件。
2 Checkpoints and OR statements
2.1 Checkpoints
你可以使用 > checkpoints 用来模块化或简化你的训练数据,检查点即使很有用,但也不要过度使用它,使用大量的检查点会导致你的示例 stories 难以理解。如果在不同的 stories 中经常重复执行 story 块,则使用它就很有意义,但是没有检查点的 stories 更易于读写。以下是一个包含检查点的示例 story 文件
stories:
- story: beginning of flow
steps:
- intent: greet
- action: action_ask_user_question
- checkpoint: check_asked_question
- story: handle user affirm
steps:
- checkpoint: check_asked_question
- intent: affirm
- action: action_handle_affirmation
- checkpoint: check_flow_finished
- story: handle user deny
steps:
- checkpoint: check_asked_question
- intent: deny
- action: action_handle_denial
- checkpoint: check_flow_finished
- story: finish flow
steps:
- checkpoint: check_flow_finished
- intent: goodbye
- action: utter_goodbye
与常规故事不同,检查点不限于从用户输入开始。只要在主要故事中的正确位置插入检查点,第一个事件也可以是自定义操作或响应。
2.2 Or Statements
使用 OR 语句可以设计简短的 stories 和以相同的方式处理多个意图,例如:你需要用户确认某件事,并且你想以相同的方式处理 affirm 和 thankyou 意图,以下 story 在训练时将被转换为两个 stories:
stories:
- story:
steps:
# ... previous steps
- action: utter_ask_confirm
- or:
- intent: affirm
- intent: thankyou
- action: action_handle_affirmation
和检查点一样,即使 OR 语句很有用,但不要过度使用,过度使用这些功能(检查点和 OR 语句)会减慢训练速度。