我正在使用 rasa forms
填充用户的广告位。我希望将整个用户消息填充到插槽中。我浏览了文档,发现了有关插槽映射的信息。但是在我的情况下,插槽是动态的, data.json, yml file and stories.md
都是使用Excel工作表创建的,因此我无法创建特殊形式。我创建了一个通用表单,该表单应在用户信息中填充该位置。但是由于我不知道插槽名称,所以无法创建它。请帮我。下面是我的代码:
def slot_mappings(self): # type: # () -> Dict[Text: Union[Dict, List[Dict]]]
intent_name = tracker.latest_message['intent'].get('name')
slot_names = df['slots'][df['Intent'] == intent_name].values
slot_names = [x.strip() for x in slot_names[0].split(',')]
slot_with_value = {}
for itms in slot_names:
slot_with_value[itms]="self.from_text()"
res = ', '.join('{}: {}'.format(key, value) for key, value in slot_with_value.items())
return res
在上面的代码中,数据帧具有一个字段作为插槽,用于存储与该意图有关的插槽信息。但是在 slot_mapping
中没有跟踪器,因此我无法创建字典,因此我的机器人将用户消息存储在插槽中。
下面是我的验证功能,该功能也无法正常工作并将用户消息存储在插槽中。
def validate(self, dispatcher, tracker, domain):
slot_values= self.extract_other_slots(dispatcher, tracker, domain)
slot_to_fill = tracker.get_slot(REQUESTED_SLOT)
user_input = tracker.latest_message['text']
requested_slot = self.request_next_slot(dispatcher, tracker, domain)
requested_slot = [elem['value'] for elem in requested_slot]
intent_name = tracker.latest_message['intent'].get('name')
slot_names = df['slots'][df['Intent'] == intent_name].values
slot_names = [x.strip() for x in slot_names[0].split(',')]
if slot_to_fill:
slot_values.update(self.extract_requested_slot(dispatcher,tracker, domain))
if not slot_values:
# reject form action execution
# if some slot was requested but nothing was extracted
# it will allow other policies to predict another action
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():
if slot in slot_names:
if value is None:
dispatcher.utter_message("Plese provide {}".format(slot))
slot_values[slot] = None
else:
dispatcher.utter_message("Plese provide {}".format(slot))
slot_values[slot] = user_input
return [SlotSet(slot, value) for slot, value in slot_values.items()]
它宁愿在用户提供一些输入后执行 ActionExecutionRejection
。我该如何处理。请帮助