RasaHQ / rasa

💬 Open source machine learning framework to automate text- and voice-based conversations: NLU, dialogue management, connect to Slack, Facebook, and more - Create chatbots and voice assistants
https://rasa.com/docs/rasa/
Apache License 2.0
18.95k stars 4.64k forks source link

Rasa actions.py KeyError : 'location' #6018

Closed Bharathi-A-7 closed 4 years ago

Bharathi-A-7 commented 4 years ago

Rasa version: 1.10.1

Python version: 3.6

Operating system: Windows

Issue: I'm building a weatherbot and 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 ?

image

Error (including full traceback):

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'

Command or request that led to error:

The action action_weather while running rasa shell/ rasa interactive to get weather updates for a given location ( Tell me the weather in Paris       -> action_weather )

Content of configuration file (config.yml) (if relevant):

language: "en"
pipeline: "pretrained_embeddings_spacy"

policies:
  - name: MemoizationPolicy
  - name: KerasPolicy
    epochs: 200
  - name: MappingPolicy

Content of domain file (domain.yml) (if relevant):

slots:
  location:
    type: text

intents:
 - greet
 - goodbye
 - inform

entities:
 - location

responses:
  utter_greet:
    - text: 'Hello! How can I help?'
  utter_goodbye:
    - text: 'Bye.Talk to you later.'
    - text: 'Bubye'
  utter_ask_location:
    - text: 'In what location?'

actions:
 - action_weather

Content of stories.md :

##story_001
* greet
    -utter_greet
* inform 
    -utter_ask_location
* inform{"location":"London"}
    -slot{"location":"London"}
    -action_weather
* goodbye
    -utter_goodbye

##story_002
*greet
    -utter_greet
* inform{"location":"Paris"}
    -slot{"location":"Paris"}
    -action_weather
* goodbye
    -utter_goodbye

##story_003
* greet
    -utter_greet
* inform 
    -utter_ask_location
* inform{"location":"Vilnius"}
    -slot{"location":"Vilnius"}
    -action_weather
* goodbye
    -utter_goodbye

##story_004
* greet
    -utter_greet
* inform{"location":"Italy"}
    -slot{"location":"Italy"}
    -action_weather
* goodbye
    -utter_goodbye

##story_005
* greet
    -utter_greet
* inform
    -utter_ask_location
* inform{"location":"Lithuania"}
    -slot{"location":"Lithuania"}
    -action_weather
* goodbye
    -utter_goodbye

Content of 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)]

What could be causing this error ? Please help me . Thanks

sara-tagger commented 4 years ago

Thanks for the issue, @tttthomasssss will get back to you about it soon!

You may find help in the docs and the forum, too 🤗
Bharathi-A-7 commented 4 years ago

I resolved it .

vikkooo013 commented 4 years ago

I resolved it .

Hey @Bharathi-A-7 please share how you were able to reolve it