Hey there,
How can I get from the rasa stack starterpack the value of the name example into the actions.py file?
So I want to make a WeatherAction and when I say: “Tell me the current weather in London”, that he take the value “London” into the actions.py file.
You can use the get_latest_entity_values() method from the tracker to access the value(s) of a given entity from within your action’s run() method.
If you are using a spaCy pre-trained model, it handily pulls locations out into a GPE entity for you so you could do something like this…
class ActionWeather(Action):
def name(self):
return "action_weather"
def run(self, dispatcher, tracker, domain):
where = next(tracker.get_latest_entity_values('GPE'), None)
if where is not None:
dispatcher.utter_message("You asked about {}".format(where))
else:
dispatcher.utter_message("I couldn't tell where!")
return []
Ok, so that shows that the action server is working but you’ll need more training data to get the NLU reliably picking up the location entity. I suggest you add at least 20 more training examples and then re-train the NLU.
In your training data, you have called the entity “weather”, but the action.py code is expecting it to be called “GPE”. Just changing the run method in the action.py code to read…
where = next(tracker.get_latest_entity_values('weather'), None)
Personally, I find having the same name for the intent and the entity rather confusing. It’ is clearer if the entity is named after what it really represents. I think your training data is confusing as it is marking up the location (the city/place) and calling it “weather.”