首页 > 解决方案 > formActions 是如何工作的?

问题描述

我不明白槽映射​​如何知道要回答用户获得请求的“实体”的“话语”。


我的表单类的示例:

class RestaurantForm(FormAction):
  """Example of a custom form action"""
  def name(self):
    # type: () -> Text
    """Unique identifier of the form"""
    return "formaejemplo"

  @staticmethod
  def required_slots(tracker):
    # type: () -> List[Text]
    """A list of required slots that the form has to fill"""
    return ["valor1","valor2","valor3"]

  def slot_mappings(self):
    return {"valor1": self.from_entity(entity="valor1",intent="getvalor1"),
                "valor2": self.from_entity(entity="valor2",intent="getvalor2"),
                "valor3": self.from_entity(entity="valor3",intent="getvalor3")}

  def submit(self, dispatcher, tracker, domain):
    dispatcher.utter_template('utter_listo', tracker)
    return []

域.yml:

intents: 
- peticion_habitacion:
    use_entities: false
- getvalor1
- getvalor2
- getvalor3

entities:
- valor1
- valor2
- valor3

slots:
  valor1:
    type: unfeaturized
    auto_fill: false
  valor2:
    type: unfeaturized
    auto_fill: false
  valor3:
    type: unfeaturized
    auto_fill: false

actions:
- utter_prueba
- utter_completo

templates:
  utter_completo:
  - text: "listo:\nvalor 1 {valor1} \nvalor 2 {valor2} \nvalor 3 {valor3}"

  utter_prueba:
  - text: "iniciando prueba:\n"  

  utter_valor1:
  - text: "dame el valor 1 no enteros"

  utter_valor2:
  - text: "dame el valor 2 no enteros" 

  utter_valor3:
  - text: "dame el valor 3 no enteros"  

  utter_listo:
  - text: "prueba completa"  

forms:
 - formaejemplo

在您获得 value1、value2 等的部分...根据 Rasa 文档:“valor1”:self.from_entity (entity = "valor1", intent = "getvalor1" "the "valor 1" will be getting从意图 getvalor1."

我的问题是,在什么时间或在什么部分或什么文件中,操作表单被告知它必须发送“话语”“utter_valor1”或“utter_valor2”,因为有几个互联网示例加上相同的机器人示例rasa,我看到这些发送话语然后恢复价值,但我无法理解他们如何发送话语然后获得价值

标签: rasa-nlurasa-core

解决方案


我假设您的意思是动作 sdk 如何确定它应该使用哪个模板来请求请求的插槽,对吗?

这个逻辑实际上在这里是硬编码的:https ://github.com/RasaHQ/rasa_core_sdk/blob/cfffaac0013606f7614ab0f213bc39623ee8b53c/rasa_core_sdk/forms.py#L374

它所做的只是发送一个话语是utter_ask_{the name of slot which should be requested}.

如果用户随后发回他的答案,则再次触发表单操作并且可以提取槽值。


推荐阅读