Reset slot after the forms complete - Getting Started with Rasa / Tutorials, Resources & Videos - Rasa Community Forum
Reset slot after the forms complete
post by Dinesh-gowdam-2610 on Oct 1, 2020
I have created a from using slots and actions. it is working with the form completion but after the form completion I don't know how to re active the form like the earlier one. stories:
happy path
- greet
- utter_greet
admission path
affirm
admission_form
form{“name”: “admission_form”}
form{“name”: null}
utter_slots_values
utter_ask_feedback
utter_ask_help
admission stop
- greet
- utter_greet
- affirm
- admission_form
- form{“name”: “admission_form”}
- out_of_scope
- utter_continue
- deny
- action_deactivate_form
- form{“name”: null}
- utter_goodbye
admission continue
- greet
- utter_greet
- affirm
- admission_form
- form{“name”: “admission_form”}
- out_of_scope
- utter_continue
- affirm
- admission_form
- form{“name”: null}
- utter_slots_values
- utter_ask_feedback
- utter_ask_help
Action.py
from typing import Any, Text, Dict, List,Union, Optional
from rasa_sdk import Action, Tracker
from rasa_sdk.executor import CollectingDispatcher
from rasa_sdk.forms import FormAction
from rasa_sdk.events import AllSlotsReset
from rasa_core.events import SlotSet
from rasa_core.events import Restarted
class ActionHelloWorld(FormAction):
def name(self) -> Text:
return "admission_form"
@staticmethod
def required_slots(tracker: Tracker) -> List[Text]:
return ["name", "ssn", "subject", "address"]
def slot_mappings(self) -> Dict[Text, Union[Dict, List[Dict]]]:
return {
"name": self.from_entity(entity = "name" , intent = "name_entry"),
"ssn": self.from_entity(entity = "ssn" , intent = "ssn_entry"),
"subject":self.from_entity(entity = "subject" , intent = "subject_entry"),
"address": [self.from_text()],
}
@staticmethod
def sub_db() -> List[Text]:
return [
"python",
"visual",
"java",
"c",
"core-java",
"software",
"data",
]
def validate_subject(
self,
value: Text,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]
) -> Dict[Text, Any]:
if value.lower() in self.sub_db():
return {"subject": value}
else:
dispatcher.utter_message(template="utter_wrong_subject")
return{"subject": None}
def validate_ssn(
self,
value: Text,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]
) -> Dict[Text, Any]:
if len(value) == 6:
return {"ssn": value}
else:
dispatcher.utter_message(template="utter_wrong_ssn")
return{"ssn": None}
def submit(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict]:
dispatcher.utter_message(template = "utter_submit", name = tracker.get_slot("name"), subject=tracker.get_slot("subject"),
address=tracker.get_slot("address"), ssn= tracker.get_slot("ssn"))
return []
entities:
- name
- ssn
- subject
- address forms:
- admission_form intents:
- greet
- goodbye
- admission_enqiry
- name_entry
- subject_entry
- ssn_entry
- help
- address
- out_of_scope
- deny
- affirm
actions:
- action_reset_all_slots
responses: utter_ask_address:
text: “{name}, Please Enter your Address” utter_ask_continue:
text: “Sorry, I don’t quite understand. Do you want to continue?” utter_ask_feedback:
text: “please give the feedback so far” utter_ask_help:
text: “Do you want anything else {name}?” utter_ask_name:
text: “Your name please?” utter_ask_ssn:
text: "{name} Please enter your ssn number " utter_ask_subject:
buttons:
payload: "/subject_entry{"subject":"python"}" title: python
payload: "/subject_entry{"subject":"visual"}" title: visual
payload: "/subject_entry{"subject":"core-java"}" title: core-java
payload: "/subject_entry{"subject":"c"}" title: c
payload: "/subject_entry{"subject":"java"}" title: java
payload: "/subject_entry{"subject":"software"}" title: software text: "hi {name}, Which subject you want to take?" utter_goodbye:
text: “Bye see you next time {name}” utter_greet:
text: |- welcome to Madras University Admission!! Are you coming for the Admission?? utter_help:
text: “Thanks for your admission we will get back to you soon {name}” utter_continue:
- text: “Sorry, I don’t quite understand. Do you want to continue?” utter_slots_values:
- text: |- I’m going to take your admission requests with these information:
- name : {name}
- ssn : {ssn}
- subject: {subject}
- address : {address} utter_submit:
- text: “All Done!!” utter_wrong_ssn:
- text: “SOCIAL SECURITY KEY MUST BE IN 6 DIGITS ONLY!!!” utter_wrong_subject:
- text: “THIS IS NOT AVAILABLE IN THE DATABASE!!! TRY SOME OTHER SUBJECT” utter_are_slots_ok:
- text: “Continue for the another admission_enqiry?”
slots: continue: type: unfeaturized auto_fill: false address: type: unfeaturized auto_fill: false help: type: unfeaturized auto_fill: false name: type: unfeaturized auto_fill: false ssn: type: unfeaturized auto_fill: false subject: type: unfeaturized auto_fill: false
session_config: carry_over_slots_to_new_session: true session_expiration_time: 60
Can you guys please help me at the situation, i want loop the story after complted the slots or reset the slots thank you in advance
post by UlisesVD on Oct 1, 2020
import this
from rasa_sdk.events import SlotSet
and it your submit return make this:
return [SlotSet("your_entiti_nae", None)]
post by Dinesh-gowdam-2610 on Oct 1, 2020
have to give one entity name is enough or should give all the name which i had given in the entities???
post by Dinesh-gowdam-2610 on Oct 2, 2020
how can I give multiple slotset values in action? single slotset is working fine. But i want to pass multiple. Thanks
post by UlisesVD on Oct 2, 2020
you need to put all in the list return [SlotSet("",""), SlotSet("","")] I think is the only way to do it
post by Dinesh-gowdam-2610 on Oct 2, 2020
But it is not restarts the forms its showing only what I typed before after the form completion. But I found the another way by creating the another action run and the return value given by return[AllSlotReset()] it will looping the forms again and again.
post by krkc on Aug 10, 2021
Hello @Dinesh-gowdam-2610
The same case with me.
But i have been fixed it by creating an extra python class for resetting the all slots immediate after successful submission of the form. And it works fine
class ActionResetAllSlots(Action):
def name(self):
return "action_reset_all_slots"
def run(self, dispatcher, tracker, domain):
return [AllSlotsReset()]
And I have been added it at the end of my form rule as below…
rules:
- rule: activate document search form
steps:
- intent: lookingfordocuments # intent that triggers form activation
- action: document_form # run the form
- active_loop: document_form # this form is active
- rule: submit form
condition:
- active_loop: document_form # this form must be active
steps:
- action: document_form # run the form
- active_loop: null # the form is no longer active because it has been filled
- slot_was_set:
- requested_slot: null # All the required slots have been filled
- action: action_submit
- action: action_reset_all_slots
Also, registered the action in my domain.yml. Thanks
Best Regards, Ravi