Slots with entity values

Problem: I wanted to fetch the entity from the user’s question and match it with the list of entities stored in a google sheets but it is fetching only the entities which are present in the training data, if the entity is not from the training data it gives ‘None’ as the slot value. How to deal with this ? please help me resolve this issue.

Thanks

If you have an intent related to the slot filling, you can make a custom action to search words from the user message in the google sheet and set the slot with an event.

If you don’t, you can use a form, ask directly for the value of the slot (with mapping from_text(intent=None)), search the value in the google sheet and assign it.

Another option, if your list is relatively small, is to add the entire list to a lookup table.

 def run(self, dispatcher: CollectingDispatcher,
         tracker: Tracker,
         domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
     import gspread
     from oauth2client.service_account import ServiceAccountCredentials
     from pprint import pprint
     import pandas as pd

     scope = ["https://spreadsheets.google.com/feeds", 'https://www.googleapis.com/auth/spreadsheets',
           "https://www.googleapis.com/auth/drive.file", "https://www.googleapis.com/auth/drive"]

     creds = ServiceAccountCredentials.from_json_keyfile_name("cred.json", scope)
     client = gspread.authorize(creds)
     sheet = client.open("rasa") # Open the spreadsheet
     worksheet = sheet.get_worksheet(0)
     x = worksheet.get_all_records()
     pprint(x)
     data = pd.DataFrame(x)  # Get a list of all records
     skil = tracker.get_slot("skill")
     print(skil)
     a = []
     for i,v in enumerate(data['skill']):
         #print(v, skil)

         if v == skil:
             a.append('y')
         else:
             a.append('n')
     #print('this is a', a)
     if 'y' in a:
         dispatcher.utter_message("Yes")
     else:
         dispatcher.utter_message("Noooo")
     return (a)

This is what my custom action is

please have a look at my custom action and please do say where i was wrong

Thanks

You are trying to extract the slot directly from the tracker. If you want to do this, use the lookup table.

skil = tracker.get_slot("skill")

if skil is None:

dispatcher.uttermessage("please provide valid data")

else:
normal flow

and make sure , you are setting your slots in stories for example

  • intent_time{“time”:“3 o clock”}
    • slot{“time”:“3 o clock”}
    • action_thankyou

yes thanks @Bala but it is giving the entity name for the training data and when it comes to the data outside from the training data it is giving the slot value as ‘None’ even the data is valid question and i’ve checked the confidence it’s showing around 97 why is this heppening?

thanks @Gehova but i’ve used only one entity and i’ve given that as slot too i don’t see any point creating the lookup table.