Everything in the below code works fine. For validation I am using a small database. Whenever the user provides something out of database, the slot is set to none. As mentioned below in the output if the user says ‘yess’ instead of ‘yes’(which is in database), then the slot is set to none. I would like to know if there is a way to use intents (from nlu.yml) (in this case, user_affirm and user_deny) to perform slot validation, so that I don’t have to expect a perfect match from database everytime. It would also be okay if this can be achieved by any other method. Thanks
nlu.yml
-
intent: user_affirm
examples: |
- yes
- yesss
- y
- yeah
- indeed
- right
- yup
- correct
-
intent: user_deny
examples: |
- no
- nooo
- nope
- nah
- n
- not
domain.yml
slots:
meal:
type: rasa.shared.core.slots.TextSlot
initial_value: null
auto_fill: true
influence_conversation: false
forms:
x_form:
required_slots:
meal:
- intent:
- user_affirm
- user_deny
type: from_text
actions.py
class Validate___(FVA):
-------------
-------------
@staticmethod
def meal_options_db1() -> List[Text]:
return ['yes', 'yeah', 'y', 'indeed', 'of course', 'that sounds good', 'right', 'yup', 'correct', ]
@staticmethod
def meal_options_db2() -> List[Text]:
return ['no', 'nope', 'nah', 'n', 'not', 'not so', 'never', 'don\'t think so', 'don\'t like that','no way',
'not really']
def validate_meal(
self,
slot_value: Text,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: DomainDict,
) -> Dict[Text, Any]:
if slot_value.lower() in self.meal_options_db1():
return {'meal': 'yes'}
elif slot_value.lower() in self.meal_options_db2():
return {'meal': 'no'}
dispatcher.utter_message(text='can you repeat it?')
return {'meal': None}
output 1
Bot: Did you have meal today?
User: yes
{‘meal’: ‘yes’}
output 2
Bot: Did you have meal today?
User: yess
{‘meal’: None}