Skip to content

Commit

Permalink
Improved typing, naming and docs for flow step links
Browse files Browse the repository at this point in the history
  • Loading branch information
twerkmeister committed Oct 26, 2023
1 parent 32b8d72 commit 3d4459e
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 120 deletions.
12 changes: 6 additions & 6 deletions rasa/core/policies/flow_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@
FlowStep,
)
from rasa.shared.core.flows.flow_step_links import (
IfFlowLink,
ElseFlowLink,
StaticFlowLink,
IfFlowStepLink,
ElseFlowStepLink,
StaticFlowStepLink,
)
from rasa.shared.core.flows.steps.constants import END_STEP
from rasa.shared.core.flows.steps.continuation import ContinueFlowStep
Expand Down Expand Up @@ -370,18 +370,18 @@ def _select_next_step_id(
) -> Optional[Text]:
"""Selects the next step id based on the current step."""
next = current.next
if len(next.links) == 1 and isinstance(next.links[0], StaticFlowLink):
if len(next.links) == 1 and isinstance(next.links[0], StaticFlowStepLink):
return next.links[0].target

# evaluate if conditions
for link in next.links:
if isinstance(link, IfFlowLink) and link.condition:
if isinstance(link, IfFlowStepLink) and link.condition:
if self.is_condition_satisfied(link.condition, tracker):
return link.target

# evaluate else condition
for link in next.links:
if isinstance(link, ElseFlowLink):
if isinstance(link, ElseFlowStepLink):
return link.target

if next.links:
Expand Down
6 changes: 3 additions & 3 deletions rasa/shared/core/flows/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from rasa.shared.core.flows.flow_step import (
FlowStep,
)
from rasa.shared.core.flows.flow_step_links import StaticFlowLink
from rasa.shared.core.flows.flow_step_links import StaticFlowStepLink
from rasa.shared.core.flows.steps.continuation import ContinueFlowStep
from rasa.shared.core.flows.steps.constants import (
CONTINUE_STEP_PREFIX,
Expand Down Expand Up @@ -89,9 +89,9 @@ def resolve_default_next(steps: List[FlowStep], is_root_sequence: bool) -> None:
# if this is the root sequence, we need to add an end step
# to the end of the sequence. other sequences, e.g.
# in branches need to explicitly add a next step.
step.next.links.append(StaticFlowLink(END_STEP))
step.next.links.append(StaticFlowStepLink(END_STEP))
else:
step.next.links.append(StaticFlowLink(steps[i + 1].id))
step.next.links.append(StaticFlowStepLink(steps[i + 1].id))
for link in step.next.links:
if sub_steps := link.child_steps():
resolve_default_next(sub_steps, is_root_sequence=False)
Expand Down
8 changes: 4 additions & 4 deletions rasa/shared/core/flows/flow_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import structlog

if TYPE_CHECKING:
from rasa.shared.core.flows.flow_step_links import FlowLinks
from rasa.shared.core.flows.flow_step_links import FlowStepLinks

structlogger = structlog.get_logger()

Expand Down Expand Up @@ -65,7 +65,7 @@ class FlowStep:
"""The description of the flow step."""
metadata: Dict[Text, Any]
"""Additional, unstructured information about this flow step."""
next: FlowLinks
next: FlowStepLinks
"""The next steps of the flow step."""

@classmethod
Expand All @@ -78,7 +78,7 @@ def _from_json(cls, flow_step_config: Dict[Text, Any]) -> FlowStep:
Returns:
The parsed flow step.
"""
from rasa.shared.core.flows.flow_step_links import FlowLinks
from rasa.shared.core.flows.flow_step_links import FlowStepLinks

return FlowStep(
# the idx is set later once the flow is created that contains
Expand All @@ -87,7 +87,7 @@ def _from_json(cls, flow_step_config: Dict[Text, Any]) -> FlowStep:
custom_id=flow_step_config.get("id"),
description=flow_step_config.get("description"),
metadata=flow_step_config.get("metadata", {}),
next=FlowLinks.from_json(flow_step_config.get("next", [])),
next=FlowStepLinks.from_json(flow_step_config.get("next", [])),
)

def as_json(self) -> Dict[Text, Any]:
Expand Down

0 comments on commit 3d4459e

Please sign in to comment.