Hi.
I’m starting with rasa, for the moment, I want to make a telegram bot in which I can ask the pokedex number of a pokemon, and have it answer me.
The problem is that it only consults the pokemons that are defined in my nlu.yml, if I ask about another pokemon, it tells me that it could not find information about None. The request to the API is made but it passes None as a parameter, it is not capturing the entity correctly.
Would I have to define all the pokemons in the nlu.yml? I don’t think so, it wouldn’t be optimal at all. Can someone help me configure it so that it is whatever pokemon it is, the request to the API is made correctly?
This is my nlu.yml:
- intent: ask_pokedex_num
examples: |
- What pokedex number is [charizard](pokemon)
- I want to know [snorlax](pokemon)'s pokedex number
- Tell me [pikachu](pokemon)'s pokedex number'
- [ditto](pokemon)'s pokedex number'
actions.py:
class ActionGetPokedexNumber(Action):
def name(self):
return "action_get_pokedex_number"
def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
#pokemon = tracker.get_slot("pokemon")
pokemon = next(tracker.get_latest_entity_values("pokemon"), None)
api_url = f"https://pokeapi.co/api/v2/pokemon/{pokemon}"
response = requests.get(api_url)
if response.status_code == 200:
data = response.json()
pokedex_number = data.get("id")
response_message = f"{pokemon}'s pokedex number is {pokedex_number}."
else:
response_message = f"I couldn't find information about {pokemon} in the pokedex"
dispatcher.utter_message(response_message)
#return [SlotSet("pokemon", pokemon)]
return []
config.yml:
pipeline:
- name: WhitespaceTokenizer
- name: RegexFeaturizer
- name: LexicalSyntacticFeaturizer
- name: CountVectorsFeaturizer
- name: CountVectorsFeaturizer
analyzer: "char_wb"
min_ngram: 1
max_ngram: 4
- name: DIETClassifier
epochs: 200
Thanks.