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

Form switching #7771

Merged
merged 29 commits into from
Feb 8, 2021
Merged
Changes from 2 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
7de47da
Do the ActionExecutionRejection independent if user rejected manually
ArjaanBuijk Jan 21, 2021
ef115ed
Ignore REQUESTED_SLOT when switching to another form.
ArjaanBuijk Jan 21, 2021
3b27bcc
Correct fix for issue #7751 where rasa ass for slot upon form switch
ArjaanBuijk Jan 22, 2021
a48889b
When ActionExecutionRejected, the form no longer asks for the next slot
ArjaanBuijk Jan 22, 2021
8161219
Forms will only fill the requested slot if it is active
ArjaanBuijk Jan 22, 2021
1ee2ebd
Make it a protected method.
ArjaanBuijk Jan 26, 2021
24aff50
Update docstring
ArjaanBuijk Jan 26, 2021
322fe0b
Update docstring
ArjaanBuijk Jan 26, 2021
efcfcd7
Update docstring
ArjaanBuijk Jan 26, 2021
fc67440
Update docstring & use the protected method
ArjaanBuijk Jan 26, 2021
c9b91dd
Fix lint-docstrings
ArjaanBuijk Jan 27, 2021
b3fb312
Add test for switching forms when first slot is same in both forms
ArjaanBuijk Jan 27, 2021
3253ab0
Add changelogs
ArjaanBuijk Jan 27, 2021
c6370de
Merge branch 'main' into form-switching
ArjaanBuijk Jan 27, 2021
a5f767a
Merge branch 'main' into form-switching
ArjaanBuijk Jan 28, 2021
ec43b8d
Update rasa/core/actions/forms.py
ArjaanBuijk Feb 2, 2021
aa95b56
No need for async
ArjaanBuijk Feb 2, 2021
ae39b1e
no longer async
ArjaanBuijk Feb 2, 2021
ab5c9a9
Update tests/core/actions/test_forms.py
ArjaanBuijk Feb 2, 2021
dde0081
Update tests/core/actions/test_forms.py
ArjaanBuijk Feb 2, 2021
f34c2ce
Use full-blown docstring with Args & Returns for _user_rejected_manually
ArjaanBuijk Feb 2, 2021
dafda77
Merge remote-tracking branch 'origin/form-switching' into form-switching
ArjaanBuijk Feb 2, 2021
45577b9
No longer async
ArjaanBuijk Feb 2, 2021
cdefacb
Rename text_xa into utter_ask_form_x
ArjaanBuijk Feb 2, 2021
fda20b4
test_switch_forms_with_same_slot now uses MessageProcessor
ArjaanBuijk Feb 2, 2021
015e36a
Merge branch 'main' into form-switching
ArjaanBuijk Feb 2, 2021
d723704
Update switching forms test
ArjaanBuijk Feb 5, 2021
cade65a
Merge branch 'main' into form-switching
ArjaanBuijk Feb 5, 2021
1d292f4
Merge branch 'main' into form-switching
ArjaanBuijk Feb 8, 2021
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
34 changes: 20 additions & 14 deletions rasa/core/actions/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def extract_other_slots(
if they are set by corresponding entities from the user input
else return `None`.
"""
slot_to_fill = tracker.get_slot(REQUESTED_SLOT)
slot_to_fill = self.get_slot_to_fill(tracker)

entity_type_of_slot_to_fill = self._get_entity_type_of_slot_to_fill(
slot_to_fill, domain
Expand Down Expand Up @@ -317,13 +317,26 @@ def extract_other_slots(

return slot_values

def get_slot_to_fill(self, tracker: "DialogueStateTracker") -> Optional[str]:
"""Get the slot to be filled.
ArjaanBuijk marked this conversation as resolved.
Show resolved Hide resolved

When switching to another form, the requested slot setting is still from the
previous form and must be ignored.

Returns:
The slot name or None
ArjaanBuijk marked this conversation as resolved.
Show resolved Hide resolved
"""
return (
ArjaanBuijk marked this conversation as resolved.
Show resolved Hide resolved
tracker.get_slot(REQUESTED_SLOT)
if tracker.active_loop_name == self.name()
else None
)

def extract_requested_slot(
self, tracker: "DialogueStateTracker", domain: Domain
) -> Dict[Text, Any]:
"""Extract the value of requested slot from a user input
else return `None`.
"""
slot_to_fill = tracker.get_slot(REQUESTED_SLOT)
"""Extract the value of requested slot from a user input else return `None`."""
ArjaanBuijk marked this conversation as resolved.
Show resolved Hide resolved
slot_to_fill = self.get_slot_to_fill(tracker)
logger.debug(f"Trying to extract requested slot '{slot_to_fill}' ...")

# get mapping for requested slot
Expand Down Expand Up @@ -446,7 +459,7 @@ async def validate(
slot_values = self.extract_other_slots(tracker, domain)

# extract requested slot
slot_to_fill = tracker.get_slot(REQUESTED_SLOT)
slot_to_fill = self.get_slot_to_fill(tracker)
if slot_to_fill:
slot_values.update(self.extract_requested_slot(tracker, domain))

Expand All @@ -461,14 +474,7 @@ async def validate(
# to be filled by the user.
if isinstance(event, SlotSet) and not event.key == REQUESTED_SLOT
)
user_rejected_manually = any(
isinstance(event, ActionExecutionRejected) for event in validation_events
)
if (
slot_to_fill
and not some_slots_were_validated
and not user_rejected_manually
):
if slot_to_fill and not some_slots_were_validated:
# reject to execute the form action
# if some slot was requested but nothing was extracted
# it will allow other policies to predict another action
Expand Down