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

Update collect_information scope to reset_after_flow_ends bool property #12854

Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 1 addition & 2 deletions rasa/core/policies/flow_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
GenerateResponseFlowStep,
IfFlowLink,
EntryPromptFlowStep,
CollectInformationScope,
SlotRejection,
StepThatCanStartAFlow,
UserMessageStep,
Expand Down Expand Up @@ -521,7 +520,7 @@ def _reset_scoped_slots(
# reset all slots scoped to the flow
if (
isinstance(step, CollectInformationFlowStep)
and step.scope == CollectInformationScope.FLOW
and step.reset_after_flow_ends
):
slot = tracker.slots.get(step.collect_information, None)
initial_value = slot.initial_value if slot else None
Expand Down
27 changes: 4 additions & 23 deletions rasa/shared/core/flows/flow.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

from dataclasses import dataclass
from enum import Enum
from typing import Any, Dict, List, Optional, Protocol, Set, Text, runtime_checkable

import structlog
Expand Down Expand Up @@ -963,24 +962,6 @@ def is_triggered(self, tracker: DialogueStateTracker) -> bool:
return False


# enumeration of collect information scopes. scope can either be flow or global
class CollectInformationScope(str, Enum):
FLOW = "flow"
GLOBAL = "global"

@staticmethod
def from_str(label: Optional[Text]) -> "CollectInformationScope":
"""Converts a string to a CollectInformationScope."""
if label is None:
return CollectInformationScope.FLOW
elif label.lower() == "flow":
return CollectInformationScope.FLOW
elif label.lower() == "global":
return CollectInformationScope.GLOBAL
else:
raise NotImplementedError


@dataclass
class SlotRejection:
"""A slot rejection."""
Expand Down Expand Up @@ -1029,8 +1010,8 @@ class CollectInformationFlowStep(FlowStep):
"""how the slot value is validated using predicate evaluation."""
ask_before_filling: bool = False
"""Whether to always ask the question even if the slot is already filled."""
scope: CollectInformationScope = CollectInformationScope.FLOW
"""how the question is scoped, determines when to reset its value."""
reset_after_flow_ends: bool = True
"""Determines whether to reset the slot value at the end of the flow."""

@classmethod
def from_json(cls, flow_step_config: Dict[Text, Any]) -> CollectInformationFlowStep:
Expand All @@ -1049,7 +1030,7 @@ def from_json(cls, flow_step_config: Dict[Text, Any]) -> CollectInformationFlowS
"utter", f"utter_ask_{flow_step_config['collect_information']}"
),
ask_before_filling=flow_step_config.get("ask_before_filling", False),
scope=CollectInformationScope.from_str(flow_step_config.get("scope")),
reset_after_flow_ends=flow_step_config.get("reset_after_flow_ends", True),
rejections=[
SlotRejection.from_dict(rejection)
for rejection in flow_step_config.get("rejections", [])
Expand All @@ -1067,7 +1048,7 @@ def as_json(self) -> Dict[Text, Any]:
dump["collect_information"] = self.collect_information
dump["utter"] = self.utter
dump["ask_before_filling"] = self.ask_before_filling
dump["scope"] = self.scope.value
dump["reset_after_flow_ends"] = self.reset_after_flow_ends
dump["rejections"] = [rejection.as_dict() for rejection in self.rejections]

return dump
Expand Down
Loading