You can use the Amazon Lex NLU Connector to connect to Amazon Lex and use the language understanding results from this service to power the NLU of agents within Cognigy.AI.
Requirements
You'll need the following credentials and settings to successfully connect to a Lex Chatbot from Cognigy.AI:
- Access Key
- Secret Access Key
- AWS Region
- Bot Id
- Bot Alias Id
Setup
1. Prerequisites
Before setting up an Amazon Lex Bot get sure you have access to a user with credentials for the AWS console and your user has at least the following rights:
- iam:CreateUser
- iam:CreatePolicy
- iam:AttachUserPolicy
- lex:ListBotAliases
- lex:ListBotLocales
- lex:ListBots
- lex:ListBotVersions
- lex:ListBuiltInIntents
- lex:ListBuiltInSlotTypes
- lex:ListSlots
- lex:ListSlotTypes
- lex:DescribeBot
- lex:DescribeBotAlias
- lex:DescribeBotLocale
- lex:DescribeBotVersion
- lex:DescribeSlot
- lex:DescribeSlotType
- lex:CreateBot
- lex:CreateBotAlias
- lex:CreateBotLocale
- lex:CreateBotVersion
- lex:CreateIntent
- lex:CreateSlot
- lex:RecognizeText
- lex:StartConversation
2. Create a Lex Bot
As each customer use case varies we will focus on creating and connecting a sample bot in this article. For further information please refer to the official Lex documentation
Logon to the AWS console and open the Lex start page, then create a new bot.
We will start with the example called OrderFlowers as it demonstrates perfectly how Lex NLU can be used together with Cognigy.AI.
Further down on this page select a proper name for your new Lex bot and choose to automatically create a new IAM role for execution.
The language screen is important. Lex needs to be configured for each language you intend to use. Languages are mapped according to the locale of the user calling four Cognigy.AI flows, so get sure to add several languages in case your flows support multiple languages, otherwise you will run into errors.
After you press done you will see the OrderFlowers intent with two parts of interest.
The utterances section lists all utterances that can be called to trigger the NLU. The utterances don't need to be 100% accurate to trigger the intent, if there's no 100% match all intents will be compared to pick the most accurate one or the empty fallback intent. Here you can add any number of additional sentences per intent.
Amazon Lex supports slots but they work different than in Cognigy.AI. In Lex you will create some utterances to start an intent but due to the slots it acts as some kind of whole conversation. All slots have a slot question and each question will be asked in exactly the same order to retrieve each kind of information that wasn't answered in the utterance used to trigger it.
As this lays the whole conversation design in the hands of Lex and causes sideeffects as each response gives a different output depending on the order we decided to randomize the session id and to use the NLU as if the message was always the first in a conversation.
To use the NLU in a realiable way we use utterances that have several slots.
You can select parts of an utterance and replace it with a slot, this way all information at this position will be saved to a slot. A user input "I want to pick up roses tomorrow at 12pm" will then trigger this intent and fill all three slots
Intent --> OrderFlowers
FlowerType --> roses
PickupDate --> the date string of the day tomorrow
PickupTime --> 12:00:00
All this information will be accessible in Cognigy.AI using the {{input}} object.
To get started we first need to save our changes and then build it using the bottom bar. Keep in mind that it needs to be built for each language you want to use. Use the test to check if utterances got recognized properly afterwards.
Using the "Back to Intents list" we can go to the intents list where we can see a sidebar with all important sections we need for configuration.
At first we see the name of the bot, "Docubot" in this case
Bot versions are read-only compiled versions that can be shared and a draft version that is used for development but can't be shared. We start in the draft version but we have to change it later to test already created versions
Below we see a list of languages added to the bot. I created a second language for German for demonstration purpose. Keep in mind that you need to trigger the build process for each language you use.
At last we have aliases that can be stored in our Cognigy.AI Endpoint configuration. They work like a link to a version that can be changed in Lex afterwards to avoid modifying the embedding code.
To make our Lex Bot reachable so we can use the NLU we need to click "Bot versions" in the sidebar to see the list of versions. At first we only have the draft so we need to click "Create version".
Always double check that all languages are properly built, otherwise you can't add them to the version, then click "Create".
The next step is to create a new alias using the "Aliases" sidebar menu. There is already one entry but this one is for testing purposes only and can't be used for our use case. Click "Create alias" to create a new one.
Add a name for the new alias and associate it with the Version 1 we just created. Click Create and it is ready to be used in our NLU Connector.
When we click our new alias we will see a URL in our browser that will look like this:
Copy X to a text file as it will be later used as our Bot ID and Y as our Bot Alias Id.
Now we need to create a user with proper rights.
3. Create a User and Policy
Open the AWS IAM console and create a new IAM user that will have all rights mandatory for calling the Lex Bot from Cognigy.AI.
Check "Access key - Programmatic access" to retrieve credentials when the user is created.
Open the tab "Attach existing policies directly" and create a new policy. A new browser tab will open.
Search for the service Lex and you will receive two matches. Select the V2 as we use the new API for our NLU connector.
Go to the Write section and check "Recognize Text".
It is possible to give the user only access to the Lex Bot we just created if we specify the Bot Alias to be value Y we copied in step 2. If we want to grant him access to all bots we should choose "All resources".
We don't need tags therefore we are now ready to give it a name and save it.
Now returning to the IAM User tab we won't be able to find our new policy. Hit the refresh icon on the right, search for it and check the checkbox in front of it, then skip the Tags section and click "Create user"
You can now access the Access key ID and Secret access key. Note both down as this is the only time you will be able to see them and we need both for our NLU endpoint settings. You can also download them as a .csv file as well.
4. Cognigy.AI configuration
To use Amazon Lex NLU for our flows we need to do some configuration in our Cognigy.AI installation. NLU connectors can be created in Build-->NLU Connectors in the sidebar, then select Lex as the NLU Connector Type.
After completing the previous steps we got all that is required for the configuration.
Access Key --> The access key we copied from the user we created
Secret Access Key --> The secret access key we copied from the user we created
AWS Region --> The AWS region we used to create the Lex Bot.
Bot Id --> The value X we copied from the URL at the end of step 2
Bot Alias Id --> The value Y we copied from the URL at the end of step 2
If we want to use the Lex NLU and additionally the Cognigy.AI Slot parsing we can toggle "Reparse Lex Slots".
From now on we can select our new NLU connector at the top of the interaction panel for testing
and pick our NLU connector in the configuration of our Endpoints.
Comments
0 comments