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

Cancel initiated slot correction - [ENG 414] #12718

Closed
wants to merge 7 commits into from
Closed
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
4 changes: 0 additions & 4 deletions rasa/core/policies/default_flows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ flows:
- id: "1"
action: utter_corrected_previous_input
- id: "2"
set_slots:
varunshankar marked this conversation as resolved.
Show resolved Hide resolved
- rasa_corrected_slots: None
next: "3"
- id: "3"
action: utter_not_corrected_previous_input

pattern_cancel_flow:
Expand Down
31 changes: 22 additions & 9 deletions rasa/core/policies/flow_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from rasa.shared.constants import FLOW_PREFIX
from rasa.shared.nlu.constants import (
ACTION_NAME,
INTENT_NAME_KEY,
)
from rasa.shared.core.constants import (
ACTION_LISTEN_NAME,
Expand Down Expand Up @@ -695,17 +696,29 @@ def _run_step(
and previous_flow_step
and current_frame.frame_type == StackFrameType.CORRECTION
):
# TODO: we need to figure out how to actually
# "undo" the changed slots
corrected_slots = tracker.get_slot(CORRECTED_SLOTS_SLOT)
if corrected_slots:
self._correct_flow_position(
corrected_slots, previous_flow_step, previous_flow, tracker
)
else:
# TODO: we need to figure out how to actually "undo" the
# changed slots
pass
if tracker.latest_message.intent[INTENT_NAME_KEY] == "affirm":
self._correct_flow_position(
corrected_slots,
previous_flow_step,
previous_flow,
tracker,
)
else:
for corrected_slot in corrected_slots:
found_first_event = False
for event in reversed(tracker.events):
if isinstance(event, SlotSet):
if event.key == corrected_slot:
if not found_first_event:
found_first_event = True
else:
events.append(
SlotSet(event.key, event.value)
)
break
events.append(SlotSet(CORRECTED_SLOTS_SLOT, None))
return ActionPrediction(None, 0.0, events=events)
else:
raise FlowException(f"Unknown flow step type {type(step)}")
Loading