Hi @abhi_bh_nlp , is “application” also the name of a slot in your form? Have you checked that _validat_application is being called as expected (you could add a print statement for this)?
You are returning a list, but the validate methods expect you to return a dictionary.
Please try this:
return { “requested_slot”: None}
The reason you have to return a dictionary like this is just by convention.
The method of the rasa_sdk that calls your validate method just expect you to return a dictionary. It will convert this dictionary into a list of SlotSet events that are send back to rasa open source.
I had tried returning a dictionary earlier, but the action server throws an error. Error:
File "/Users/riya/repo/form_bot/venv/lib/python3.8/site-packages/rasa_sdk/interfaces.py", line 271, in add_slots
if not event.get("event") == "slot":
AttributeError: 'str' object has no attribute 'get'
This is my validate method:
async def validate(
self,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any],
) -> Dict[Text, Any]:
current_answer_slot = tracker.get_slot("requested_slot")
print(f"Current answer slot in validate: {current_answer_slot}")
answer_generic_slot = tracker.get_slot("answer")
print(f"Answer generic slot in validate: {answer_generic_slot}")
if answer_generic_slot is None:
answer_generic_slot = {}
if current_answer_slot is None:
return []
# QUESTIONS is a dictionary
slot_details = QUESTIONS.get(current_answer_slot, None)
if slot_details is not None:
possible_intents_list = slot_details.get("possible_intents", None)
latest_intent = tracker.latest_message.get("intent", {}).get("name", "")
confidence = tracker.latest_message.get("intent", {}).get("confidence", 0)
if latest_intent in possible_intents_list:
print(
f"Latest intent present in possible intents list: latest intent '{latest_intent}', confidence '{confidence}' "
)
return {"requested_slots": None}
else:
print(
f"Latest intent not present in possible intents list. Setting slot..."
)
answer_generic_slot[current_answer_slot] = tracker.latest_message.get("text")
return {"answer": answer_generic_slot, "rephrase": True}
Basically, I want to switch to another form (context switching) if the latest intent is from one of the intents listed in the QUESTIONS dictionary. To achieve that, I want to switch the control to stories by deactivating the form in validate method.
Can you show the full trace, so it is more clear what return statement in your validate is causing the error? Maybe also put some print statements right before each possible return from your code.
Oh, my bad.
Figured out that the issue was with the way I had return stories. It’s fixed, and now it’s working fine, even with a list of SlotSet events as a return type.
Thanks a ton for the prompt reply.
Hi , Once I return { “requested_slot”: None}, Bot will ask if you want to continue with two options . If user click yes → It will run a custom action to reset slots and go back to main menu.
But if user wants to continue how to get back form to previous state all the slots as I have set { “requested_slot”: None}