大家好,我有一个问题。自从开始使用rasa-nlurasa-core以来已经有一段时间了,我的问题是为什么对我的编队的验证不能正确进行?我正在打印slotvalues,它总是返回空。我想知道如何解决这个问题,它只要求第一个插槽,然后就吹了!

这是我的代码:



def validate(self,dispatcher: CollectingDispatcher,tracker: Tracker,domain: Dict[Text, Any]) -> List[Dict]:
    slot_values = self.extract_other_slots(dispatcher, tracker, domain)
    print('slot values:',slot_values)
    slot_to_fill = tracker.get_slot(REQUESTED_SLOT)
    if slot_to_fill:
        slot_values.update(self.extract_requested_slot(dispatcher,tracker, domain))

    if not slot_values:
        raise ActionExecutionRejection(self.name(),"Failed to validate slot {0} with action {1}".format(slot_to_fill,self.name()))

    for slot, value in slot_values.items():
      print('Slot: ',slot)
      print('valor: ',values)
      if slot == 'tipo_habitacion':
        if value.lower() not in self.habitaciones_db():
          dispatcher.utter_template('utter_wrong_tipo_habitacion', tracker)
          # validation failed, set slot to None
          slot_values[slot] = None
      if slot == 'mes':
        if value.lower() not in self.meses_db():
          dispatcher.utter_template('utter_wrong_mes', tracker)
          # validation failed, set slot to None
          slot_values[slot] = None

      elif slot == 'num_adultos':
        if not self.is_int(value) or int(value) <= 0:
          dispatcher.utter_template('utter_wrong_num_adultos',tracker)
          # validation failed, set slot to None
          slot_values[slot] = None

      elif slot == 'num_niños':
        if not self.is_int(value) or int(value) <= 0:
          dispatcher.utter_template('utter_wrong_num_niños',tracker)
          # validation failed, set slot to None
          slot_values[slot] = None

      elif slot == 'dia':
        if not self.is_int(value) or int(value) <= 0:
          dispatcher.utter_template('utter_wrong_dia',tracker)
          # validation failed, set slot to None
          slot_values[slot] = None
    # validation succeed, set the slots values to the extracted values
    return [SlotSet(slot, value) for slot, value in slot_values.items()]

最佳答案

我可以看到的一个问题是

if not slot_values:
        raise ActionExecutionRejection(self.name(),"Failed to validate slot {0} with action {1}".format(slot_to_fill,self.name()))


应该从内部if slot_to_fill:调用

关于python - Formaction中的广告位验证不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55622989/

10-12 18:00