我正在使用 RASA 表单创建一个基本的聊天机器人。我想在插槽上添加特定条件,以便当它们为真时,将询问表单中的下一个问题;否则它将跳到进一步的问题。
这是我的故事 -
- story: phone/text prefer story
steps:
- intent: greet
- action: utter_greet
- intent: affirm
- action: basic_info_form
- active_loop: basic_info_form
- or:
- slot_was_set:
- contact_prefer: "phone call"
- slot_was_set:
- contact_prefer: "text(SMS)"
- active_loop: null
- action: utter_thank_you
- action: action_submit_form
我使用 Slot_was_set 来检查插槽的值;但是,无论 contact_prefer 槽的值如何,表单都会询问所有问题,然后结束并提交表单。
我在这里缺少什么吗?
任何帮助将不胜感激。谢谢。
实现这一目标的典型方法是:
required_slots
中,不要提及要跳过的插槽。就像默认情况下您会跳过该插槽一样。FormValidationAction
并在其中实现某些方法来完成的。required_slots()
,在其中检查是否需要询问跳过的插槽,如果是,则只需添加它。示例,在您的域文件中:
forms:
my_form:
required_slots:
- slot_a
_ slot_b
# assume you want to ask slot_c here if slot_b is set as "add"
_ slot_d
actions:
- validate_my_form
然后在自定义操作文件中:
class ValidateMyForm(FormValidationAction):
"""
Inserts slot_c if it needs to be asked.
"""
def name(self) -> Text:
return "validate_my_form"
async def required_slots(
self,
domain_slots: List[Text],
dispatcher: "CollectingDispatcher",
tracker: "Tracker",
domain: "DomainDict",
) -> List[Text]:
slots = slots.copy();
slot_b = tracker.get_slot("slot_b")
if(slot_b is not None and slot_b == "add"): # if it has been set and set as "add"
slots = ["slot_c"] + slots;
return slots;
这是如何运作的?
Rasa 将此称为
required_slots()
来检查它需要询问的所有插槽。默认情况下,它返回域文件的 required_slots:
部分中的插槽。注意:即使在返回的槽中,如果槽已设置,也不会被询问。 (如果
slot_c
已经设置,则不会询问)。