slot value returns None

133 Views Asked by At

version: "3.1"

intents:
  - greet
  - goodbye
  - inform


entities:
  - location

slots:
  location:
    type: text
    mappings:
    - type: from_entity
      entity: location
      intent: inform
      
actions:
  - action_weather


responses:
  utter_greet:
  - text: "Hey! How can I help you?"

  utter_goodbye:
  - text: "Bye bye"
  - text: "Have a nice day"

  utter_ask_locations:
  - text: in what location?

 

session_config:
  session_expiration_time: 60
  carry_over_slots_to_new_session: true

actions.py

from typing import Any, Text, Dict, List

from rasa_sdk import Action, Tracker
from rasa_sdk.executor import CollectingDispatcher
from rasa_sdk.events import SlotSet


class ActionWeather(Action):

    def name(self) -> Text:
        return "action_weather"

    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:

        import datetime as dt
        import requests

        BASE_URL = 'http://api.openweathermap.org/data/2.5/weather?'
        API_KEY = '[API_KEY]'

        location = tracker.get_slot("location")
         
        CITY = 'London'
        

        url1 = BASE_URL + "q=" + CITY +"&APPID=" +  API_KEY 

        response = requests.get(url1).json()
        temperature_c = response['main']['temp']-273.15
        humidity = response['main']['humidity']

        output = """the temperature is {} degrees, 
                        the humidity is {} and {}""".format(temperature_c,humidity, location)

        dispatcher.utter_message(text=output)

        return []

nlu.yml

from typing import Any, Text, Dict, List

from rasa_sdk import Action, Tracker
from rasa_sdk.executor import CollectingDispatcher
from rasa_sdk.events import SlotSet


class ActionWeather(Action):

    def name(self) -> Text:
        return "action_weather"

    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:

        import datetime as dt
        import requests

        BASE_URL = 'http://api.openweathermap.org/data/2.5/weather?'
        API_KEY = '5bb19e158658330f798faa1276c4a34b'

        location = tracker.get_slot("location")
         
        CITY = 'London'
        

        url1 = BASE_URL + "q=" + CITY +"&APPID=" +  API_KEY 

        response = requests.get(url1).json()
        temperature_c = response['main']['temp']-273.15
        humidity = response['main']['humidity']

        output = """the temperature is {} degrees, 
                        the humidity is {} and {}""".format(temperature_c,humidity, location)

        dispatcher.utter_message(text=output)

        return []

the output

enter image description here

I want to know why slot "location" not getting the value from the entity "location". it returns none How can I extract the value of a slot/entity during a conversation?

I have created a slot "location", and it takes the value of entity "location" from the intent "inform", but it seems like it's not taking the value from the slot.

0

There are 0 best solutions below