Formaction中的广告位验证不起作用

时间:2019-04-11 00:18:40

标签: python rasa-nlu rasa-core

大家好,我有一个问题。自从我开始使用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()]

1 个答案:

答案 0 :(得分:0)

我可以看到的一个问题是

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:内调用