终止支持通知:2025年9月15日, AWS 我们将停止对Amazon Lex V1的支持。2025 年 9 月 15 日之后,您将无法再访问亚马逊 Lex V1 主机或 Amazon Lex V1 资源。如果您使用的是 Amazon Lex V2,请改为参阅 Amazon Lex V2 指南。
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
练习 2:添加新表达 (AWS CLI)
为完善 Amazon Lex 用来识别用户请求的机器学习模型,我们再向机器人添加一个示例语句。
添加新表达的过程分为四步。
要运行本练习中的命令,您需要知道将在其中运行命令的区域。有关区域列表,请参阅 模型构建配额 。
来自 GetIntent 操作的响应包含一个名为 checksum 的字段,该字段标识目的的一个特定修订版。在使用 PutIntent 操作更新目的时必须提供校验和值。如果不提供,您会收到以下错误消息:
An error occurred (PreconditionFailedException) when calling
the PutIntent operation: Intent intent name already exists.
If you are trying to update intent name you must specify the
checksum.
注意
以下 AWS CLI 示例是针对 Unix、Linux 和 macOS 进行格式化的。对于 Windows,请将 "\$LATEST" 更改为 $LATEST 并将每行末尾的反斜杠 (\) 继续符替换为脱字号 (^)。
更新 OrderFlowers 目的 (AWS CLI)
-
在《》中 AWS CLI,从 Amazon Lex 那里获取意图。Amazon Lex 将输出发送到一个名为
OrderFlowers-V2.json.的文件aws lex-models get-intent \ --regionregion\ --name OrderFlowers \ --intent-version "\$LATEST" > OrderFlowers-V2.json -
在文本编辑器中打开
OrderFlowers-V2.json。-
找到并删除
createdDate、lastUpdatedDate和version字段。 -
将下面的内容添加到
sampleUtterances字段中:I want to order flowers -
保存该文件。
-
-
使用以下命令将更新后的意图发送给 Amazon Lex:
aws lex-models put-intent \ --regionregion\ --name OrderFlowers \ --cli-input-json file://OrderFlowers-V2.jsonAmazon Lex 会发送以下响应:
现在您已更新了目的,接下来要重建使用它的所有自动程序。
重建 OrderFlowersBot 自动程序 (AWS CLI)
-
在中 AWS CLI,获取
OrderFlowersBot机器人的定义并使用以下命令将其保存到文件中:aws lex-models get-bot \ --regionregion\ --name OrderFlowersBot \ --version-or-alias "\$LATEST" > OrderFlowersBot-V2.json -
在文本编辑器中,打开
OrderFlowersBot-V2.json。删除createdDate、lastUpdatedDate、status和version字段。 -
在文本编辑器中,将下面一行添加到自动程序定义中。
"processBehavior": "BUILD", -
在中 AWS CLI,通过运行以下命令来构建机器人的新版本:
aws lex-models put-bot \ --regionregion\ --name OrderFlowersBot \ --cli-input-json file://OrderFlowersBot-V2.json服务器的响应如下: