Hello! I’m new to programming and I’m trying to make a simple bot where I just need it to check the “year” and return the information regarding it.
The problem is that my slot is not receiving the information “2022 or 2023”. Can you help me?
DOMAIN
version: “3.1”
slots: ano: type: text mappings: - type: custom
entities:
- ano
regex: ano: ^(19[5-9]\d|20[0-4]\d|2050)$
intents:
- greet
- goodbye
- affirm
- deny
- mood_great
- mood_unhappy
- bot_challenge
- pergunta_campeonato
responses: utter_greet:
- text: Olá! Como posso ajudar?
utter_cheer_up:
- text: “Here is something to cheer you up:” image: “https://i.imgur.com/nGF1K8f.jpg”
utter_did_that_help:
- text: “Did that help you?”
utter_happy:
- text: “Great, carry on!”
utter_goodbye:
- text: Até mais!
utter_iamabot:
- text: “Sim, eu sou uma IA!”
utter_default: - text: “Desculpe, não entendi. Poderia reformular a pergunta?”
actions:
- utter_default
- action_responder_campeonato
- action_show_slots
session_config: session_expiration_time: 60 carry_over_slots_to_new_session: true
STORIES
version: “3.1”
stories:
-
story: happy path steps:
- intent: greet
- action: utter_greet
- intent: mood_great
- action: utter_happy
-
story: sad path 1 steps:
- intent: greet
- action: utter_greet
- intent: mood_unhappy
- action: utter_cheer_up
- action: utter_did_that_help
- intent: affirm
- action: utter_happy
-
story: sad path 2 steps:
- intent: greet
- action: utter_greet
- intent: mood_unhappy
- action: utter_cheer_up
- action: utter_did_that_help
- intent: deny
- action: utter_goodbye
-
story: pergunta sobre o campeonato steps:
- intent: pergunta_campeonato
- slot_was_set:
- ano: 2022
- action: action_responder_campeonato
-
story: pergunta sobre o campeonato steps:
- intent: pergunta_campeonato
- slot_was_set:
- ano: 2023
- action: action_responder_campeonato
NLU
version: “3.1” nlu:
-
intent: greet examples: |
- oi
- ola
- hi
- hello
- oioi
- ooi
- ola!
- Olá!
- Oi
-
intent: goodbye examples: |
- até mais!
- tchau
- adeus!
- tchau tchau
- bye
- até
-
intent: affirm examples: |
- yes
- sim
- correct
-
intent: deny examples: |
- no
- não
- n
-
intent: mood_great examples: |
- perfect
- great
- amazing
- feeling like a king
- wonderful
- I am feeling very good
-
intent: mood_unhappy examples: |
- my day was horrible
- I am sad
- I don’t feel very well
- I am disappointed
-
intent: bot_challenge examples: |
- are you a bot?
- are you a human?
- am I talking to a bot?
- am I talking to a human?
-
intent: pergunta_campeonato examples: |
- Quais clubes jogaram o campeonato de [2022] (ano)?
- Times que jogaram o campeonato de [2023] (ano)?
- Quais times participaram do campeonato de [2022] (ano)?
- Quais times jogaram em [2022] (ano)?
- Quais clubes jogaram o campeonato de [2023] (ano)?
- Times que jogaram o campeonato de [2023] (ano)?
- Quais times participaram do campeonato de [2023] (ano)?
- Quais times jogaram em [2022] (ano)?
- Qual time jogou em [2022] (ano)?
ACTIONS
from typing import Dict, Text, Any, List, Union from rasa_sdk import Action, Tracker from rasa_sdk.events import SlotSet from rasa_sdk.executor import CollectingDispatcher
class ActionResponderCampeonato(Action): def name(self) → Text: return “action_responder_campeonato”
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
ano = tracker.get_slot("ano")
print(f"Ano capturado: {ano}")
# Aqui você pode adicionar as condições para responder à pergunta com base no ano
if ano == "2022":
response = "Estes são os times que jogaram o campeonato de 2022: time A, time B, time C"
elif ano == "2023":
response = "Estes são os times que jogaram o campeonato de 2023: time X, time Y, time Z"
else:
response = "Desculpe, não tenho informações sobre esse ano"
dispatcher.utter_message(text=response)
return []
class ActionShowSlots(Action): def name(self): return “action_show_slots”
def run(self, dispatcher, tracker, domain):
for key, value in tracker.slots.items():
dispatcher.utter_message(f"{key}: {value}")