I am using Rasa 2.x.
Let say I put a query:
I want to book appointment at 6:00 p.m
The bot will ask to fill slot hospital_name.:
Please enter the hospital name.
The user enters:
Unitd Hospital
The bot replies:
Sorry, this hospital does not exists. Please enter the correct hospital name.
Now, for the last reply. I don’t want to reply this way but want something like this:
Did you mean United Hospital?
User selects Yes.
I want to give this sort of suggestion to user to click and get results in case of misspelling in entity_name/slot_name.
Can you help me how to implement this feature?
You could do that as a validation action (example for Rasa 2):
from rasa_sdk import FormValidationAction
# You could define the possible values in the domain, or somewhere else
# possible_hospitals = ['united hospital', 'disunited clinic']
class ValidateHospitalName(FormValidationAction):
def name(self) -> Text:
return "validate_company_type"
def find_likeliest_choice(self, candidate, possible_choices, threshold=0.7):
# Write code to get some sort of similarity score between candidate
# each element of possible_choices, take the maximum score
# Perhaps use a minimum threshold as well
def validate_hospital_name(
self,
slot_value: Any,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: DomainDict,
) -> Dict[Text, Any]:
"""Validate hospital_name."""
possible_values = domain.slots['hospital_name']['values']
slot_value = slot_value.lower()
if slot_value in possible_values:
return {'hospital_name': slot_value}
likeliest = self.find_likeliest_choice(slot_value, possible_values)
# You could fill in the slot from likeliest, or perhaps fill in
# but add a check, maybe by implementing required_slots...
Thanks @E-dC
Do you also have a project or a video tutorial where something like this has been implemented? Little difficult to understand from here. But making some sense to me.