How to include database information in the response message?

I am trying to include database information in the system response. For example, I have a database of lists of restaurants with its name, address, address, area, post code. I am trying to fetch information from database according to the user’s input message.

user input: Hello
sys response: Hello! welcome to our services
user input: Can you look for restaurants which serves european food?
sys response: I have list of restaurants for your choices [rest_A, rest_B, rest_C]

I am trying to use tracker package (from rasa_sdk import Action, Tracker) to get the required information from user’s input.

if any (tracker.get_latest_entity_values("Food")):
    food = tracker.current_slot_values()

Though, the input has entity value ‘european’ in the user’s input, it does not fetch the corresponding value. I have tried to use get_slot() but it throws attribute error, if any (tracker.get_latest_entity_values(“Food”)): value = tracker.get_latest_entity_values(“Food”) food = tracker.get_slot()

But, it throws Attribute Error

Could I get help to get the entity value from the user’s input? Any information would be helpful

I am trying to use tracker package (from rasa_sdk import Action, Tracker) to get the required information from user’s input

Seems you are already on the right path since custom actions written in python are indeed the way to go :rocket:

Do you have an entity Food in your domain.yml and are you sure european is correctly recognised by your entity extractor? I think it would help us debugging if you do a print(tracker.current_state()) in your custom action and share the printed message here.

And the log of the AttributeError would also be great :slightly_smiling_face:

Thank you for the Reply :slight_smile: @Tobias_Wochinger

Now, it works for me when I use the following Code.

if any (tracker.get_latest_entity_values("Food")):
    food = tracker.get_slot(key = 'Food')

I have received the following information, for print(Tracker.current_slot_values)

{'Addr': None, 'Area': 'west', 'Day': None, 'Food': 'vietnamese', 'Name': 'Rest_Name', 'People': None, 'Phone': None, 'Post': None, 'Price': 'cheap', 'none': None}

I have tried to get the details about particular Restaurant. It does not Output the Details for few Restaurant Name,even though the database has the Information About that.

For example,

user Input: Provide me the Details About the Restaurant Pizza Hut
sys Response: The Restaurant REST_NAME is located at ADDR in AREA
user Input: Provide me the Details About the Restaurant Dominos Pizza
sys Response: The Restaurant [] is located at [] in []

I have seen that the current Slot values does not get updated from Pizza Hut to Dominos Pizza

1){'Addr': None, 'Area': 'None', 'Day': None, 'Food': 'Italian', 'Name': 'Pizza Hut', 'People': None, 'Phone': None, 'Post': None, 'Price': 'None', 'none': None}

2){'Addr': None, 'Area': 'None', 'Day': None, 'Food': 'Italian', 'Name': 'Pizza Hut', 'People': None, 'Phone': None, 'Post': None, 'Price': 'None', 'none': None}

I have tried to get the details about particular Restaurant. It does not Output the Details for few Restaurant Name,even though the database has the Information About that.

Where you getting the restaurant detail and which code are you using to set the slots with the information?

@Tobias_Wochinger

I have the restaurant database in JSON format, which has a list of details in it. I have used python code which has developed by me, to access the specific information of each restaurants from the database. For example,

[ { “address”: xxxxx, “area”: yy, “food”: a, “name”: xyz", “phone”: “0927684566”, “postcode”: “cb21ab”, “pricerange”: “cheap”, “type”: “restaurant” } ]

Then, I use tracker with replacing the required entity names as follows,

if any (tracker.get_latest_entity_values("Food")):
    food = tracker.get_slot(key = 'Food')
if any (tracker.get_latest_entity_values("name")):
    food = tracker.get_slot(key = 'name')

Then i use for loop to search for restaurants which serves the specific food and to check the name of the restaurant.

I have noticed that if I specify any name of the restaurant which has seen in the training data of Rasa NLU, it extracts the information otherwise, it could not extract the information of the specific restaurant. Could you clarify me whether Rasa has solution to handle this scenario?

I have noticed that if I specify any name of the restaurant which has seen in the training data of Rasa NLU, it extracts the information otherwise, it could not extract the information of the specific restaurant.

So the problem is that Rasa NLU does not correctly extract the restaurant names? In that case you have to options

  • add more training examples for the entity extractor (how many do you have currently?)
  • checkout lookup tables

@Tobias_Wochinger Thanks for the info :slight_smile: Do I have to include the list of all names of the Restaurant in the lookup table? Is there any Option to use Restaurant Names as Out of-the Vocabulary words in Count Vector featurizer such that the similarity of those words can be learned and it can predict the Entity as Restaurant Name?

A lookup tables only makes sense if the set of possible values is limited. In case it’s arbitrary, it’s better to add more examples so that the conditional random field learns to pick it up from the sentence structure

@Tobias_Wochinger Thank you! :slight_smile: