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

Eng 585 flows wrap up #12940

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
4f30859
Moved exceptions
twerkmeister Oct 24, 2023
dc78a0d
fixed typo
twerkmeister Oct 24, 2023
c154ae9
fixed schema
twerkmeister Oct 24, 2023
e0abaec
added basic test for flow schema
twerkmeister Oct 24, 2023
7c2c4a1
replaced Text with str typing, typo
twerkmeister Oct 24, 2023
0a66c7c
Added exceptions, validations, and tests for empty flows and empty st…
twerkmeister Oct 24, 2023
b579422
Using normal inheritance for FlowLink class hierarchy
twerkmeister Oct 24, 2023
3acbbca
fixed bad import and trailing whitespace
twerkmeister Oct 25, 2023
5d943e3
Removed unused method
twerkmeister Oct 25, 2023
5b67da8
Extracted FlowsList into own file
twerkmeister Oct 25, 2023
c9c8716
small doc string improvement, removed unused methods
twerkmeister Oct 25, 2023
9ffd161
Moved flow validation outside of class
twerkmeister Oct 25, 2023
20a67f3
improved typing
twerkmeister Oct 25, 2023
27d69fd
Moved branch based link from json to that class
twerkmeister Oct 25, 2023
d2c428d
Moved flow steps, step sequence and step links out of the main flow file
twerkmeister Oct 25, 2023
ab653db
moved exceptions to the validation code
twerkmeister Oct 25, 2023
068ea2c
moved file testing into io file
twerkmeister Oct 25, 2023
0db22f4
removed empty utils file
twerkmeister Oct 26, 2023
32b8d72
Pulled big flow step, flow step sequence and flow step links file apart
twerkmeister Oct 26, 2023
3d4459e
Improved typing, naming and docs for flow step links
twerkmeister Oct 26, 2023
b8a6c2b
fixed empty step sequence validation not to use target method
twerkmeister Oct 26, 2023
15aa90f
ruff check
twerkmeister Oct 26, 2023
1c131f0
improved docs, variable naming, interface adherence for all flow step…
twerkmeister Oct 26, 2023
5464980
added type annotations
twerkmeister Oct 26, 2023
1861c19
improved docs, naming in the flow step sequence
twerkmeister Oct 26, 2023
c5d8e51
improved docs and naming of the FlowsList
twerkmeister Oct 26, 2023
cb80889
removed branch flow step and fixed predicate validation, added test
twerkmeister Oct 26, 2023
a6e99c1
removed unused import
twerkmeister Oct 26, 2023
a602a9a
excluded conditions with jinja templating from tests for now
twerkmeister Oct 26, 2023
8c0260b
moved type check for former branch flow step back where it was and ad…
twerkmeister Oct 27, 2023
48c0718
Added tests for flows io, fixed bug that made serialization and deser…
twerkmeister Oct 27, 2023
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
10 changes: 10 additions & 0 deletions data/test_flows/basic_flows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
flows:
foo:
description: "A test flow"
steps:
- action: "utter_test"
bar:
description: "Another test flow"
steps:
- action: "utter_greet"
- collect: "important_info"
3 changes: 2 additions & 1 deletion rasa/core/actions/action_clean_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
from rasa.shared.core.constants import ACTION_CLEAN_STACK, DIALOGUE_STACK_SLOT
from rasa.shared.core.domain import Domain
from rasa.shared.core.events import Event, SlotSet
from rasa.shared.core.flows.flow import ContinueFlowStep, END_STEP
from rasa.shared.core.flows.steps.constants import END_STEP
from rasa.shared.core.flows.steps.continuation import ContinueFlowStep
from rasa.shared.core.trackers import DialogueStateTracker


Expand Down
45 changes: 25 additions & 20 deletions rasa/core/policies/flow_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,31 @@
ACTION_SEND_TEXT_NAME,
)
from rasa.shared.core.events import Event, SlotSet
from rasa.shared.core.flows.flow import (
END_STEP,
ActionFlowStep,
BranchFlowStep,
ContinueFlowStep,
ElseFlowLink,
EndFlowStep,
Flow,
from rasa.shared.core.flows.flow_step import (
FlowStep,
FlowsList,
GenerateResponseFlowStep,
IfFlowLink,
)
from rasa.shared.core.flows.flow_step_links import (
IfFlowStepLink,
ElseFlowStepLink,
StaticFlowStepLink,
)
from rasa.shared.core.flows.steps.constants import END_STEP
from rasa.shared.core.flows.steps.continuation import ContinueFlowStep
from rasa.shared.core.flows.steps.set_slots import SetSlotsFlowStep
from rasa.shared.core.flows.steps.collect import (
SlotRejection,
CollectInformationFlowStep,
)
from rasa.shared.core.flows.steps.generate_response import GenerateResponseFlowStep
from rasa.shared.core.flows.steps.user_message import (
StepThatCanStartAFlow,
UserMessageStep,
LinkFlowStep,
SetSlotsFlowStep,
CollectInformationFlowStep,
StaticFlowLink,
)
from rasa.shared.core.flows.steps.link import LinkFlowStep
from rasa.shared.core.flows.steps.action import ActionFlowStep
from rasa.shared.core.flows.flow import Flow
from rasa.shared.core.flows.flows_list import FlowsList
from rasa.shared.core.flows.steps.end import EndFlowStep
from rasa.core.featurizers.tracker_featurizers import TrackerFeaturizer
from rasa.core.policies.policy import Policy, PolicyPrediction
from rasa.engine.graph import ExecutionContext
Expand Down Expand Up @@ -364,18 +369,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 Expand Up @@ -672,8 +677,8 @@ def run_step(
structlogger.debug("flow.step.run.user_message")
return ContinueFlowWithNextStep()

elif isinstance(step, BranchFlowStep):
structlogger.debug("flow.step.run.branch")
elif type(step) is FlowStep:
structlogger.debug("flow.step.run.base_flow_step")
return ContinueFlowWithNextStep()

elif isinstance(step, GenerateResponseFlowStep):
Expand Down
2 changes: 1 addition & 1 deletion rasa/core/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from rasa.engine.storage.storage import ModelMetadata
from rasa.model import get_latest_model
from rasa.plugin import plugin_manager
from rasa.shared.core.flows.flow import FlowsList
from rasa.shared.core.flows.flows_list import FlowsList
from rasa.shared.data import TrainingType
import rasa.shared.utils.io
import rasa.core.actions.action
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import Any, Dict, List
from rasa.dialogue_understanding.commands import Command
from rasa.shared.core.events import Event
from rasa.shared.core.flows.flow import FlowsList
from rasa.shared.core.flows.flows_list import FlowsList
from rasa.shared.core.trackers import DialogueStateTracker


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from rasa.dialogue_understanding.stack.dialogue_stack import DialogueStack
from rasa.dialogue_understanding.stack.frames import UserFlowStackFrame
from rasa.shared.core.events import Event
from rasa.shared.core.flows.flow import FlowsList
from rasa.shared.core.flows.flows_list import FlowsList
from rasa.shared.core.trackers import DialogueStateTracker
from rasa.dialogue_understanding.stack.utils import top_user_flow_frame

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from rasa.dialogue_understanding.patterns.chitchat import ChitchatPatternFlowStackFrame
from rasa.dialogue_understanding.stack.dialogue_stack import DialogueStack
from rasa.shared.core.events import Event
from rasa.shared.core.flows.flow import FlowsList
from rasa.shared.core.flows.flows_list import FlowsList
from rasa.shared.core.trackers import DialogueStateTracker


Expand Down
2 changes: 1 addition & 1 deletion rasa/dialogue_understanding/commands/clarify_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from rasa.dialogue_understanding.patterns.clarify import ClarifyPatternFlowStackFrame
from rasa.dialogue_understanding.stack.dialogue_stack import DialogueStack
from rasa.shared.core.events import Event
from rasa.shared.core.flows.flow import FlowsList
from rasa.shared.core.flows.flows_list import FlowsList
from rasa.shared.core.trackers import DialogueStateTracker

structlogger = structlog.get_logger()
Expand Down
2 changes: 1 addition & 1 deletion rasa/dialogue_understanding/commands/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import dataclasses
from typing import Any, Dict, List
from rasa.shared.core.events import Event
from rasa.shared.core.flows.flow import FlowsList
from rasa.shared.core.flows.flows_list import FlowsList
from rasa.shared.core.trackers import DialogueStateTracker
import rasa.shared.utils.common

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
UserFlowStackFrame,
)
from rasa.shared.core.events import Event
from rasa.shared.core.flows.flow import END_STEP, ContinueFlowStep, FlowStep, FlowsList
from rasa.shared.core.flows.flow_step import FlowStep
from rasa.shared.core.flows.steps.constants import END_STEP
from rasa.shared.core.flows.steps.continuation import ContinueFlowStep
from rasa.shared.core.flows.flows_list import FlowsList
from rasa.shared.core.trackers import DialogueStateTracker
import rasa.dialogue_understanding.stack.utils as utils

Expand Down
2 changes: 1 addition & 1 deletion rasa/dialogue_understanding/commands/error_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
)
from rasa.dialogue_understanding.stack.dialogue_stack import DialogueStack
from rasa.shared.core.events import Event
from rasa.shared.core.flows.flow import FlowsList
from rasa.shared.core.flows.flows_list import FlowsList
from rasa.shared.core.trackers import DialogueStateTracker

structlogger = structlog.get_logger()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from rasa.dialogue_understanding.stack.dialogue_stack import DialogueStack
from rasa.shared.core.constants import DIALOGUE_STACK_SLOT
from rasa.shared.core.events import Event, SlotSet
from rasa.shared.core.flows.flow import FlowsList
from rasa.shared.core.flows.flows_list import FlowsList
from rasa.shared.core.trackers import DialogueStateTracker
from rasa.dialogue_understanding.stack.utils import top_user_flow_frame

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import Any, Dict, List
from rasa.dialogue_understanding.commands import Command
from rasa.shared.core.events import Event
from rasa.shared.core.flows.flow import FlowsList
from rasa.shared.core.flows.flows_list import FlowsList
from rasa.shared.core.trackers import DialogueStateTracker


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from rasa.dialogue_understanding.patterns.search import SearchPatternFlowStackFrame
from rasa.dialogue_understanding.stack.dialogue_stack import DialogueStack
from rasa.shared.core.events import Event
from rasa.shared.core.flows.flow import FlowsList
from rasa.shared.core.flows.flows_list import FlowsList
from rasa.shared.core.trackers import DialogueStateTracker


Expand Down
2 changes: 1 addition & 1 deletion rasa/dialogue_understanding/commands/set_slot_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from rasa.dialogue_understanding.stack.dialogue_stack import DialogueStack
from rasa.dialogue_understanding.stack.utils import filled_slots_for_active_flow
from rasa.shared.core.events import Event, SlotSet
from rasa.shared.core.flows.flow import FlowsList
from rasa.shared.core.flows.flows_list import FlowsList
from rasa.shared.core.trackers import DialogueStateTracker

structlogger = structlog.get_logger()
Expand Down
2 changes: 1 addition & 1 deletion rasa/dialogue_understanding/commands/start_flow_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
user_flows_on_the_stack,
)
from rasa.shared.core.events import Event
from rasa.shared.core.flows.flow import FlowsList
from rasa.shared.core.flows.flows_list import FlowsList
from rasa.shared.core.trackers import DialogueStateTracker

structlogger = structlog.get_logger()
Expand Down
2 changes: 1 addition & 1 deletion rasa/dialogue_understanding/generator/command_generator.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import List, Optional
import structlog
from rasa.dialogue_understanding.commands import Command
from rasa.shared.core.flows.flow import FlowsList
from rasa.shared.core.flows.flows_list import FlowsList
from rasa.shared.core.trackers import DialogueStateTracker
from rasa.shared.nlu.training_data.message import Message
from rasa.shared.nlu.constants import COMMANDS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
from rasa.engine.recipes.default_recipe import DefaultV1Recipe
from rasa.engine.storage.resource import Resource
from rasa.engine.storage.storage import ModelStorage
from rasa.shared.core.flows.flow import (
Flow,
from rasa.shared.core.flows.flow_step import (
FlowStep,
FlowsList,
CollectInformationFlowStep,
)
from rasa.shared.core.flows.steps.collect import CollectInformationFlowStep
from rasa.shared.core.flows.flow import Flow
from rasa.shared.core.flows.flows_list import FlowsList
from rasa.shared.core.trackers import DialogueStateTracker
from rasa.shared.core.slots import (
BooleanSlot,
Expand Down
3 changes: 2 additions & 1 deletion rasa/dialogue_understanding/patterns/cancel.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
from rasa.shared.core.constants import ACTION_CANCEL_FLOW
from rasa.shared.core.domain import Domain
from rasa.shared.core.events import Event
from rasa.shared.core.flows.flow import END_STEP, ContinueFlowStep
from rasa.shared.core.flows.steps.constants import END_STEP
from rasa.shared.core.flows.steps.continuation import ContinueFlowStep
from rasa.shared.core.trackers import DialogueStateTracker


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from rasa.dialogue_understanding.stack.dialogue_stack import DialogueStackFrame
from rasa.shared.constants import RASA_DEFAULT_FLOW_PATTERN_PREFIX
from rasa.dialogue_understanding.stack.frames import PatternFlowStackFrame
from rasa.shared.core.flows.flow import SlotRejection
from rasa.shared.core.flows.steps.collect import SlotRejection

FLOW_PATTERN_COLLECT_INFORMATION = (
RASA_DEFAULT_FLOW_PATTERN_PREFIX + "collect_information"
Expand Down
6 changes: 2 additions & 4 deletions rasa/dialogue_understanding/patterns/correction.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
)
from rasa.dialogue_understanding.stack.dialogue_stack import DialogueStack
from rasa.shared.constants import RASA_DEFAULT_FLOW_PATTERN_PREFIX
from rasa.shared.core.flows.flow import (
START_STEP,
)
from rasa.shared.core.flows.steps.constants import START_STEP, END_STEP
from rasa.shared.core.trackers import (
DialogueStateTracker,
)
Expand All @@ -30,7 +28,7 @@
SlotSet,
)
from rasa.core.nlg import NaturalLanguageGenerator
from rasa.shared.core.flows.flow import END_STEP, ContinueFlowStep
from rasa.shared.core.flows.steps.continuation import ContinueFlowStep

structlogger = structlog.get_logger()

Expand Down
6 changes: 2 additions & 4 deletions rasa/dialogue_understanding/processor/command_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@
)
from rasa.shared.core.constants import FLOW_HASHES_SLOT
from rasa.shared.core.events import Event, SlotSet
from rasa.shared.core.flows.flow import (
FlowsList,
CollectInformationFlowStep,
)
from rasa.shared.core.flows.steps.collect import CollectInformationFlowStep
from rasa.shared.core.flows.flows_list import FlowsList
from rasa.shared.core.trackers import DialogueStateTracker
from rasa.shared.nlu.constants import COMMANDS

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from rasa.engine.storage.resource import Resource
from rasa.engine.storage.storage import ModelStorage
from rasa.shared.core.events import Event
from rasa.shared.core.flows.flow import FlowsList
from rasa.shared.core.flows.flows_list import FlowsList
from rasa.shared.core.trackers import DialogueStateTracker


Expand Down
5 changes: 4 additions & 1 deletion rasa/dialogue_understanding/stack/frames/flow_stack_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
from typing import Any, Dict, Optional

from rasa.dialogue_understanding.stack.frames import DialogueStackFrame
from rasa.shared.core.flows.flow import START_STEP, Flow, FlowStep, FlowsList
from rasa.shared.core.flows.flow_step import FlowStep
from rasa.shared.core.flows.steps.constants import START_STEP
from rasa.shared.core.flows.flow import Flow
from rasa.shared.core.flows.flows_list import FlowsList
from rasa.shared.exceptions import RasaException


Expand Down
4 changes: 3 additions & 1 deletion rasa/dialogue_understanding/stack/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
from rasa.dialogue_understanding.stack.frames import BaseFlowStackFrame
from rasa.dialogue_understanding.stack.dialogue_stack import DialogueStack
from rasa.dialogue_understanding.stack.frames import UserFlowStackFrame
from rasa.shared.core.flows.flow import END_STEP, ContinueFlowStep, FlowsList
from rasa.shared.core.flows.steps.constants import END_STEP
from rasa.shared.core.flows.steps.continuation import ContinueFlowStep
from rasa.shared.core.flows.flows_list import FlowsList


def top_flow_frame(
Expand Down
8 changes: 4 additions & 4 deletions rasa/graph_components/providers/flows_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
from rasa.shared.importers.importer import TrainingDataImporter
from rasa.shared.core.flows.yaml_flows_io import YAMLFlowsReader, YamlFlowsWriter

from rasa.shared.core.flows.flow import FlowsList
from rasa.shared.core.flows.flows_list import FlowsList

FLOWS_PERSITENCE_FILE_NAME = "flows.yml"
FLOWS_PERSISTENCE_FILE_NAME = "flows.yml"


class FlowsProvider(GraphComponent):
Expand Down Expand Up @@ -50,7 +50,7 @@ def load(
"""Creates provider using a persisted version of itself."""
with model_storage.read_from(resource) as resource_directory:
flows = YAMLFlowsReader.read_from_file(
resource_directory / FLOWS_PERSITENCE_FILE_NAME
resource_directory / FLOWS_PERSISTENCE_FILE_NAME
)
return cls(model_storage, resource, flows)

Expand All @@ -59,7 +59,7 @@ def _persist(self, flows: FlowsList) -> None:
with self._model_storage.write_to(self._resource) as resource_directory:
YamlFlowsWriter.dump(
flows.underlying_flows,
resource_directory / FLOWS_PERSITENCE_FILE_NAME,
resource_directory / FLOWS_PERSISTENCE_FILE_NAME,
)

def provide_train(self, importer: TrainingDataImporter) -> FlowsList:
Expand Down
2 changes: 1 addition & 1 deletion rasa/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -1378,7 +1378,7 @@ async def get_flows(request: Request) -> HTTPResponse:
"""Get all the flows currently stored by the agent."""
processor = app.ctx.agent.processor
flows = processor.get_flows()
return response.json(flows.as_json())
return response.json(flows.as_json_list())

@app.get("/domain")
@requires_auth(app, auth_token)
Expand Down
Loading
Loading