How to validate entities? - Getting Started with Rasa / Tutorials, Resources & Videos - Rasa Community Forum
How to validate entities?
Post by manoj_kumar on Aug 25, 2021
Hi,
I am trying to create a bot regarding weather. I have called weather API and going well. But I have doubts about how can we validate the “location” entity.
Example:
Bot: which location do you want to check for?
You: Mumbai
Bot: Haze in Mumbai and temperature is 27 degrees Celcius and Humidity 89%
And if give “12345” it should render “please enter the correct location”.
Bot: which location do you want to check for?
You: 123456
Bot: please enter the correct location
Post by nik202 on Aug 25, 2021
@manoj_kumar Hope you have seen this Forms?
Post by manoj_kumar on Aug 26, 2021
Yes @nik202, But I getting confused while implementing the validation.
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]]:
loc=tracker.get_slot('location')
temp = int(Weather(loc)['temp']-273)
hum = int(Weather(loc)['humidity'])
cond = Weather_Condition()[0]['description']
dispatcher.utter_message(template="utter_temp", LOC=loc, temp=temp, hum=hum, condition=cond)
return []
class ValidateWeatherForm(FormValidationAction):
def name(self) -> Text:
return "validate_weather_form"
def validate_location(
self,
slot_value: Text,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: DomainDict,
) ->Dict[Text, Any]:
if (str(slot_value.isalpha()))==False:
dispatcher.utter_message(template="utter_invalid")
return{"location": None}
else:
return {"location": slot_value}
Post by manoj_kumar on Aug 27, 2021
Hi @nik202,
Can I use spacy to validate the location name?
Post by nik202 on Aug 30, 2021
@manoj_kumar means ?