我一直在和rasa一起工作,还有一些我仍然不太了解的formAction
,我今天的问题是为什么?我的formAction
被激活,但它不存储任何slotvalue
,如果我使用不正确?这是我的代码:
class HotelForm(FormAction):
def name(self):
# type: () -> Text
return "formaejemplo"
@staticmethod
def required_slots(tracker):
return ["tipo_habitacion"]
def slot_mappings(self):
return {'tipo_habitacion':[self.from_entity(entity='tipo_habitacion',intent=['gethabitacion','peticion_habitacion'])]}
@staticmethod
def habitaciones_db():
return ["individual","doble","suite","suite doble"]
def submit(self, dispatcher, tracker, domain):
dispatcher.utter_template('utter_listo', tracker)
return []
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:
print('slot values:',slot_values)
slot_values.update(self.extract_requested_slot(dispatcher,tracker, domain))
if not slot_values:
try:
return super().validate(dispatcher, tracker, domain)
except ActionExecutionRejection as e:
# could not extract entity
dispatcher.utter_message(
"Sorry, I could not parse the value correctly. \n"
"Please double check your entry otherwise I will ask you this forever"
)
return []
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
# validation succeed, set the slots values to the extracted values
return [SlotSet(slot, value) for slot, value in slot_values.items()]
当我在控制台上打印值(slotvalues
)时,它总是为空。
当你第一次使用print('slot values:',slot_values)
时,它只收集了额外的插槽(所需插槽的实体,它没有要求,但无论如何都要拾取)。您不应该拥有任何这些,因为您只有一个必需的插槽。
至于你第二次print('slot values:',slot_values)
,你在slot_values.update(self.extract_requested_slot(dispatcher,tracker, domain))
之前做的,所以它和以前完全一样。更新发生后尝试打印它。如果您没有遇到if not slot_values
逻辑,那么如果您在更新后移动它,它应该正确打印。
当你做这些线时它是否正确打印?
print('Slot: ',slot)
print('valor: ',values)