我正在尝试在此处实施FormAction,但是我已经覆盖了validate方法。
以下是同一代码:
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."
答案 0 :(得分:1)
默认情况下,ActionExecutionRejection不会发出名称为utter_ask_{slotname}
的模板,而是保留表单逻辑以允许其他策略(例如FallbackPolicy)采取措施。 utter_ask_{slotname}
是快乐路径的默认值,在该路径中,它第一次尝试获取所需的插槽。动作拒绝的默认实现是为了处理某些不愉快的路径,例如用户是否决定通过拒绝退出流程或通过聊天绕道等。
如果您想使用发声来实现模板以重新询问所需的插槽,则可以将ActionExecutionRejection替换为dispatcher.utter_template(<desired template name>, tracker)
。但是,如果没有验证,这将使您无法退出表单操作-我不知道您的意图是什么,但是也许您还希望基于意图合并一些逻辑(即,如果类似“拒绝” ,让ActionExecutionRejection发生,以便它可以退出,这是一种“输入数据”类型的意图,请确保再次询问。)