【问题标题】:form is not activated in Rasa 2.0表单在 Rasa 2.0 中未激活
【发布时间】:2021-02-24 22:48:24
【问题描述】:

我正在尝试在我的 rasa 聊天机器人中集成一个表单。 在 domain.yml 中,我包含了以下内容:

  1. 我声明了插槽:
slots:
    question1:
      type: text
   question2:
     type: text
   question3:
     type: text
  1. 表单应该发送给用户的问题:
     utter_ask_question1: 
       - text:" first question goes here"
     utter_ask_question2: 
       - text:" second question goes here"
     utter_ask_question3: 
       - text:" third question goes here"
  1. 将表单定义为:
forms: 
    user_quiz_form:
    question1:
      - type: from_text
        # entity: date
    question2:
       - type: from_text
    question3:
       - type: from_text 
  1. 操作部分还包含:
   actions:
      - action_submit
      - user_quiz_form

文件 rules.yml 包含:

   - rule: Activate quiz form
       steps:
       - intent: quiz
       - action: utter_quiz
       - action: user_quiz_form
       - active_loop: user_quiz_form
   - rule: Submit quiz form
     condition:
     - active_loop: user_quiz_form
    steps:
     - action: user_quiz_form
    - active_loop: null
    - slot_was_set:
      - requested_slot: null
    - action: action_submit

而actions.py是:

from typing import Any, Text, Dict, List
from rasa_sdk import Action, Tracker
from rasa_sdk.events import SlotSet, EventType
from rasa_sdk.executor import CollectingDispatcher
import webbrowser

class ValidateForm(Action):
    def name(self) -> Text:
        return "user_quiz_form"

    def run(
        self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict
    ) -> List[EventType]:
         required_slots = ["question1","question2", "question3"]
        
        for slot_name in required_slots:
          if tracker.slots.get(slot_name) is None:
                # The slot is not filled yet. Request the user to fill this slot next.
             return [SlotSet("requested_slot", slot_name)]
        return [SlotSet("requested_slot", None)]

class ActionSubmit(Action):
    def name(self) -> Text:
        return "action_submit"
    def run(
        self,
        dispatcher,
        tracker: Tracker,
        domain: "DomainDict",
    ) -> List[Dict[Text, Any]]:
       print("****************SUBMIT*****************")
       dispatcher.utter_message(template="utter_quiz_thanks", date=tracker.slots.get("question1"))
       return []

当表单被触发时,它不会向用户提问并返回 utter_quiz_thanks,其中 None 作为 question1 值。

【问题讨论】:

    标签: rasa-nlu rasa rasa-core


    【解决方案1】:

    这与您在 domain.yml 中使用的缩进相同吗?如果是这样,那么您缺少一些缩进;表单下方的插槽需要缩进(参见下面的示例)。我的猜测是您正确启动了表单,但由于缩进问题,您的助手将其视为包含 0 个问题的表单。

    forms:
      restaurant_form:
        cuisine:
          - type: from_entity
            entity: cuisine
        num_people:
          - type: from_entity
            entity: number
    

    【讨论】:

    • 我在 domain.yml 中使用了正确的缩进,就像在你的示例中一样。
    • 嗯,注意了。您介意分享您的完整对话日志吗? (rasa shell -vv) 编辑添加:我目前的快速修复是删除最新的模型并重新训练,以防你也想尝试。
    猜你喜欢
    • 2014-12-20
    • 1970-01-01
    • 1970-01-01
    • 2012-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-26
    相关资源
    最近更新 更多