hey @j.mosig what I mean when I am saying that the slots are being overwritten is that I have two numeric values in my form that is age and the salary. For both of these I have to just write their numerical values instead of giving values to bot like
Age 30
salary 50000
So the bot confuses these values and overwrites the value of age in salary even though it has been filled before
Ok, so because both age and salary are integers, both slots get mapped from the same entity. You can use a form validation action to fix this. In your validation action, you can check that age is some number below 200 and salary something above 10000. You can also check what the requested slot is and make sure age only gets filled when age is requested. Does this help?
@j.mosig I tried what you told me but the thing is I do not know we will write the story. I have edited the function for form validation action
class ValidateAgeForm(FormValidationAction):
def name(self) -> Text:
return "user_age_form"
@staticmethod
def age() -> List[Text]:
age = [age for age in range(19, 101)]
print(age)
return age
def validate_cuisine(
self,
slot_value: Any,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: DomainDict,
) -> Dict[Text, Any]:
"""Validate age value."""
print('Age validated')
if slot_value in self.age():
return {"age": slot_value}
else:
# validation failed, set this slot to None so that the
# user will be asked for the slot again
return {"age": None}
I think this function should verify that the age is between 18-100 but I don’t know how to write its story.
Also before the slot is validated it needs to has some input to be validated I guess? but as soon as I enter the salary the age slot gets overwritten.
@j.mosig so I have tried it and this works but the issue that I am now having is that when I enter salary even after validation it tries to overwrite the age but is unable to do so because of the validation check.
so to validate other slots do we have to make a separate class or if we do it in the same class? what will be the process.
I have even tried slot mappings and still it is not working.
Thank you so much for the help
class ValidateAgeForm(FormValidationAction):
def name(self) -> Text:
return "validate_user_details_form"
def slot_mappings(self) -> Dict[Text, Union[Dict, List[Dict]]]:
return {
"age": self.from_entity(entity="age", intent="age_english"),
"salary": self.from_entity(entity="salary", intent="salary_english")
}
def validate_age(
self,
slot_value: Any,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: DomainDict
) -> Dict[Text, Any]:
if int(slot_value) >= 18 and int(slot_value) <= 100:
print(slot_value)
return {"age": slot_value}
else:
dispatcher.utter_message('Age must be between 18 and 100')
return {"age": None}
def validate_salary(
self,
slot_value: Any,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: DomainDict
) -> Dict[Text, Any]:
print('Salary:', slot_value)
if len(slot_value) >= 4 and len(slot_value) <= 7:
print(slot_value)
return {"salary": slot_value}
else:
dispatcher.utter_message('Salary must be between 1000 and 1000000')
return {"salary": None}
No this does not resolves the issue.
I mean by that is slot validation is working fine but when I write the salary it still overwrites the age slot. Now in the age slot there is a validation check and due to that it throws the exception that age must be between 18 & 100. The issue is still there that the bot is getting confused between age and salary as both the values are integers i.e
age:18
salary:18000
@Juste I am having trouble with this.
I am thinking of a new approach where I make an intent inform and get my otp and account no in the same intent.
Will that somehow work?
@afnaan the run method has to return a list of events. Your function doesn’t return anything. You should have something like return [SlotSet("acc_num", your_value)] somewhere.