Hi everyone. I have some issue with my bot. When user is in a formAction with some required slots. In there i cannot restart bot with '/restart '. How do i restart bot anytime if i want. Thank you so much
The way I did it was to create a custom action action_reset_full
which resets all slots, restart the conversation and turns off any form.
from rasa_sdk import Action
from rasa_sdk.events import Form, AllSlotsReset, Restarted
class ActionResetFull(Action):
def name(self):
return "action_reset_full"
def run(self, dispatcher, tracker, domain):
dispatcher.utter_template("utter_reset_full", tracker)
return [Form(None), AllSlotsReset(None), Restarted(None)]
I also have an intent reset
that triggers this action so that you can just type âResetâ and the whole thing starts over. In our domain, it would look like (in the intents
section of domain.yml
):
- reset:
name: reset
triggers: action_reset_full
Hope that helps! Nicolas
Thank you so much for reply. I will try it
Youâre welcome! Let me know if that works or if you have any issue
Hi Nicolas, sorry for the late reply.
your code worked but some issues appeared
because when user is in a formAction (some slots are filled and some slots are not filled)
user cannot reset chatbot. All type of slot are unfeaturized and text.
How can i reset chatbot anytime
Thank you so much,
@vunt39 what happens when the user tries to reset the slots? How is the slot mapping of your forms?
For us, it usually works but we have some issues sometimes in forms (itâs quite erratic though).
here is the slot mapping
def slot_mappings(self) -> Dict[Text, Union[Dict, List[Dict]]]: return { # âcuisineâ: self.from_entity(entity=âcuisineâ, not_intent=âchitchatâ),
"lunch_time_string": [self.from_entity(entity="lunch_time_string"), self.from_text()],
"lunch_select_kitchen": [self.from_entity(entity="lunch_select_kitchen"), self.from_text()],
}
the slot mapping of my bot capture text message from user because there are many slot is number. for example lunch_number_slot is number, and lunch_number_people is a number too. so i cannot capture that slots in 1 or multiple intent. i capture that by self.from_text(). i think itâs the issue
this is an idea of mine about that in file actions.py
def validate_lunch_select_kitchen(
self,
value: Text,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any],
) -> Any:
print(value)
if(value == ârestartâ):
return [trackers(âaction_reset_fullâ)]
if vali.validate_kitchen(value):
value = vali.return_kitchen(value)
return {âlunch_select_kitchenâ: value}
else:
dispatcher.utter_template(âutter_wrong_lunch_select_kitchenâ,tracker)
return{âlunch_select_kitchenâ: None}
but it isnât work.
Two ideas:
- Do you have the
MappingPolicy
at the beginning of yourpolicies
in config.yml? Without it, the mapped triggers wonât work (and as far as I understand, this policy must be at the beginning of yourp policies) - In the slot_mapping, you can also explicitely ignore some intents.
self.from_text(not_intent=["reset"])
for example. That can also be achieved with stories I believe but itâs much more annoying to do.
On a side note regarding your numbers problem. We had a similar issue with number of bedrooms and number of bathrooms that could be specified in the same sentence. What I ended up doing was to create two entities bedrooms_count
and bathrooms_count
and added some training samples:
## intent:chose_apartment
- I need a [1](bedrooms_count) bed [2](bathrooms_count) bath apt
- Looking for a [one](bedrooms_count) bedroom flat
- ...
No idea if itâs best practice but that worked quite well with enough training samples as the CRFEntityExtractor
would recognize that the number is followed by a specific word. Then, in our validation functions, we matched the number extracted by Duckling and the one extracted by the bedrooms_count
/bathrooms_count
entities.
Hope that helps!
Hi nicolas. thank you for your reply. i think that knowledge help me very much. i will try it and then notify you about my result. thank you so much again
Very happy to help Let me know how it goes!
thank you nicolas thatâs advice really really helpful to me. itâs worked. thank you so much