RASA FormAction ActionExecutionRejection 不会重新提示缺少插槽
RASA FormAction ActionExecutionRejection doesn’t re-prompt for missing slot
我正在尝试在这里实现一个 FormAction,我已经覆盖了验证方法。
这是相同的代码:
def validate(self, dispatcher, tracker, domain):
logger.info("Validate of single entity called")
document_number = tracker.get_slot("document_number")
# Run regex on latest_message
extracted = re.findall(regexp, tracker.latest_message['text'])
document_array = []
for e in extracted:
document_array.append(e[0])
# generate set for needed things and
document_set = set(document_array)
document_array = list(document_set)
logger.info(document_set)
if len(document_set) > 0:
if document_number and len(document_number):
document_array = list(set(document_array + document_number))
return [SlotSet("document_number", document_array)]
else:
if document_number and len(document_number):
document_array = list(set(document_array + document_number))
return [SlotSet("document_number", document_array)]
else:
# Here it doesn't have previously set slot
# So Raise an error
raise ActionExecutionRejection(self.name(),
"Please provide document number")
因此,理想情况下,根据文档,当发生 ActionExecutionRejection 时,它应该发出名称为 utter_ask_{slotname} 的模板,但它不会触发该操作。
这是我的 domain.yml 模板
templates:
utter_greet:
- text: "Hi, hope you are having a good day! How can I help?"
utter_ask_document_number:
- text: "Please provide document number"
utter_help:
- text: "To find the document, please say the ID of a single document or multiple documents"
utter_goodbye:
- text: "Talk to you later!"
utter_thanks:
- text: "My pleasure."
默认情况下,ActionExecutionRejection 不会发出名称为 utter_ask_{slotname}
的模板,而是保留表单逻辑以允许其他策略(例如 FallbackPolicy)采取行动。 utter_ask_{slotname}
是它第一次尝试获得所需插槽的快乐路径的默认设置。这个动作拒绝的默认实现是为了处理某些不愉快的路径,例如如果用户决定他们想要通过拒绝退出流程,或者通过聊天绕道等。
如果要实现模板以使用话语重新请求所需的插槽,可以将 ActionExecutionRejection 替换为 dispatcher.utter_template(<desired template name>, tracker)
。但是,这将使您无法在未经验证的情况下退出表单操作——我不知道您的意图是什么,但也许您还想根据意图合并一些逻辑(即,如果它像 "deny",让 ActionExecutionRejection 发生,这样它就可以退出,这是一种 "enter data" 类型的意图,确保它再次询问)。
我正在尝试在这里实现一个 FormAction,我已经覆盖了验证方法。
这是相同的代码:
def validate(self, dispatcher, tracker, domain):
logger.info("Validate of single entity called")
document_number = tracker.get_slot("document_number")
# Run regex on latest_message
extracted = re.findall(regexp, tracker.latest_message['text'])
document_array = []
for e in extracted:
document_array.append(e[0])
# generate set for needed things and
document_set = set(document_array)
document_array = list(document_set)
logger.info(document_set)
if len(document_set) > 0:
if document_number and len(document_number):
document_array = list(set(document_array + document_number))
return [SlotSet("document_number", document_array)]
else:
if document_number and len(document_number):
document_array = list(set(document_array + document_number))
return [SlotSet("document_number", document_array)]
else:
# Here it doesn't have previously set slot
# So Raise an error
raise ActionExecutionRejection(self.name(),
"Please provide document number")
因此,理想情况下,根据文档,当发生 ActionExecutionRejection 时,它应该发出名称为 utter_ask_{slotname} 的模板,但它不会触发该操作。
这是我的 domain.yml 模板
templates:
utter_greet:
- text: "Hi, hope you are having a good day! How can I help?"
utter_ask_document_number:
- text: "Please provide document number"
utter_help:
- text: "To find the document, please say the ID of a single document or multiple documents"
utter_goodbye:
- text: "Talk to you later!"
utter_thanks:
- text: "My pleasure."
默认情况下,ActionExecutionRejection 不会发出名称为 utter_ask_{slotname}
的模板,而是保留表单逻辑以允许其他策略(例如 FallbackPolicy)采取行动。 utter_ask_{slotname}
是它第一次尝试获得所需插槽的快乐路径的默认设置。这个动作拒绝的默认实现是为了处理某些不愉快的路径,例如如果用户决定他们想要通过拒绝退出流程,或者通过聊天绕道等。
如果要实现模板以使用话语重新请求所需的插槽,可以将 ActionExecutionRejection 替换为 dispatcher.utter_template(<desired template name>, tracker)
。但是,这将使您无法在未经验证的情况下退出表单操作——我不知道您的意图是什么,但也许您还想根据意图合并一些逻辑(即,如果它像 "deny",让 ActionExecutionRejection 发生,这样它就可以退出,这是一种 "enter data" 类型的意图,确保它再次询问)。