用于导入和导出的 JSON 格式 - Amazon Lex

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

用于导入和导出的 JSON 格式

您可以根据包含描述资源各部分的 JSON 结构的 .zip 文件从 Amazon Lex V2 中导入和导出机器人、机器人区域设置或自定义词汇。当您导出资源时,Amazon Lex V2 会创建 .zip 文件,并通过 Amazon S3 的预签名 URL 将其提供给您。导入资源时,必须创建一个包含 JSON 结构的 .zip 文件并将其上传到 S3 预签名 URL。

当您导出机器人时,Amazon Lex 会在 .zip 文件中创建以下目录结构。导出机器人区域设置时,仅导出该区域设置下的结构。导出自定义词汇时,仅导出自定义词汇下的结构。

BotName_BotVersion_ExportID_LexJson.zip -or- BotName_BotVersion_LocaleId_ExportId_LEX_JSON.zip --> manifest.json --> BotName ----> Bot.json ----> BotLocales ------> Locale_A --------> BotLocale.json --------> Intents ----------> Intent_A ------------> Intent.json ------------> Slots --------------> Slot_A ----------------> Slot.json --------------> Slot_B ----------------> Slot.json ----------> Intent_B ... --------> SlotTypes ----------> SlotType_A ------------> SlotType.json ----------> SlotType_B ... --------> CustomVocabulary ------------> CustomVocabulary.json ------> Locale_B ...

清单文件结构

清单文件包含导出文件的元数据。

{ "metadata": { "schemaVersion": "1.0", "fileFormat": "LexJson", "resourceType": "Bot | BotLocale | CustomVocabulary" } }

机器人文件结构

机器人文件包含机器人的配置信息。

{ "name": "BotName", "identifier": "identifier", "version": "number", "description": "description", "dataPrivacy": { "childDirected": true | false }, "idleSessionTTLInSeconds": seconds }

机器人区域设置文件结构

机器人区域设置文件包含对机器人的区域或语言的描述。导出机器人时,.zip 文件中可以包含多个机器人区域设置文件。导出机器人区域设置时,该 .zip 文件中只有一个区域设置。

{ "name": "locale name", "identifier": "locale ID", "version": "number", "description": "description", "voiceSettings": { "voiceId": "voice", "engine": "standard | neural }, "nluConfidenceThreshold": number }

意图文件结构

意图文件包含意图配置信息。.zip 文件中针对特定区域设置的每个意图都有一个意图文件。

BookTrip 机器人中 BookCar 意图的 JSON 结构示例如下。有关意图的 JSON 结构的完整示例,请参阅 CreateIntent 操作。

{ "name": "BookCar", "identifier": "891RWHHICO", "description": "Intent to book a car.", "parentIntentSignature": null, "sampleUtterances": [ { "utterance": "Book a car" }, { "utterance": "Reserve a car" }, { "utterance": "Make a car reservation" } ], "intentConfirmationSetting": { "confirmationPrompt": { "messageGroupList": [ { "message": { "plainTextMessage": { "value": "OK, I have you down for a {CarType} hire in {PickUpCity} from {PickUpDate} to {ReturnDate}. Should I book the reservation?" }, "ssmlMessage": null, "customPayload": null, "imageResponseCard": null }, "variations": null } ], "maxRetries": 2 }, "declinationResponse": { "messageGroupList": [ { "message": { "plainTextMessage": { "value": "OK, I have cancelled your reservation in progress." }, "ssmlMessage": null, "customPayload": null, "imageResponseCard": null }, "variations": null } ] } }, "intentClosingSetting": null, "inputContexts": null, "outputContexts": null, "kendraConfiguration": null, "dialogCodeHook": null, "fulfillmentCodeHook": null, "slotPriorities": [ { "slotName": "DriverAge", "priority": 4 }, { "slotName": "PickUpDate", "priority": 2 }, { "slotName": "ReturnDate", "priority": 3 }, { "slotName": "PickUpCity", "priority": 1 }, { "slotName": "CarType", "priority": 5 } ] }

插槽文件结构

插槽文件包含意图中插槽的配置信息。.zip 文件中包含一个插槽文件,用于在特定区域设置中为某个意图定义的每个插槽。

插槽的 JSON 结构允许客户在 BookTrip 示例机器人的 BookCar 意图中选择他们想要租的汽车类型,示例如下。有关插槽的 JSON 结构的完整示例,请参阅 CreateSlot 操作。

{ "name": "CarType", "identifier": "KDHJWNGZGC", "description": "Type of car being reserved.", "multipleValuesSetting": { "allowMutlipleValues": false }, "slotTypeName": "CarTypeValues", "obfuscationSetting": null, "slotConstraint": "Required", "defaultValueSpec": null, "slotValueElicitationSetting": { "promptSpecification": { "messageGroupList": [ { "message": { "plainTextMessage": { "value": "What type of car would you like to rent? Our most popular options are economy, midsize, and luxury" }, "ssmlMessage": null, "customPayload": null, "imageResponseCard": null }, "variations": null } ], "maxRetries": 2 }, "sampleValueElicitingUtterances": null, "waitAndContinueSpecification": null, } }

复合插槽的 JSON 结构示例如下。

{ "name": "CarType", "identifier": "KDHJWNGZGC", "description": "Type of car being reserved.", "multipleValuesSetting": { "allowMutlipleValues": false }, "slotTypeName": "CarTypeValues", "obfuscationSetting": null, "slotConstraint": "Required", "defaultValueSpec": null, "slotValueElicitationSetting": { "promptSpecification": { "messageGroupList": [ { "message": { "plainTextMessage": { "value": "What type of car would you like to rent? Our most popular options are economy, midsize, and luxury" }, "ssmlMessage": null, "customPayload": null, "imageResponseCard": null }, "variations": null } ], "maxRetries": 2 }, "sampleValueElicitingUtterances": null, "waitAndContinueSpecification": null, }, "subSlotSetting": { "slotSpecifications": { "firstname": { "valueElicitationSetting": { "promptSpecification": { "allowInterrupt": false, "messageGroupsList": [ { "message": { "imageResponseCard": null, "ssmlMessage": null, "customPayload": null, "plainTextMessage": { "value": "please provide firstname" } }, "variations": null } ], "maxRetries": 2, "messageSelectionStrategy": "Random" }, "defaultValueSpecification": null, "sampleUtterances": [ { "utterance": "my name is {firstName}" } ], "waitAndContinueSpecification": null }, "slotTypeId": "AMAZON.FirstName" }, "eyeColor": { "valueElicitationSetting": { "promptSpecification": { "allowInterrupt": false, "messageGroupsList": [ { "message": { "imageResponseCard": null, "ssmlMessage": null, "customPayload": null, "plainTextMessage": { "value": "please provide eye color" } }, "variations": null } ], "maxRetries": 2, "messageSelectionStrategy": "Random" }, "defaultValueSpecification": null, "sampleUtterances": [ { "utterance": "eye color is {eyeColor}" }, { "utterance": "I have eyeColor eyes" } ], "waitAndContinueSpecification": null }, "slotTypeId": "7FEVCB2PQE" } }, "expression": "(firstname OR eyeColor)" } }

插槽类型文件结构

插槽类型文件中包含在某种语言或区域设置中使用的自定义插槽类型的配置信息。对于特定区域设置中的每种自定义插槽类型,.zip 文件中都包含一个插槽类型文件。

以下是插槽类型的 JSON 结构,其中列出了 BookTrip 示例机器人中可用的汽车类型。有关插槽类型的 JSON 结构的完整示例,请参阅 CreateSlotType 操作。

{ "name": "CarTypeValues", "identifier": "T1YUHGD9ZR", "description": "Enumeration representing possible types of cars available for hire", "slotTypeValues": [{ "synonyms": null, "sampleValue": { "value": "economy" } }, { "synonyms": null, "sampleValue": { "value": "standard" } }, { "synonyms": null, "sampleValue": { "value": "midsize" } }, { "synonyms": null, "sampleValue": { "value": "full size" } }, { "synonyms": null, "sampleValue": { "value": "luxury" } }, { "synonyms": null, "sampleValue": { "value": "minivan" } }], "parentSlotTypeSignature": null, "valueSelectionSetting": { "resolutionStrategy": "TOP_RESOLUTION", "advancedRecognitionSetting": { "audioRecognitionStrategy": "UseSlotValuesAsCustomVocabulary" }, "regexFilter": null } }

复合插槽类型的 JSON 结构示例如下。

{ "name": "CarCompositeType", "identifier": "TPA3CC9V", "description": null, "slotTypeValues": null, "parentSlotTypeSignature": null, "valueSelectionSetting": { "regexFilter": null, "resolutionStrategy": "CONCATENATION" }, "compositeSlotTypeSetting": { "subSlots": [ { "name": "model", "slotTypeId": "MODELTYPEID" # custom slot type Id for model }, { "name": "city", "slotTypeId": "AMAZON.City" }, { "name": "country", "slotTypeId": "AMAZON.Country" }, { "name": "make", "slotTypeId": "MAKETYPEID" # custom slot type Id for make } ] } }

以下插槽类型通过自定义语法来理解客户言语。有关更多信息,请参阅语法插槽类型

{ "name": "custom_grammar", "identifier": "7KEAQIQKPX", "description": "Slot type using a custom grammar", "slotTypeValues": null, "parentSlotTypeSignature": null, "valueSelectionSetting": null, "externalSourceSetting": { "grammarSlotTypeSetting": { "source": { "kmsKeyArn": "arn:aws:kms:Region:123456789012:alias/customer-grxml-key", "s3BucketName": "grxml-test", "s3ObjectKey": "grxml_files/grammar.grxml" } } } }

自定义词汇文件结构

自定义词汇文件中包含单一语言或区域设置的自定义词汇中的条目。在 .zip 文件中,每个具有自定义词汇的区域设置都有一个自定义词汇文件。

用于机器人接收餐厅订单的自定义词汇文件如下。机器人中每个区域设置都有一个文件。

{ "customVocabularyItems": [ { "weight": 3, "phrase": "wafers" }, { "weight": null, "phrase": "extra large" }, { "weight": null, "phrase": "cremini mushroom soup" }, { "weight": null, "phrase": "ramen" }, { "weight": null, "phrase": "orzo" } ] }