Cobus Greyling
1 min readJan 29, 2020

--

Two updates to this story…

Firstly:

The one is that I managed to get entities (or as AWS Les refers to it, Slots) working contextually. I took cities, and gave it a Slot Type of Amazon European City. From here I could enter other City names, non-European and very unknown. Even fictitious names; and Lex could determine the name purely from context; even though the city name was not in Europe.

Below is my slot configuration.

Contextual Slot Detection In Amazon Lex

Secondly…

Below is the code from an updated Lamda function in Python 3.8 performing the following:

  • Setting two session attributes
  • Catching the entity and the intent and return it in a message.

This code can serve as a basic framework for you to build out your integration and add intelligence, checks and advanced dialog management.

def lambda_handler(event, context):
entity = event["currentIntent"]["slots"]["Name"].title()
intent = event["currentIntent"]["name"]

response = {

"sessionAttributes": {
"key1": "value1",
"key2": "value2"
},
"dialogAction":
{
"fulfillmentState":"Fulfilled",
"type":"Close",
"message":
{
"contentType":"PlainText",
"content": "The intent you are in now is "+intent+"! And the entity is "+entity+"!"
}
}

}
return response

--

--

Cobus Greyling
Cobus Greyling

Written by Cobus Greyling

I’m passionate about exploring the intersection of AI & language. www.cobusgreyling.com

No responses yet