Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
varunshankar committed Jun 20, 2023
1 parent 7bf8884 commit 2ebd0e2
Show file tree
Hide file tree
Showing 3 changed files with 228 additions and 11 deletions.
176 changes: 176 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions rasa/core/policies/default_flows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ responses:
- text: "Ok, I did not correct the previous input."
metadata:
rephrase: True

utter_flow_continue_sequence:
- text: Let's proceed to the next topic.

slots:
confirm_correction:
Expand Down Expand Up @@ -65,4 +68,11 @@ flows:
next: "3"
- id: "3"
action: utter_not_corrected_previous_input

pattern_continue_sequence:
description: A meta flow that should be started to continue to the flow in sequence.

steps:
- id: "0"
action: utter_flow_continue_sequence

53 changes: 42 additions & 11 deletions rasa/core/policies/flow_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ def handle_multi_intent_message(tracker, domain, flows, multi_intent):
tracker, flows or FlowsList([]), domain
)
structlogger.debug(vars(executor.flow_stack))
stack_update = False
current_flow = None
for intent in multi_intent:
structlogger.debug(intent)
for flow in executor.all_flows.underlying_flows:
Expand All @@ -205,18 +207,20 @@ def handle_multi_intent_message(tracker, domain, flows, multi_intent):

if first_step.is_triggered(intent, []):
structlogger.debug("IN STACK PUSH")
executor.flow_stack.push(
FlowStackFrame(
flow_id=flow.id,
step_id=START_STEP,
frame_type=StackFrameType.REGULAR,
if not stack_update:
executor.flow_stack.push(
FlowStackFrame(
flow_id=flow.id,
step_id=START_STEP,
frame_type=StackFrameType.SEQUENCE,
)
)
)
stack_update = True
else:
current_flow = flow.id
break
structlogger.debug(vars(executor.flow_stack))
prediction = ActionPrediction(
FLOW_PREFIX + executor.flow_stack.top().flow_id, 1.0
)
prediction = ActionPrediction(FLOW_PREFIX + current_flow, 1.0)
if not prediction.events:
prediction.events = []
prediction.events.append(
Expand Down Expand Up @@ -438,7 +442,6 @@ class StackFrameType(str, Enum):
LINK = "link"
"""The frame is a link frame.
This means that the previous flow linked to this flow."""
RESUME = "resume"
"""The frame is a resume frame.
Expand All @@ -450,8 +453,13 @@ class StackFrameType(str, Enum):
This means that the previous flow was corrected by this flow."""
REGULAR = "regular"
"""The frame is a regular frame.
In all other cases, this is the case."""
SEQUENCE = "sequence"
"""The frame is a sequence frame.
This frame was created together with another frame, that
needs to be executed in sequence."""

@staticmethod
def from_str(typ: Optional[Text]) -> "StackFrameType":
Expand All @@ -468,6 +476,8 @@ def from_str(typ: Optional[Text]) -> "StackFrameType":
return StackFrameType.RESUME
elif typ == StackFrameType.CORRECTION.value:
return StackFrameType.CORRECTION
elif typ == StackFrameType.SEQUENCE.value:
return StackFrameType.SEQUENCE
else:
raise NotImplementedError

Expand Down Expand Up @@ -1013,6 +1023,7 @@ def _run_step(
if current_frame := self.flow_stack.pop():
previous_flow = self.flow_stack.top_flow(self.all_flows)
previous_flow_step = self.flow_stack.top_flow_step(self.all_flows)
prev_frame = self.flow_stack.top()
if current_frame.frame_type == StackFrameType.INTERRUPT:
# get stack frame that is below the current one and which will
# be continued now that this one has ended.
Expand Down Expand Up @@ -1040,6 +1051,26 @@ def _run_step(
self._correct_flow_position(
corrected_slots, previous_flow_step, previous_flow, tracker
)
elif prev_frame.frame_type == StackFrameType.SEQUENCE:
structlogger.debug("HERE", "CHECKING")
structlogger.debug("flow.test", vars(self.flow_stack.top()))
previous_flow_name = (
previous_flow.name or previous_flow.id
if previous_flow
else None
)

return ActionPrediction(
FLOW_PREFIX + "pattern_continue_sequence",
1.0,
metadata={"slots": {PREVIOUS_FLOW_SLOT: previous_flow_name}},
events=events,
)

structlogger.debug("flow.current_frame", vars(current_frame))
structlogger.debug("flow.previous_flow", vars(previous_flow))
structlogger.debug("flow.previous_flow_step", vars(previous_flow_step))

return ActionPrediction(None, 0.0, events=events)
else:
raise FlowException(f"Unknown flow step type {type(step)}")

0 comments on commit 2ebd0e2

Please sign in to comment.