Rasa version: 1.10.1
I'm building a weatherbot in Rasa using custom actions and am facing issues in the actions.py file.
While testing the dialogue model using rasa shell / rasa interative , I'm receiving an error ' Key Error : 'location ' in country = current['location']['country'] , when I perform a query like ' Tell me the weather in Paris' . The entity is extracted correctly as Paris(location) and the slot(for location) is also filled . What could be causing this error given that the entity is correctly extracted ?
The terminal running rasa run actions shows the following error :
Exception occurred while handling uri: 'http://localhost:5055/webhook/'
Traceback (most recent call last):
File "c:\users\91887\anaconda3\envs\myenv\lib\site-packages\sanic\app.py", line 976, in handle_request
response = await response
File "c:\users\91887\anaconda3\envs\myenv\lib\site-packages\rasa_sdk\endpoint.py", line 102, in webhook
result = await executor.run(action_call)
File "c:\users\91887\anaconda3\envs\myenv\lib\site-packages\rasa_sdk\executor.py", line 387, in run
events = action(dispatcher, tracker, domain)
File "D:\Data Mining\Mini Projects\WeatherBot\actions.py", line 15, in run
country = current['location']['country']
KeyError: 'location'
My actions.py :
from rasa_sdk import Action
from rasa_sdk.events import SlotSet
class ActionWeather(Action):
def name(self):
return 'action_weather'
def run(self,dispatcher,tracker,domain):
from apixu.client import ApixuClient
api_key = '********'
client = ApixuClient(api_key)
loc = tracker.get_slot('location')
current = client.current(q=loc)
country = current['location']['country']
city = current['location']['name']
condition = current['current']['condition']['text']
temperature_c = current['current']['temp_c']
humidity = current['current']['humidity']
wind_mph = current['current']['wind_mph']
response =""" It is currently {} in {} at the moment . The temperature is {} degrees,the humidity is {}% and the wind speed is {} mph.""".format(condition,city,temperature_c,humidity,wind_mph)
dispatcher.utter_message(response)
return [SlotSet('location',loc)]
My config.yml file :
language: "en"
pipeline: "pretrained_embeddings_spacy"
policies:
- name: MemoizationPolicy
- name: KerasPolicy
epochs: 200
- name: MappingPolicy
What could be causing this error?