如何使用 Amazon Lex 在一个话语中添加多个相同类型的槽?

How to add multiple slots of the same type in one utterance with Amazon Lex?

我正在构建一个允许用户选择一项或多项服务的聊天机器人。我想要的是用户在一个话语中添加许多相同类型的插槽。

我的服务槽有如下服务:

我希望用户能够输入:

I need {Service} and {Service}
I need {Service}, {Service} and {Service}

例如我需要咨询和治疗

但是当我尝试使用这些话语进行构建时,出现了这个错误:

The slot "{Service}," is invalid in utterance "I need {Service}, {Service} and {Service}" for intent "FindService". Slots in an utterance must have the form {slotName}.

我能够重现您的错误:

The slot "{_____}," is invalid in utterance "__________" for intent "___". Slots in an utterance must have the form {slotName}.

这是由于花括号 旁边有任何字符造成的,Lex 需要在“{slotName}”两边添加space。您将不得不完全删除逗号,因为如果您只是通过在 }, 之间放置 space 来修复它,那么您将收到此错误:

"," in utterance "________" for intent "___" contains an unsupported character or word. An utterance can consist only of Unicode characters, spaces, and valid punctuation marks. Valid punctuation marks are: periods for abbreviations, underscores, apostrophes, and hyphens. If there is a slot placeholder in your utterance, ensure that it's in the {slotName} format and has spaces at both ends.

此外,删除逗号后,您应该还会收到另一个错误:

The slot name "Service" was used more than once in utterance "I need {Service} {Service} and {Service}" for intent "FindService".

因此,要解决此问题,您应该创建多个具有不同 slotNames 但都使用相同 slotType 的插槽。使用插槽名称,例如:Service_one Service_two Service_three。 请注意,您不能在插槽名称中使用数字 (0-9),否则会出现错误:

The value specified for 'slots.#.member.name' is invalid. Member must satisfy regular expression pattern: ^(A-Za-z?)+$

创建这 3 个独立的槽后,您可以像这样编写新的有效话语:

I need {Service_one} and {Service_two}
I need {Service_one} {Service_two} and {Service_three}

该设置没有错误。现在我不知道 Lex 将如何区分话语 #2 的列表,尤其是让两个槽彼此紧挨着并寻找相同的 slotType 值。因此,您必须对其进行测试并观察 Lex 如何填充插槽,然后相应地构建您的 Lambda 验证代码。