Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validate user input in activation #6172

Merged
merged 5 commits into from
Jul 9, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions rasa/core/actions/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ def get_entity_value(
value = value[0]
return value

# noinspection PyUnusedLocal
def extract_other_slots(
self, tracker: DialogueStateTracker, domain: Domain
) -> Dict[Text, Any]:
Expand Down Expand Up @@ -240,7 +239,6 @@ def extract_other_slots(

return slot_values

# noinspection PyUnusedLocal
def extract_requested_slot(
self, tracker: "DialogueStateTracker", domain: Domain
) -> Dict[Text, Any]:
Expand Down Expand Up @@ -498,13 +496,16 @@ async def _validate_if_required(
- the form is called after `action_listen`
- form validation was not cancelled
"""
if tracker.latest_action_name == "action_listen" and tracker.active_loop.get(
"validate", True
):
logger.debug(f"Validating user input '{tracker.latest_message}'")
# no active_loop means that it is called during activation
Ghostvv marked this conversation as resolved.
Show resolved Hide resolved
need_validation = not tracker.active_loop or (
tracker.latest_action_name == "action_listen"
Ghostvv marked this conversation as resolved.
Show resolved Hide resolved
and tracker.active_loop.get("validate", True)
)
if need_validation:
logger.debug(f"Validating user input '{tracker.latest_message}'.")
return await self.validate(tracker, domain, output_channel, nlg)
else:
logger.debug("Skipping validation")
logger.debug("Skipping validation.")
return []

@staticmethod
Expand Down Expand Up @@ -536,6 +537,8 @@ async def activate(
Returns:
Events from the activation.
"""

logger.debug(f"Activated the form '{self.name()}'.")
# collect values of required slots filled before activation
prefilled_slots = {}

Expand Down
2 changes: 2 additions & 0 deletions rasa/core/actions/loops.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ async def run(
domain: "Domain",
) -> List[Event]:
events = []

if not await self.is_activated(output_channel, nlg, tracker, domain):
events += self._default_activation_events()
events += await self.activate(output_channel, nlg, tracker, domain)
Expand All @@ -43,6 +44,7 @@ async def is_activated(

# default implementation checks if form active
def _default_activation_events(self) -> List[Event]:
# TODO if this is in the loop action, probably it should not be `Form`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean we should rename the event?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, and also think whether we want to use the same event name for forms and loops. So we need to think through how they interact with each other. Let's tackle it separately. I added TODO so that we don't forget

return [Form(self.name())]

async def activate(
Expand Down