I’m already tell the return with other slot is not works, also validate_confirm_patient_name is works, i just dont give you complete actions.py, here the full complete (and still cannot reset slot patient_name inside validate_confirm_patient_name
complete actions.py :
# This files contains your custom actions which can be used to run
# custom Python code.
#
# See this guide on how to implement these action:
# https://rasa.com/docs/rasa/custom-actions
# This is a simple example for a custom action which utters "Hello World!"
from typing import Any, Text, Dict, List, Optional
from rasa_sdk.events import SlotSet
from rasa_sdk import Action, Tracker
from rasa_sdk.executor import CollectingDispatcher
from rasa_sdk.forms import FormValidationAction
from rasa_sdk.events import EventType
from rasa_sdk.types import DomainDict
class ActionOutOfContext(Action):
def name(self) -> Text:
return "action_out_of_context"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
dispatcher.utter_message(text="Maaf, maksudnya apa ya?")
return []
class ActionCompleteAskVaccinationStatus(Action):
def name(self) -> Text:
return "action_complete_ask_vaccination_status"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
patient_name = tracker.get_slot('patient_name')
dispatcher.utter_message(text=f"{patient_name}, anda sudah divaksinasi, terima kasih")
return [SlotSet("patient_name",None)]
class AskForPatientName(Action):
def name(self) -> Text:
return "action_ask_patient_name"
def run(
self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict
) -> List[EventType]:
dispatcher.utter_message(text="Boleh tau nama lengkap anda? silakan ketik nama anda dibawah :")
return []
class AskPatientNameConfirmation(Action):
def name(self) -> Text:
return "action_ask_confirm_patient_name"
def run(
self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict
) -> List[EventType]:
patient_name = tracker.get_slot('patient_name')
dispatcher.utter_message(text=f"apakah benar nama anda adalah \"{patient_name}\"? ")
return []
class ValidateVaccinationForm(FormValidationAction):
def name(self) -> Text:
return "validate_vaccination_form"
async def required_slots(
self,
slots_mapped_in_domain: List[Text],
dispatcher: "CollectingDispatcher",
tracker: "Tracker",
domain: "DomainDict",
) -> Optional[List[Text]]:
additional_slots = ["confirm_patient_name"]
if tracker.slots.get("patient_name") is not None:
# jika nama pasien sudah terisi, konfirmasikan namanya bener apa nggak
return additional_slots + slots_mapped_in_domain
else:
return slots_mapped_in_domain
async def extract_confirm_patient_name(
self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict
) -> Dict[Text, Any]:
user_input = tracker.latest_message.get("text")
return {"confirm_patient_name": user_input}
def validate_patient_name(
self,
slot_value: Any,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: DomainDict,
) -> Dict[Text, Any]:
if tracker.get_intent_of_latest_message() != "out_of_context":
if len(slot_value) > 1:
return {"patient_name":slot_value}
else:
dispatcher.utter_message(text=f"Maaf, nama: \"{slot_value}\" terlalu pendek, minimal 2 huruf")
return {"patient_name":None}
else:
dispatcher.utter_message(text=f"Maaf, kami tidak mengerti maksud anda")
return {"patient_name":None}
def validate_confirm_patient_name(
self,
slot_value: Any,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: DomainDict,
) -> Dict[Text, Any]:
if slot_value == "ya":
'''dispatcher.utter_message(text=f"user confirm YA")'''
return {"confirm_patient_name":True}
else:
'''dispatcher.utter_message(text=f"user confirm TIDAK")'''
return {"confirm_patient_name":None,"patient_name":None}
here the some debug :
Your input -> n
2021-11-23 06:31:08 DEBUG rasa.core.lock_store - Issuing ticket for conversation 'e4a3c57b9f7041d988b0c6ac3c58ac0e'.
2021-11-23 06:31:08 DEBUG rasa.core.lock_store - Acquiring lock for conversation 'e4a3c57b9f7041d988b0c6ac3c58ac0e'.
2021-11-23 06:31:08 DEBUG rasa.core.lock_store - Acquired lock for conversation 'e4a3c57b9f7041d988b0c6ac3c58ac0e'.
2021-11-23 06:31:08 DEBUG rasa.core.tracker_store - Recreating tracker for id 'e4a3c57b9f7041d988b0c6ac3c58ac0e'
2021-11-23 06:31:08 DEBUG rasa.nlu.classifiers.diet_classifier - There is no trained model for 'ResponseSelector': The component is either not trained or didn't receive enough training data.
2021-11-23 06:31:08 DEBUG rasa.nlu.selectors.response_selector - Adding following selector key to message property: default
2021-11-23 06:31:08 DEBUG rasa.core.processor - Received user message 'n' with intent '{'id': 6057978783892506229, 'name': 'affirm', 'confidence': 0.9353043437004089}' and entities '[]'
2021-11-23 06:31:08 DEBUG rasa.core.processor - Logged UserUtterance - tracker now has 61 events.
2021-11-23 06:31:08 DEBUG rasa.core.policies.rule_policy - Current tracker state:
[state 1] user intent: ask_status_vaccination | previous action name: action_listen
[state 2] user intent: ask_status_vaccination | previous action name: vaccination_form | active loop: {'name': 'vaccination_form'}
[state 3] user text: n | previous action name: action_listen | active loop: {'name': 'vaccination_form'}
2021-11-23 06:31:08 DEBUG rasa.core.policies.rule_policy - There is no applicable rule.
2021-11-23 06:31:08 DEBUG rasa.core.policies.rule_policy - Predicted loop 'vaccination_form'.
2021-11-23 06:31:08 DEBUG rasa.core.policies.ensemble - Made prediction using user intent.
2021-11-23 06:31:08 DEBUG rasa.core.policies.ensemble - Added `DefinePrevUserUtteredFeaturization(False)` event.
2021-11-23 06:31:08 DEBUG rasa.core.policies.ensemble - Predicted next action using policy_0_RulePolicy.
2021-11-23 06:31:08 DEBUG rasa.core.processor - Predicted next action 'vaccination_form' with confidence 1.00.
2021-11-23 06:31:08 DEBUG rasa.core.actions.forms - Validating user input 'UserUttered(text: n, intent: affirm, use_text_for_featurization: False)'.
2021-11-23 06:31:08 DEBUG rasa.core.actions.forms - Trying to extract requested slot 'confirm_patient_name' ...
2021-11-23 06:31:08 DEBUG rasa.core.actions.forms - Got mapping '{'type': 'from_entity', 'entity': 'confirm_patient_name', 'intent': [], 'not_intent': [], 'role': None, 'group': None}'
2021-11-23 06:31:08 DEBUG rasa.core.actions.forms - Failed to extract requested slot 'confirm_patient_name'
2021-11-23 06:31:08 DEBUG rasa.core.actions.forms - Validating extracted slots: {}
2021-11-23 06:31:08 DEBUG rasa.core.actions.action - Calling action endpoint to run action 'validate_vaccination_form'.
2021-11-23 06:31:08 DEBUG rasa.core.actions.forms - Request next slot 'confirm_patient_name'
2021-11-23 06:31:08 DEBUG rasa.core.actions.action - Calling action endpoint to run action 'action_ask_confirm_patient_name'.
2021-11-23 06:31:08 DEBUG rasa.core.processor - Policy prediction ended with events '[<rasa.shared.core.events.DefinePrevUserUtteredFeaturization object at 0x7fdbce631580>]'.
2021-11-23 06:31:08 DEBUG rasa.core.processor - Action 'vaccination_form' ended with events '[<rasa.shared.core.events.SlotSet object at 0x7fdbce588460>, <rasa.shared.core.events.SlotSet object at 0x7fdbce60f7c0>, BotUttered('apakah benar nama anda adalah "Wira"? ', {"elements": null, "quick_replies": null, "buttons": null, "attachment": null, "image": null, "custom": null}, {}, 1637649068.390572)]'.
2021-11-23 06:31:08 DEBUG rasa.core.processor - Current slot values:
patient_name: Wira
confirm_patient_name: None
requested_slot: confirm_patient_name
session_started_metadata: None
2021-11-23 06:31:08 DEBUG rasa.core.policies.rule_policy - Predicted 'action_listen' after loop 'vaccination_form'.
2021-11-23 06:31:08 DEBUG rasa.core.policies.ensemble - Predicted next action using policy_0_RulePolicy.
2021-11-23 06:31:08 DEBUG rasa.core.processor - Predicted next action 'action_listen' with confidence 1.00.
2021-11-23 06:31:08 DEBUG rasa.core.processor - Policy prediction ended with events '[]'.
2021-11-23 06:31:08 DEBUG rasa.core.processor - Action 'action_listen' ended with events '[]'.
2021-11-23 06:31:08 DEBUG rasa.core.lock_store - Deleted lock for conversation 'e4a3c57b9f7041d988b0c6ac3c58ac0e'.
apakah benar nama anda adalah "Wira"?
Your input -> n
2021-11-23 06:31:09 DEBUG rasa.core.lock_store - Issuing ticket for conversation 'e4a3c57b9f7041d988b0c6ac3c58ac0e'.
2021-11-23 06:31:09 DEBUG rasa.core.lock_store - Acquiring lock for conversation 'e4a3c57b9f7041d988b0c6ac3c58ac0e'.
2021-11-23 06:31:09 DEBUG rasa.core.lock_store - Acquired lock for conversation 'e4a3c57b9f7041d988b0c6ac3c58ac0e'.
2021-11-23 06:31:09 DEBUG rasa.core.tracker_store - Recreating tracker for id 'e4a3c57b9f7041d988b0c6ac3c58ac0e'
2021-11-23 06:31:09 DEBUG rasa.nlu.classifiers.diet_classifier - There is no trained model for 'ResponseSelector': The component is either not trained or didn't receive enough training data.
2021-11-23 06:31:09 DEBUG rasa.nlu.selectors.response_selector - Adding following selector key to message property: default
2021-11-23 06:31:09 DEBUG rasa.core.processor - Received user message 'n' with intent '{'id': 6057978783892506229, 'name': 'affirm', 'confidence': 0.9353043437004089}' and entities '[]'
2021-11-23 06:31:09 DEBUG rasa.core.processor - Logged UserUtterance - tracker now has 68 events.
2021-11-23 06:31:09 DEBUG rasa.core.policies.rule_policy - Current tracker state:
[state 1] user intent: ask_status_vaccination | previous action name: action_listen
[state 2] user intent: ask_status_vaccination | previous action name: vaccination_form | active loop: {'name': 'vaccination_form'}
[state 3] user text: n | previous action name: action_listen | active loop: {'name': 'vaccination_form'}
2021-11-23 06:31:09 DEBUG rasa.core.policies.rule_policy - There is no applicable rule.
2021-11-23 06:31:09 DEBUG rasa.core.policies.rule_policy - Predicted loop 'vaccination_form'.
2021-11-23 06:31:09 DEBUG rasa.core.policies.ensemble - Made prediction using user intent.
2021-11-23 06:31:09 DEBUG rasa.core.policies.ensemble - Added `DefinePrevUserUtteredFeaturization(False)` event.
2021-11-23 06:31:09 DEBUG rasa.core.policies.ensemble - Predicted next action using policy_0_RulePolicy.
2021-11-23 06:31:09 DEBUG rasa.core.processor - Predicted next action 'vaccination_form' with confidence 1.00.
2021-11-23 06:31:09 DEBUG rasa.core.actions.forms - Validating user input 'UserUttered(text: n, intent: affirm, use_text_for_featurization: False)'.
2021-11-23 06:31:09 DEBUG rasa.core.actions.forms - Trying to extract requested slot 'confirm_patient_name' ...
2021-11-23 06:31:09 DEBUG rasa.core.actions.forms - Got mapping '{'type': 'from_entity', 'entity': 'confirm_patient_name', 'intent': [], 'not_intent': [], 'role': None, 'group': None}'
2021-11-23 06:31:09 DEBUG rasa.core.actions.forms - Failed to extract requested slot 'confirm_patient_name'
2021-11-23 06:31:09 DEBUG rasa.core.actions.forms - Validating extracted slots: {}
2021-11-23 06:31:09 DEBUG rasa.core.actions.action - Calling action endpoint to run action 'validate_vaccination_form'.
2021-11-23 06:31:09 DEBUG rasa.core.actions.forms - Request next slot 'confirm_patient_name'
2021-11-23 06:31:09 DEBUG rasa.core.actions.action - Calling action endpoint to run action 'action_ask_confirm_patient_name'.
2021-11-23 06:31:09 DEBUG rasa.core.processor - Policy prediction ended with events '[<rasa.shared.core.events.DefinePrevUserUtteredFeaturization object at 0x7fdbce4437f0>]'.
2021-11-23 06:31:09 DEBUG rasa.core.processor - Action 'vaccination_form' ended with events '[<rasa.shared.core.events.SlotSet object at 0x7fdbce613520>, <rasa.shared.core.events.SlotSet object at 0x7fdbce460a90>, BotUttered('apakah benar nama anda adalah "Wira"? ', {"elements": null, "quick_replies": null, "buttons": null, "attachment": null, "image": null, "custom": null}, {}, 1637649069.103176)]'.
2021-11-23 06:31:09 DEBUG rasa.core.processor - Current slot values:
patient_name: Wira
confirm_patient_name: None
requested_slot: confirm_patient_name
session_started_metadata: None
2021-11-23 06:31:09 DEBUG rasa.core.policies.rule_policy - Predicted 'action_listen' after loop 'vaccination_form'.
2021-11-23 06:31:09 DEBUG rasa.core.policies.ensemble - Predicted next action using policy_0_RulePolicy.
2021-11-23 06:31:09 DEBUG rasa.core.processor - Predicted next action 'action_listen' with confidence 1.00.
2021-11-23 06:31:09 DEBUG rasa.core.processor - Policy prediction ended with events '[]'.
2021-11-23 06:31:09 DEBUG rasa.core.processor - Action 'action_listen' ended with events '[]'.
2021-11-23 06:31:09 DEBUG rasa.core.lock_store - Deleted lock for conversation 'e4a3c57b9f7041d988b0c6ac3c58ac0e'.
apakah benar nama anda adalah "Wira"?
Your input -> n
2021-11-23 06:31:09 DEBUG rasa.core.lock_store - Issuing ticket for conversation 'e4a3c57b9f7041d988b0c6ac3c58ac0e'.
2021-11-23 06:31:09 DEBUG rasa.core.lock_store - Acquiring lock for conversation 'e4a3c57b9f7041d988b0c6ac3c58ac0e'.
2021-11-23 06:31:09 DEBUG rasa.core.lock_store - Acquired lock for conversation 'e4a3c57b9f7041d988b0c6ac3c58ac0e'.
2021-11-23 06:31:09 DEBUG rasa.core.tracker_store - Recreating tracker for id 'e4a3c57b9f7041d988b0c6ac3c58ac0e'
2021-11-23 06:31:09 DEBUG rasa.nlu.classifiers.diet_classifier - There is no trained model for 'ResponseSelector': The component is either not trained or didn't receive enough training data.
2021-11-23 06:31:09 DEBUG rasa.nlu.selectors.response_selector - Adding following selector key to message property: default
2021-11-23 06:31:09 DEBUG rasa.core.processor - Received user message 'n' with intent '{'id': 6057978783892506229, 'name': 'affirm', 'confidence': 0.9353043437004089}' and entities '[]'
2021-11-23 06:31:09 DEBUG rasa.core.processor - Logged UserUtterance - tracker now has 75 events.
2021-11-23 06:31:09 DEBUG rasa.core.policies.rule_policy - Current tracker state:
[state 1] user intent: ask_status_vaccination | previous action name: action_listen
[state 2] user intent: ask_status_vaccination | previous action name: vaccination_form | active loop: {'name': 'vaccination_form'}
[state 3] user text: n | previous action name: action_listen | active loop: {'name': 'vaccination_form'}
2021-11-23 06:31:09 DEBUG rasa.core.policies.rule_policy - There is no applicable rule.
2021-11-23 06:31:09 DEBUG rasa.core.policies.rule_policy - Predicted loop 'vaccination_form'.
2021-11-23 06:31:09 DEBUG rasa.core.policies.ensemble - Made prediction using user intent.
2021-11-23 06:31:09 DEBUG rasa.core.policies.ensemble - Added `DefinePrevUserUtteredFeaturization(False)` event.
2021-11-23 06:31:09 DEBUG rasa.core.policies.ensemble - Predicted next action using policy_0_RulePolicy.
2021-11-23 06:31:09 DEBUG rasa.core.processor - Predicted next action 'vaccination_form' with confidence 1.00.
2021-11-23 06:31:09 DEBUG rasa.core.actions.forms - Validating user input 'UserUttered(text: n, intent: affirm, use_text_for_featurization: False)'.
2021-11-23 06:31:09 DEBUG rasa.core.actions.forms - Trying to extract requested slot 'confirm_patient_name' ...
2021-11-23 06:31:09 DEBUG rasa.core.actions.forms - Got mapping '{'type': 'from_entity', 'entity': 'confirm_patient_name', 'intent': [], 'not_intent': [], 'role': None, 'group': None}'
2021-11-23 06:31:09 DEBUG rasa.core.actions.forms - Failed to extract requested slot 'confirm_patient_name'
2021-11-23 06:31:09 DEBUG rasa.core.actions.forms - Validating extracted slots: {}
2021-11-23 06:31:09 DEBUG rasa.core.actions.action - Calling action endpoint to run action 'validate_vaccination_form'.
2021-11-23 06:31:09 DEBUG rasa.core.actions.forms - Request next slot 'confirm_patient_name'
2021-11-23 06:31:09 DEBUG rasa.core.actions.action - Calling action endpoint to run action 'action_ask_confirm_patient_name'.
2021-11-23 06:31:09 DEBUG rasa.core.processor - Policy prediction ended with events '[<rasa.shared.core.events.DefinePrevUserUtteredFeaturization object at 0x7fdbce6312e0>]'.
2021-11-23 06:31:09 DEBUG rasa.core.processor - Action 'vaccination_form' ended with events '[<rasa.shared.core.events.SlotSet object at 0x7fdbce33ad90>, <rasa.shared.core.events.SlotSet object at 0x7fdbce33ac10>, BotUttered('apakah benar nama anda adalah "Wira"? ', {"elements": null, "quick_replies": null, "buttons": null, "attachment": null, "image": null, "custom": null}, {}, 1637649069.8484604)]'.
2021-11-23 06:31:09 DEBUG rasa.core.processor - Current slot values:
patient_name: Wira
confirm_patient_name: None
requested_slot: confirm_patient_name
session_started_metadata: None
2021-11-23 06:31:09 DEBUG rasa.core.policies.rule_policy - Predicted 'action_listen' after loop 'vaccination_form'.
2021-11-23 06:31:09 DEBUG rasa.core.policies.ensemble - Predicted next action using policy_0_RulePolicy.
2021-11-23 06:31:09 DEBUG rasa.core.processor - Predicted next action 'action_listen' with confidence 1.00.
2021-11-23 06:31:09 DEBUG rasa.core.processor - Policy prediction ended with events '[]'.
2021-11-23 06:31:09 DEBUG rasa.core.processor - Action 'action_listen' ended with events '[]'.
2021-11-23 06:31:09 DEBUG rasa.core.lock_store - Deleted lock for conversation 'e4a3c57b9f7041d988b0c6ac3c58ac0e'.
apakah benar nama anda adalah "Wira"?
Your input ->