使用CodeHook验证时,Amazon Lex不提示缺少变量

编程入门 行业动态 更新时间:2024-10-11 13:21:12
本文介绍了使用CodeHook验证时,Amazon Lex不提示缺少变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在Amazon Lex中建立具有3个目的的代理.所有这三个intent都有一个已被标记为"required"的变量,这意味着代理在用户查询丢失时必须提示输入这些变量.

I am building an agent in Amazon Lex with around 3 intents. All the 3 intents have a variable which has been ticked as 'required', meaning the agent has to prompt for those variables when the user query is missing it.

但是,当我使用lambda函数作为代码钩子验证时,会触发,而无需提示缺少变量.

However when I am using a lambda function as codehook validation the , function gets triggered without prompting for the missing variable.

例如:Intent,用于描述与特定人员的通话中的通话记录:

For example: Intent which describes call notes from a call with a specific person:

提示是指定要查看其笔记的人的名字.

The prompt is " Specify the name of the person whose notes you want to see'

lambda函数的目的是打印出该人的通话记录为XYZ'

The objective of the lambda function is to print out "Call notes for the person is XYZ'

当我不通过代码钩子验证使用任何lambda函数时,我会提示输入人名,

When I don't use any lambda function through codehook validation, I get a prompt for the name of the person,

但是当我使用codehook验证时,lambda函数被触发,并且得到的答复为无呼叫的注释为XYZ".

but when I use codehook validation, the lambda function gets triggered and I get the reply as "Call notes for None is XYZ".

没有,因为,用户查询中没有提及此人的名字,也没有提示我输入该人的名字.

None because , there wasn't any mention of the person's name in the user query nor am I getting prompted for the person's name.

有人可以为此提供帮助吗?我已经尝试过对lambda函数进行各种修改,但是提示是否不应该是独立于lambda函数的功能?

Can anybody help regarding this? I have tried all sorts of modifications in the lambda function , but shouldn't the prompt be an independent functionality from the lambda function?

从2到3天以来,我一直在浏览和尝试与此有关的事情,但都陷入了僵局.

I have been browsing and trying things regarding this since 2~3 days and have hit a dead end.

推荐答案

之所以发生这种情况,是因为 Lambda初始化和验证发生在Amazon Lex中的插槽填充之前. 您仍然可以检查用户是否在DialogCodeHook中提供了"person"插槽,即验证部分. 下面的代码将帮助您完成工作:

This is happening because Lambda initialization and validation happens before Slot filling in Amazon Lex. You can still check that user have provided the "person" slot in DialogCodeHook i.e validation part. Something like below code will get your work done:

def build_validation_result(is_valid, violated_slot, message_content): if message_content == None: return { 'isValid': is_valid, 'violatedSlot': violated_slot } return { 'isValid': is_valid, 'violatedSlot': violated_slot, 'message': {'contentType': 'PlainText', 'content': message_content} } def validate_person(person): # apply validations here if person is None: return build_validation_result(False, 'person', 'Please enter the person name') return build_validation_result(True, None, None) def get_notes(intent_request): source = intent_request['invocationSource'] output_session_attributes = intent_request['sessionAttributes'] if intent_request['sessionAttributes'] is not None else {} slots = intent_request['currentIntent']['slots'] person = slots['person'] if source == 'DialogCodeHook': # check existence of "person" slot validation_result = validate_person(person) if not validation_result['isValid']: slots[ticket_validation_result['violatedSlot']] = None return elicit_slot( output_session_attributes, intent_request['currentIntent']['name'], slots, validation_result['violatedSlot'], validation_result['message'] ) return delegate(output_session_attributes, slots)

如果人员"插槽为空,将提示用户错误消息.这样,您无需在广告位上的必填"上打钩. 这是我在使用DialogCodeHook时遇到此问题时唯一想到的解决方法. 希望对您有所帮助.

If the "person" slot is empty, user will be prompted the error message. This way you don't need to tick on "Required" on the slot. This was the only workaround I could think of when I faced this problem while using DialogCodeHook. Hope it helps.

更多推荐

使用CodeHook验证时,Amazon Lex不提示缺少变量

本文发布于:2023-11-28 05:59:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1641207.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:变量   提示   CodeHook   Amazon   Lex

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!