Skip to content

Commit

Permalink
Eng 496 intentless changes (#12900)
Browse files Browse the repository at this point in the history
* retrieving all utterances from flows with new attribute

* Added trigger actions for search and chitchat

* added search pattern

* adjusted patterns for new yaml format

* added test for default action + name consistency

* fixed default flows

* setting default flow name, if there is none
  • Loading branch information
twerkmeister authored and tabergma committed Oct 12, 2023
1 parent c4e3e1b commit ca74d6f
Show file tree
Hide file tree
Showing 31 changed files with 388 additions and 125 deletions.
10 changes: 7 additions & 3 deletions rasa/core/actions/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,10 @@ def default_actions(action_endpoint: Optional[EndpointConfig] = None) -> List["A
from rasa.dialogue_understanding.patterns.correction import ActionCorrectFlowSlot
from rasa.dialogue_understanding.patterns.cancel import ActionCancelFlow
from rasa.dialogue_understanding.patterns.clarify import ActionClarifyFlows
from rasa.core.actions.action_run_slot_rejections import (
ActionRunSlotRejections,
)
from rasa.core.actions.action_run_slot_rejections import ActionRunSlotRejections
from rasa.core.actions.action_trigger_chitchat import ActionTriggerChitchat
from rasa.core.actions.action_trigger_search import ActionTriggerSearch
from rasa.core.actions.action_clean_stack import ActionCleanStack

return [
ActionListen(),
Expand All @@ -123,6 +124,9 @@ def default_actions(action_endpoint: Optional[EndpointConfig] = None) -> List["A
ActionCorrectFlowSlot(),
ActionClarifyFlows(),
ActionRunSlotRejections(),
ActionCleanStack(),
ActionTriggerSearch(),
ActionTriggerChitchat(),
]


Expand Down
4 changes: 2 additions & 2 deletions rasa/core/actions/action_clean_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from typing import Optional, Dict, Any, List

from rasa.core.actions import action
from rasa.core.actions.action import Action
from rasa.core.channels import OutputChannel
from rasa.core.nlg import NaturalLanguageGenerator
from rasa.dialogue_understanding.stack.dialogue_stack import DialogueStack
Expand All @@ -18,7 +18,7 @@
from rasa.shared.core.trackers import DialogueStateTracker


class ActionCleanStack(action.Action):
class ActionCleanStack(Action):
"""Action which cancels a flow from the stack."""

def name(self) -> str:
Expand Down
32 changes: 32 additions & 0 deletions rasa/core/actions/action_trigger_chitchat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from typing import Optional, Dict, Any, List

from rasa.core.actions.action import Action
from rasa.core.channels import OutputChannel
from rasa.core.nlg import NaturalLanguageGenerator
from rasa.dialogue_understanding.stack.dialogue_stack import DialogueStack
from rasa.dialogue_understanding.stack.frames import ChitChatStackFrame
from rasa.shared.core.constants import ACTION_TRIGGER_CHITCHAT
from rasa.shared.core.domain import Domain
from rasa.shared.core.events import Event
from rasa.shared.core.trackers import DialogueStateTracker


class ActionTriggerChitchat(Action):
"""Action which triggers a chitchat answer."""

def name(self) -> str:
"""Return the name of the action."""
return ACTION_TRIGGER_CHITCHAT

async def run(
self,
output_channel: OutputChannel,
nlg: NaturalLanguageGenerator,
tracker: DialogueStateTracker,
domain: Domain,
metadata: Optional[Dict[str, Any]] = None,
) -> List[Event]:
"""Run the predicate checks."""
dialogue_stack = DialogueStack.from_tracker(tracker)
dialogue_stack.push(ChitChatStackFrame())
return [dialogue_stack.persist_as_event()]
32 changes: 32 additions & 0 deletions rasa/core/actions/action_trigger_search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from typing import Optional, Dict, Any, List

from rasa.core.actions.action import Action
from rasa.core.channels import OutputChannel
from rasa.core.nlg import NaturalLanguageGenerator
from rasa.dialogue_understanding.stack.dialogue_stack import DialogueStack
from rasa.dialogue_understanding.stack.frames import SearchStackFrame
from rasa.shared.core.constants import ACTION_TRIGGER_SEARCH
from rasa.shared.core.domain import Domain
from rasa.shared.core.events import Event
from rasa.shared.core.trackers import DialogueStateTracker


class ActionTriggerSearch(Action):
"""Action which triggers a search"""

def name(self) -> str:
"""Return the name of the action."""
return ACTION_TRIGGER_SEARCH

async def run(
self,
output_channel: OutputChannel,
nlg: NaturalLanguageGenerator,
tracker: DialogueStateTracker,
domain: Domain,
metadata: Optional[Dict[str, Any]] = None,
) -> List[Event]:
"""Run the predicate checks."""
dialogue_stack = DialogueStack.from_tracker(tracker)
dialogue_stack.push(SearchStackFrame())
return [dialogue_stack.persist_as_event()]
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from dataclasses import dataclass
from typing import Any, Dict, List
from rasa.dialogue_understanding.commands import FreeFormAnswerCommand
from rasa.dialogue_understanding.patterns.chitchat import ChitchatPatternFlowStackFrame
from rasa.dialogue_understanding.stack.dialogue_stack import DialogueStack
from rasa.dialogue_understanding.stack.frames.chit_chat_frame import ChitChatStackFrame
from rasa.shared.core.events import Event
from rasa.shared.core.flows.flow import FlowsList
from rasa.shared.core.trackers import DialogueStateTracker
Expand Down Expand Up @@ -45,5 +45,5 @@ def run_command_on_tracker(
The events to apply to the tracker.
"""
stack = DialogueStack.from_tracker(tracker)
stack.push(ChitChatStackFrame())
stack.push(ChitchatPatternFlowStackFrame())
return [stack.persist_as_event()]
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from dataclasses import dataclass
from typing import Any, Dict, List
from rasa.dialogue_understanding.commands import FreeFormAnswerCommand
from rasa.dialogue_understanding.patterns.search import SearchPatternFlowStackFrame
from rasa.dialogue_understanding.stack.dialogue_stack import DialogueStack
from rasa.dialogue_understanding.stack.frames.search_frame import SearchStackFrame
from rasa.shared.core.events import Event
from rasa.shared.core.flows.flow import FlowsList
from rasa.shared.core.trackers import DialogueStateTracker
Expand Down Expand Up @@ -45,5 +45,5 @@ def run_command_on_tracker(
The events to apply to the tracker.
"""
dialogue_stack = DialogueStack.from_tracker(tracker)
dialogue_stack.push(SearchStackFrame())
dialogue_stack.push(SearchPatternFlowStackFrame())
return [dialogue_stack.persist_as_event()]
37 changes: 37 additions & 0 deletions rasa/dialogue_understanding/patterns/chitchat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from __future__ import annotations

from dataclasses import dataclass
from typing import Any, Dict
from rasa.shared.constants import RASA_DEFAULT_FLOW_PATTERN_PREFIX
from rasa.dialogue_understanding.stack.frames import PatternFlowStackFrame


FLOW_PATTERN_CHITCHAT = RASA_DEFAULT_FLOW_PATTERN_PREFIX + "chitchat"


@dataclass
class ChitchatPatternFlowStackFrame(PatternFlowStackFrame):
"""A flow stack frame that gets added to respond to Chitchat."""

flow_id: str = FLOW_PATTERN_CHITCHAT
"""The ID of the flow."""

@classmethod
def type(cls) -> str:
"""Returns the type of the frame."""
return FLOW_PATTERN_CHITCHAT

@staticmethod
def from_dict(data: Dict[str, Any]) -> ChitchatPatternFlowStackFrame:
"""Creates a `DialogueStackFrame` from a dictionary.
Args:
data: The dictionary to create the `DialogueStackFrame` from.
Returns:
The created `DialogueStackFrame`.
"""
return ChitchatPatternFlowStackFrame(
frame_id=data["frame_id"],
step_id=data["step_id"],
)
61 changes: 28 additions & 33 deletions rasa/dialogue_understanding/patterns/default_flows_for_patterns.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ responses:
metadata:
rephrase: True

utter_no_knowledge_base:
- text: I am afraid, I don't know the answer. At this point, I don't have access to a knowledge base.
metadata:
rephrase: True

slots:
confirm_correction:
type: bool
Expand All @@ -49,26 +54,19 @@ flows:
name: pattern continue interrupted

steps:
- id: "0"
action: utter_flow_continue_interrupted
- action: utter_flow_continue_interrupted

pattern_correction:
description: Handle a correction of a slot value.
name: pattern correction

steps:
- id: "check_if_reset_only"
- action: action_correct_flow_slot
next:
- if: context.is_reset_only
then: "jump_back_without_message"
- else: "correct_slots"
- id: "correct_slots"
action: action_correct_flow_slot
next: "inform_user"
- id: "inform_user"
action: utter_corrected_previous_input
- id: "jump_back_without_message"
action: action_correct_flow_slot
- if: not context.is_reset_only
then:
- action: utter_corrected_previous_input
next: "END"
- else: "END"

pattern_cancel_flow:
description: A meta flow that's started when a flow is cancelled.
Expand All @@ -85,47 +83,46 @@ flows:
description: internal error
name: pattern internal error
steps:
- id: "0"
action: utter_internal_error_rasa
- action: utter_internal_error_rasa

pattern_completed:
description: a flow has been completed and there is nothing else to be done
name: pattern completed
steps:
- id: "0"
action: utter_can_do_something_else
- action: utter_can_do_something_else

pattern_chitchat:
description: handle interactions with the user that are not task-oriented
name: pattern chitchat
steps:
- id: "0"
generation_prompt: |
- generation_prompt: |
You are an incredibly friendly assistant. Generate a short
response to the user's comment in simple english.
User: {{latest_user_message}}
Response:
pattern_search:
description: handle a knowledge-based question or request
name: pattern search
steps:
- action: utter_no_knowledge_base
# - action: action_trigger_search to use doc search policy if present

pattern_clarification:
description: handle clarifications with the user
name: pattern clarification
steps:
- id: "0"
action: action_clarify_flows
next: "1"
- id: "1"
action: utter_clarification_options_rasa
- action: action_clarify_flows
- action: utter_clarification_options_rasa

pattern_collect_information:
description: flow used to fill a slot
name: pattern collect information
steps:
- id: "start"
action: action_run_slot_rejections
next: "validate"
- id: "validate"
action: validate_{{context.collect}}
- action: validate_{{context.collect}}
next:
- if: "{{context.collect}} is not null"
then: "done"
Expand All @@ -140,9 +137,7 @@ flows:

pattern_code_change:
description: flow used to clean the stack after a bot update
name: pattern code change
steps:
- id: "inform_user"
action: utter_inform_code_change
next: "run_cleanup"
- id: "run_cleanup"
action: action_clean_stack
- action: utter_inform_code_change
- action: action_clean_stack
37 changes: 37 additions & 0 deletions rasa/dialogue_understanding/patterns/search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from __future__ import annotations

from dataclasses import dataclass
from typing import Any, Dict
from rasa.shared.constants import RASA_DEFAULT_FLOW_PATTERN_PREFIX
from rasa.dialogue_understanding.stack.frames import PatternFlowStackFrame


FLOW_PATTERN_SEARCH = RASA_DEFAULT_FLOW_PATTERN_PREFIX + "search"


@dataclass
class SearchPatternFlowStackFrame(PatternFlowStackFrame):
"""A stack frame that gets added to respond to knowledge-oriented questions."""

flow_id: str = FLOW_PATTERN_SEARCH
"""The ID of the flow."""

@classmethod
def type(cls) -> str:
"""Returns the type of the frame."""
return FLOW_PATTERN_SEARCH

@staticmethod
def from_dict(data: Dict[str, Any]) -> SearchPatternFlowStackFrame:
"""Creates a `DialogueStackFrame` from a dictionary.
Args:
data: The dictionary to create the `DialogueStackFrame` from.
Returns:
The created `DialogueStackFrame`.
"""
return SearchPatternFlowStackFrame(
frame_id=data["frame_id"],
step_id=data["step_id"],
)
4 changes: 4 additions & 0 deletions rasa/shared/core/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
ACTION_CORRECT_FLOW_SLOT = "action_correct_flow_slot"
ACTION_RUN_SLOT_REJECTIONS_NAME = "action_run_slot_rejections"
ACTION_CLEAN_STACK = "action_clean_stack"
ACTION_TRIGGER_SEARCH = "action_trigger_search"
ACTION_TRIGGER_CHITCHAT = "action_trigger_chitchat"


DEFAULT_ACTION_NAMES = [
Expand All @@ -64,6 +66,8 @@
ACTION_CLARIFY_FLOWS,
ACTION_RUN_SLOT_REJECTIONS_NAME,
ACTION_CLEAN_STACK,
ACTION_TRIGGER_SEARCH,
ACTION_TRIGGER_CHITCHAT,
]

ACTION_SHOULD_SEND_DOMAIN = "send_domain"
Expand Down
Loading

0 comments on commit ca74d6f

Please sign in to comment.