rasa-pro 3.13.0.dev20250612__py3-none-any.whl → 3.13.0.dev20250613__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of rasa-pro might be problematic. Click here for more details.
- rasa/__main__.py +0 -3
- rasa/api.py +1 -1
- rasa/cli/dialogue_understanding_test.py +1 -1
- rasa/cli/e2e_test.py +1 -1
- rasa/cli/evaluate.py +1 -1
- rasa/cli/export.py +1 -1
- rasa/cli/llm_fine_tuning.py +12 -11
- rasa/cli/project_templates/defaults.py +133 -0
- rasa/cli/run.py +1 -1
- rasa/cli/studio/link.py +53 -0
- rasa/cli/studio/pull.py +78 -0
- rasa/cli/studio/push.py +78 -0
- rasa/cli/studio/studio.py +12 -0
- rasa/cli/studio/upload.py +8 -0
- rasa/cli/train.py +1 -1
- rasa/cli/utils.py +1 -1
- rasa/cli/x.py +1 -1
- rasa/constants.py +2 -0
- rasa/core/__init__.py +0 -16
- rasa/core/actions/action.py +5 -1
- rasa/core/actions/action_repeat_bot_messages.py +18 -22
- rasa/core/actions/action_run_slot_rejections.py +0 -1
- rasa/core/agent.py +16 -1
- rasa/core/available_endpoints.py +146 -0
- rasa/core/brokers/pika.py +1 -2
- rasa/core/channels/botframework.py +2 -2
- rasa/core/channels/channel.py +2 -2
- rasa/core/channels/hangouts.py +8 -5
- rasa/core/channels/mattermost.py +1 -1
- rasa/core/channels/rasa_chat.py +2 -4
- rasa/core/channels/rest.py +5 -4
- rasa/core/channels/studio_chat.py +3 -2
- rasa/core/channels/vier_cvg.py +1 -2
- rasa/core/channels/voice_ready/audiocodes.py +1 -8
- rasa/core/channels/voice_stream/audiocodes.py +7 -4
- rasa/core/channels/voice_stream/genesys.py +2 -2
- rasa/core/channels/voice_stream/twilio_media_streams.py +10 -5
- rasa/core/channels/voice_stream/voice_channel.py +33 -22
- rasa/core/http_interpreter.py +3 -7
- rasa/core/jobs.py +2 -1
- rasa/core/nlg/contextual_response_rephraser.py +38 -11
- rasa/core/nlg/generator.py +0 -1
- rasa/core/nlg/interpolator.py +2 -3
- rasa/core/nlg/summarize.py +39 -5
- rasa/core/policies/enterprise_search_policy.py +290 -66
- rasa/core/policies/enterprise_search_prompt_with_relevancy_check_and_citation_template.jinja2 +63 -0
- rasa/core/policies/flow_policy.py +1 -1
- rasa/core/policies/flows/flow_executor.py +96 -17
- rasa/core/policies/intentless_policy.py +24 -16
- rasa/core/processor.py +104 -51
- rasa/core/run.py +33 -11
- rasa/core/tracker_stores/tracker_store.py +1 -1
- rasa/core/training/interactive.py +1 -1
- rasa/core/utils.py +24 -97
- rasa/dialogue_understanding/coexistence/intent_based_router.py +2 -1
- rasa/dialogue_understanding/coexistence/llm_based_router.py +8 -3
- rasa/dialogue_understanding/commands/can_not_handle_command.py +2 -0
- rasa/dialogue_understanding/commands/cancel_flow_command.py +2 -0
- rasa/dialogue_understanding/commands/chit_chat_answer_command.py +2 -0
- rasa/dialogue_understanding/commands/clarify_command.py +5 -1
- rasa/dialogue_understanding/commands/command_syntax_manager.py +1 -0
- rasa/dialogue_understanding/commands/human_handoff_command.py +2 -0
- rasa/dialogue_understanding/commands/knowledge_answer_command.py +2 -0
- rasa/dialogue_understanding/commands/repeat_bot_messages_command.py +2 -0
- rasa/dialogue_understanding/commands/set_slot_command.py +11 -1
- rasa/dialogue_understanding/commands/skip_question_command.py +2 -0
- rasa/dialogue_understanding/commands/start_flow_command.py +4 -0
- rasa/dialogue_understanding/commands/utils.py +26 -2
- rasa/dialogue_understanding/generator/__init__.py +7 -1
- rasa/dialogue_understanding/generator/command_generator.py +4 -2
- rasa/dialogue_understanding/generator/command_parser.py +2 -2
- rasa/dialogue_understanding/generator/command_parser_validator.py +63 -0
- rasa/dialogue_understanding/generator/constants.py +2 -2
- rasa/dialogue_understanding/generator/prompt_templates/command_prompt_v3_gpt_4o_2024_11_20_template.jinja2 +78 -0
- rasa/dialogue_understanding/generator/single_step/compact_llm_command_generator.py +28 -463
- rasa/dialogue_understanding/generator/single_step/search_ready_llm_command_generator.py +147 -0
- rasa/dialogue_understanding/generator/single_step/single_step_based_llm_command_generator.py +477 -0
- rasa/dialogue_understanding/generator/single_step/single_step_llm_command_generator.py +8 -58
- rasa/dialogue_understanding/patterns/default_flows_for_patterns.yml +37 -25
- rasa/dialogue_understanding/patterns/domain_for_patterns.py +190 -0
- rasa/dialogue_understanding/processor/command_processor.py +3 -3
- rasa/dialogue_understanding/processor/command_processor_component.py +3 -3
- rasa/dialogue_understanding/stack/frames/flow_stack_frame.py +17 -4
- rasa/dialogue_understanding/utils.py +68 -12
- rasa/dialogue_understanding_test/du_test_case.py +1 -1
- rasa/dialogue_understanding_test/du_test_runner.py +4 -22
- rasa/dialogue_understanding_test/test_case_simulation/test_case_tracker_simulator.py +2 -6
- rasa/e2e_test/e2e_test_runner.py +1 -1
- rasa/engine/constants.py +1 -1
- rasa/engine/recipes/default_recipe.py +26 -2
- rasa/engine/validation.py +3 -2
- rasa/hooks.py +0 -28
- rasa/llm_fine_tuning/annotation_module.py +39 -9
- rasa/llm_fine_tuning/conversations.py +3 -0
- rasa/llm_fine_tuning/llm_data_preparation_module.py +66 -49
- rasa/llm_fine_tuning/paraphrasing/conversation_rephraser.py +4 -2
- rasa/llm_fine_tuning/paraphrasing/rephrase_validator.py +52 -44
- rasa/llm_fine_tuning/paraphrasing_module.py +10 -12
- rasa/llm_fine_tuning/storage.py +4 -4
- rasa/llm_fine_tuning/utils.py +63 -1
- rasa/model_manager/model_api.py +88 -0
- rasa/model_manager/trainer_service.py +4 -4
- rasa/plugin.py +1 -11
- rasa/privacy/__init__.py +0 -0
- rasa/privacy/constants.py +83 -0
- rasa/privacy/event_broker_utils.py +77 -0
- rasa/privacy/privacy_config.py +281 -0
- rasa/privacy/privacy_config_schema.json +86 -0
- rasa/privacy/privacy_filter.py +340 -0
- rasa/privacy/privacy_manager.py +576 -0
- rasa/server.py +23 -2
- rasa/shared/constants.py +6 -0
- rasa/shared/core/constants.py +4 -3
- rasa/shared/core/domain.py +7 -0
- rasa/shared/core/events.py +37 -7
- rasa/shared/core/flows/flow.py +1 -2
- rasa/shared/core/flows/flows_yaml_schema.json +3 -0
- rasa/shared/core/flows/steps/collect.py +46 -2
- rasa/shared/core/slots.py +28 -0
- rasa/shared/exceptions.py +4 -0
- rasa/shared/providers/_configs/azure_openai_client_config.py +4 -0
- rasa/shared/providers/_configs/openai_client_config.py +4 -0
- rasa/shared/providers/embedding/_base_litellm_embedding_client.py +3 -0
- rasa/shared/providers/llm/_base_litellm_client.py +5 -2
- rasa/shared/utils/llm.py +161 -6
- rasa/shared/utils/yaml.py +32 -0
- rasa/studio/data_handler.py +3 -3
- rasa/studio/download/download.py +37 -60
- rasa/studio/download/flows.py +23 -31
- rasa/studio/link.py +200 -0
- rasa/studio/pull.py +94 -0
- rasa/studio/push.py +131 -0
- rasa/studio/upload.py +117 -67
- rasa/telemetry.py +82 -25
- rasa/tracing/config.py +3 -4
- rasa/tracing/constants.py +19 -1
- rasa/tracing/instrumentation/attribute_extractors.py +10 -2
- rasa/tracing/instrumentation/instrumentation.py +53 -2
- rasa/tracing/instrumentation/metrics.py +98 -15
- rasa/tracing/metric_instrument_provider.py +75 -3
- rasa/utils/common.py +1 -27
- rasa/utils/log_utils.py +1 -45
- rasa/validator.py +2 -8
- rasa/version.py +1 -1
- {rasa_pro-3.13.0.dev20250612.dist-info → rasa_pro-3.13.0.dev20250613.dist-info}/METADATA +5 -6
- {rasa_pro-3.13.0.dev20250612.dist-info → rasa_pro-3.13.0.dev20250613.dist-info}/RECORD +149 -135
- rasa/anonymization/__init__.py +0 -2
- rasa/anonymization/anonymisation_rule_yaml_reader.py +0 -91
- rasa/anonymization/anonymization_pipeline.py +0 -286
- rasa/anonymization/anonymization_rule_executor.py +0 -266
- rasa/anonymization/anonymization_rule_orchestrator.py +0 -119
- rasa/anonymization/schemas/config.yml +0 -47
- rasa/anonymization/utils.py +0 -118
- {rasa_pro-3.13.0.dev20250612.dist-info → rasa_pro-3.13.0.dev20250613.dist-info}/NOTICE +0 -0
- {rasa_pro-3.13.0.dev20250612.dist-info → rasa_pro-3.13.0.dev20250613.dist-info}/WHEEL +0 -0
- {rasa_pro-3.13.0.dev20250612.dist-info → rasa_pro-3.13.0.dev20250613.dist-info}/entry_points.txt +0 -0
|
@@ -4,33 +4,19 @@ from typing import Any, Dict, Literal, Optional, Text
|
|
|
4
4
|
import structlog
|
|
5
5
|
|
|
6
6
|
from rasa.dialogue_understanding.commands.command_syntax_manager import (
|
|
7
|
-
CommandSyntaxManager,
|
|
8
7
|
CommandSyntaxVersion,
|
|
9
8
|
)
|
|
10
|
-
from rasa.dialogue_understanding.generator.
|
|
11
|
-
|
|
12
|
-
FLOW_RETRIEVAL_KEY,
|
|
13
|
-
LLM_CONFIG_KEY,
|
|
14
|
-
USER_INPUT_CONFIG_KEY,
|
|
15
|
-
)
|
|
16
|
-
from rasa.dialogue_understanding.generator.flow_retrieval import FlowRetrieval
|
|
17
|
-
from rasa.dialogue_understanding.generator.single_step.compact_llm_command_generator import ( # noqa: E501
|
|
18
|
-
CompactLLMCommandGenerator,
|
|
9
|
+
from rasa.dialogue_understanding.generator.single_step.single_step_based_llm_command_generator import ( # noqa: E501
|
|
10
|
+
SingleStepBasedLLMCommandGenerator,
|
|
19
11
|
)
|
|
20
12
|
from rasa.engine.recipes.default_recipe import DefaultV1Recipe
|
|
21
13
|
from rasa.engine.storage.resource import Resource
|
|
22
14
|
from rasa.engine.storage.storage import ModelStorage
|
|
23
15
|
from rasa.shared.constants import (
|
|
24
|
-
EMBEDDINGS_CONFIG_KEY,
|
|
25
16
|
PROMPT_CONFIG_KEY,
|
|
26
17
|
PROMPT_TEMPLATE_CONFIG_KEY,
|
|
27
18
|
)
|
|
28
|
-
from rasa.shared.utils.
|
|
29
|
-
from rasa.shared.utils.io import deep_container_fingerprint
|
|
30
|
-
from rasa.shared.utils.llm import (
|
|
31
|
-
get_prompt_template,
|
|
32
|
-
resolve_model_client_config,
|
|
33
|
-
)
|
|
19
|
+
from rasa.shared.utils.llm import get_prompt_template
|
|
34
20
|
|
|
35
21
|
DEFAULT_COMMAND_PROMPT_TEMPLATE = importlib.resources.read_text(
|
|
36
22
|
"rasa.dialogue_understanding.generator.prompt_templates",
|
|
@@ -47,7 +33,7 @@ structlogger = structlog.get_logger()
|
|
|
47
33
|
],
|
|
48
34
|
is_trainable=True,
|
|
49
35
|
)
|
|
50
|
-
class SingleStepLLMCommandGenerator(
|
|
36
|
+
class SingleStepLLMCommandGenerator(SingleStepBasedLLMCommandGenerator):
|
|
51
37
|
"""A single step LLM-based command generator."""
|
|
52
38
|
|
|
53
39
|
def __init__(
|
|
@@ -77,53 +63,17 @@ class SingleStepLLMCommandGenerator(CompactLLMCommandGenerator):
|
|
|
77
63
|
),
|
|
78
64
|
)
|
|
79
65
|
|
|
80
|
-
# Set the command syntax version to v1
|
|
81
|
-
CommandSyntaxManager.set_syntax_version(
|
|
82
|
-
self.get_component_command_syntax_version()
|
|
83
|
-
)
|
|
84
|
-
|
|
85
|
-
@staticmethod
|
|
86
|
-
def get_default_config() -> Dict[str, Any]:
|
|
87
|
-
"""The component's default config (see parent class for full docstring)."""
|
|
88
|
-
return {
|
|
89
|
-
PROMPT_CONFIG_KEY: None, # Legacy
|
|
90
|
-
PROMPT_TEMPLATE_CONFIG_KEY: None,
|
|
91
|
-
USER_INPUT_CONFIG_KEY: None,
|
|
92
|
-
LLM_CONFIG_KEY: None,
|
|
93
|
-
FLOW_RETRIEVAL_KEY: FlowRetrieval.get_default_config(),
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
@classmethod
|
|
97
|
-
def fingerprint_addon(cls: Any, config: Dict[str, Any]) -> Optional[str]:
|
|
98
|
-
"""Add a fingerprint for the graph."""
|
|
99
|
-
prompt_template = cls._resolve_component_prompt_template(
|
|
100
|
-
config, log_context=LOG_COMPONENT_SOURCE_METHOD_FINGERPRINT_ADDON
|
|
101
|
-
)
|
|
102
|
-
llm_config = resolve_model_client_config(
|
|
103
|
-
config.get(LLM_CONFIG_KEY), SingleStepLLMCommandGenerator.__name__
|
|
104
|
-
)
|
|
105
|
-
embedding_config = resolve_model_client_config(
|
|
106
|
-
config.get(FLOW_RETRIEVAL_KEY, {}).get(EMBEDDINGS_CONFIG_KEY),
|
|
107
|
-
FlowRetrieval.__name__,
|
|
108
|
-
)
|
|
109
|
-
return deep_container_fingerprint(
|
|
110
|
-
[prompt_template, llm_config, embedding_config]
|
|
111
|
-
)
|
|
112
|
-
|
|
113
|
-
@staticmethod
|
|
114
|
-
def get_default_llm_config() -> Dict[str, Any]:
|
|
115
|
-
"""Get the default LLM config for the command generator."""
|
|
116
|
-
return DEFAULT_LLM_CONFIG
|
|
117
|
-
|
|
118
66
|
@staticmethod
|
|
119
67
|
def get_component_command_syntax_version() -> CommandSyntaxVersion:
|
|
120
68
|
return CommandSyntaxVersion.v1
|
|
121
69
|
|
|
122
|
-
@
|
|
70
|
+
@classmethod
|
|
123
71
|
def _resolve_component_prompt_template(
|
|
72
|
+
cls: Any,
|
|
124
73
|
config: Dict[str, Any],
|
|
125
74
|
prompt_template: Optional[str] = None,
|
|
126
75
|
log_context: Optional[Literal["init", "fingerprint_addon"]] = None,
|
|
76
|
+
log_source_component: Optional[str] = "SingleStepLLMCommandGenerator",
|
|
127
77
|
) -> Optional[str]:
|
|
128
78
|
"""Get the prompt template from the config or the default prompt template."""
|
|
129
79
|
# Case when model is being loaded
|
|
@@ -143,6 +93,6 @@ class SingleStepLLMCommandGenerator(CompactLLMCommandGenerator):
|
|
|
143
93
|
return get_prompt_template(
|
|
144
94
|
prompt_template_path,
|
|
145
95
|
DEFAULT_COMMAND_PROMPT_TEMPLATE,
|
|
146
|
-
log_source_component=
|
|
96
|
+
log_source_component=log_source_component,
|
|
147
97
|
log_source_method=log_context,
|
|
148
98
|
)
|
|
@@ -93,6 +93,11 @@ responses:
|
|
|
93
93
|
metadata:
|
|
94
94
|
rephrase: True
|
|
95
95
|
|
|
96
|
+
utter_no_relevant_answer_found:
|
|
97
|
+
- text: I’m sorry, I can’t help with that.
|
|
98
|
+
metadata:
|
|
99
|
+
rephrase: True
|
|
100
|
+
|
|
96
101
|
utter_skip_question_answer:
|
|
97
102
|
- text: I'm here to provide you with the best assistance, and in order to do so, I kindly request that we complete this step together. Your input is essential for a seamless experience!
|
|
98
103
|
metadata:
|
|
@@ -129,23 +134,28 @@ flows:
|
|
|
129
134
|
- action: utter_flow_cancelled_rasa
|
|
130
135
|
|
|
131
136
|
pattern_cannot_handle:
|
|
132
|
-
description:
|
|
133
|
-
|
|
134
|
-
name: pattern cannot handle
|
|
137
|
+
description: Conversation repair flow for addressing failed command generation scenarios
|
|
138
|
+
name: pattern_cannot_handle
|
|
135
139
|
steps:
|
|
136
140
|
- noop: true
|
|
137
141
|
next:
|
|
138
|
-
#
|
|
139
|
-
- if:
|
|
142
|
+
# Chitchat fallback
|
|
143
|
+
- if: context.reason is "cannot_handle_chitchat"
|
|
140
144
|
then:
|
|
141
145
|
- action: utter_cannot_handle
|
|
142
146
|
next: "END"
|
|
143
|
-
#
|
|
144
|
-
- if:
|
|
147
|
+
# Fallback for things that are not supported
|
|
148
|
+
- if: context.reason is "cannot_handle_not_supported"
|
|
145
149
|
then:
|
|
146
150
|
- action: utter_cannot_handle
|
|
147
151
|
next: END
|
|
148
|
-
#
|
|
152
|
+
# Fallback when no relevant answer to the user query has been found.
|
|
153
|
+
# This is used by the EnterpriseSearchPolicy.
|
|
154
|
+
- if: context.reason is "cannot_handle_no_relevant_answer"
|
|
155
|
+
then:
|
|
156
|
+
- action: utter_no_relevant_answer_found
|
|
157
|
+
next: END
|
|
158
|
+
# Default
|
|
149
159
|
- else:
|
|
150
160
|
- action: utter_ask_rephrase
|
|
151
161
|
next: END
|
|
@@ -219,15 +229,15 @@ flows:
|
|
|
219
229
|
|
|
220
230
|
pattern_internal_error:
|
|
221
231
|
description: Conversation repair flow for informing users about internal errors
|
|
222
|
-
name:
|
|
232
|
+
name: pattern_internal_error
|
|
223
233
|
steps:
|
|
224
234
|
- noop: true
|
|
225
235
|
next:
|
|
226
|
-
- if:
|
|
236
|
+
- if: context.error_type is "rasa_internal_error_user_input_too_long"
|
|
227
237
|
then:
|
|
228
238
|
- action: utter_user_input_too_long_error_rasa
|
|
229
239
|
next: END
|
|
230
|
-
- if:
|
|
240
|
+
- if: context.error_type is "rasa_internal_error_user_input_empty"
|
|
231
241
|
then:
|
|
232
242
|
- action: utter_user_input_empty_error_rasa
|
|
233
243
|
next: END
|
|
@@ -281,23 +291,25 @@ flows:
|
|
|
281
291
|
- noop: true
|
|
282
292
|
next:
|
|
283
293
|
- if: "slots.consecutive_silence_timeouts = 0.0"
|
|
284
|
-
then:
|
|
285
|
-
- set_slots:
|
|
286
|
-
- consecutive_silence_timeouts: 1.0
|
|
287
|
-
- action: action_repeat_bot_messages
|
|
288
|
-
next: END
|
|
294
|
+
then: set_slots_consecutive_silence_timeouts
|
|
289
295
|
- if: "slots.consecutive_silence_timeouts = 1.0"
|
|
290
|
-
then:
|
|
291
|
-
- set_slots:
|
|
292
|
-
- consecutive_silence_timeouts: 2.0
|
|
293
|
-
- action: utter_ask_still_there
|
|
294
|
-
next: END
|
|
296
|
+
then: set_slots_consecutive_silence_timeouts_2
|
|
295
297
|
- if: "slots.consecutive_silence_timeouts > 1.0"
|
|
296
|
-
then:
|
|
297
|
-
- action: utter_inform_hangup
|
|
298
|
-
- action: action_hangup
|
|
299
|
-
next: END
|
|
298
|
+
then: message_utter_inform_hangup
|
|
300
299
|
- else: END
|
|
300
|
+
- id: set_slots_consecutive_silence_timeouts
|
|
301
|
+
set_slots:
|
|
302
|
+
- consecutive_silence_timeouts: 1.0
|
|
303
|
+
- action: action_repeat_bot_messages
|
|
304
|
+
next: END
|
|
305
|
+
- id: set_slots_consecutive_silence_timeouts_2
|
|
306
|
+
set_slots:
|
|
307
|
+
- consecutive_silence_timeouts: 2.0
|
|
308
|
+
- action: utter_ask_still_there
|
|
309
|
+
next: END
|
|
310
|
+
- id: message_utter_inform_hangup
|
|
311
|
+
action: utter_inform_hangup
|
|
312
|
+
- action: action_hangup
|
|
301
313
|
|
|
302
314
|
pattern_validate_slot:
|
|
303
315
|
description: Flow for running validations on slots
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import importlib
|
|
4
|
+
import inspect
|
|
5
|
+
import os
|
|
6
|
+
from dataclasses import fields, is_dataclass
|
|
7
|
+
from typing import Any, Dict, List, Optional, Set, Text
|
|
8
|
+
|
|
9
|
+
import importlib_resources
|
|
10
|
+
from pydantic import BaseModel, Field, ValidationInfo, field_validator
|
|
11
|
+
|
|
12
|
+
from rasa.dialogue_understanding.stack.frames.pattern_frame import PatternFlowStackFrame
|
|
13
|
+
from rasa.shared.core.constants import (
|
|
14
|
+
DEFAULT_ACTION_NAMES,
|
|
15
|
+
DEFAULT_INTENTS,
|
|
16
|
+
RULE_SNIPPET_ACTION_NAME,
|
|
17
|
+
)
|
|
18
|
+
from rasa.shared.core.slots import AnySlot, BooleanSlot, CategoricalSlot, TextSlot
|
|
19
|
+
|
|
20
|
+
ACTIONS: List[Text] = [
|
|
21
|
+
*DEFAULT_ACTION_NAMES,
|
|
22
|
+
"validate_{{context.collect}}",
|
|
23
|
+
]
|
|
24
|
+
EXCLUDED_ACTIONS: Set[Text] = {RULE_SNIPPET_ACTION_NAME}
|
|
25
|
+
|
|
26
|
+
INTENTS: List[Text] = [*DEFAULT_INTENTS]
|
|
27
|
+
|
|
28
|
+
CONTEXT_FIELD_TYPES: Dict[Text, Text] = {
|
|
29
|
+
"canceled_name": CategoricalSlot.type_name,
|
|
30
|
+
"names": CategoricalSlot.type_name,
|
|
31
|
+
"collect": CategoricalSlot.type_name,
|
|
32
|
+
"utter": CategoricalSlot.type_name,
|
|
33
|
+
"collect_action": CategoricalSlot.type_name,
|
|
34
|
+
"previous_flow_name": CategoricalSlot.type_name,
|
|
35
|
+
"reset_flow_id": CategoricalSlot.type_name,
|
|
36
|
+
"is_reset_only": BooleanSlot.type_name,
|
|
37
|
+
"canceled_frames": AnySlot.type_name,
|
|
38
|
+
"corrected_slots": AnySlot.type_name,
|
|
39
|
+
"rejections": AnySlot.type_name,
|
|
40
|
+
"info": AnySlot.type_name,
|
|
41
|
+
"reason": TextSlot.type_name,
|
|
42
|
+
"error_type": TextSlot.type_name,
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
FLOW_NAME_VALUES = "FLOW_NAME"
|
|
46
|
+
FLOW_ID_VALUES = "FLOW_ID"
|
|
47
|
+
SLOT_NAME_VALUES = "SLOT_NAME"
|
|
48
|
+
RESPONSE_NAME_VALUES = "RESPONSE_NAME"
|
|
49
|
+
ACTION_NAME_VALUES = "ACTION_NAME"
|
|
50
|
+
|
|
51
|
+
CONTEXT_FIELD_VALUES: Dict[Text, Text] = {
|
|
52
|
+
"canceled_name": FLOW_NAME_VALUES,
|
|
53
|
+
"names": FLOW_NAME_VALUES,
|
|
54
|
+
"previous_flow_name": FLOW_NAME_VALUES,
|
|
55
|
+
"reset_flow_id": FLOW_ID_VALUES,
|
|
56
|
+
"collect": SLOT_NAME_VALUES,
|
|
57
|
+
"utter": RESPONSE_NAME_VALUES,
|
|
58
|
+
"collect_action": ACTION_NAME_VALUES,
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
PATTERNS_MODULE_BASE = "rasa.dialogue_understanding.patterns"
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class ContextField(BaseModel):
|
|
65
|
+
"""Element in the `contexts` mapping of the domain."""
|
|
66
|
+
|
|
67
|
+
patterns: List[Text] = Field(
|
|
68
|
+
..., description="Patterns that reference this context field."
|
|
69
|
+
)
|
|
70
|
+
type: Text = Field(
|
|
71
|
+
..., description="Slot type (categorical, text, boolean, any …)."
|
|
72
|
+
)
|
|
73
|
+
values: Optional[List[Text]] = Field(
|
|
74
|
+
None,
|
|
75
|
+
description="Optional placeholder that restricts which values a slot can take "
|
|
76
|
+
"(FLOW_NAME, SLOT_NAME, …).",
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
@field_validator("type")
|
|
80
|
+
def _validate_slot_type(cls, v: str) -> str:
|
|
81
|
+
allowed_types = list(set(CONTEXT_FIELD_TYPES.values()))
|
|
82
|
+
if v not in allowed_types:
|
|
83
|
+
raise ValueError(
|
|
84
|
+
f"Unsupported type '{v}'. "
|
|
85
|
+
f"Must be one of: {', '.join(allowed_types)}."
|
|
86
|
+
)
|
|
87
|
+
return v
|
|
88
|
+
|
|
89
|
+
@field_validator("values")
|
|
90
|
+
def _validate_values_placeholder(
|
|
91
|
+
cls, v: Optional[str], values: ValidationInfo
|
|
92
|
+
) -> Optional[str]:
|
|
93
|
+
if v is None:
|
|
94
|
+
return v
|
|
95
|
+
|
|
96
|
+
allowed_values = set(CONTEXT_FIELD_VALUES.values())
|
|
97
|
+
if not set(v).issubset(allowed_values):
|
|
98
|
+
raise ValueError(
|
|
99
|
+
f"Unsupported values placeholder '{v}'. "
|
|
100
|
+
f"Must be one of {', '.join(allowed_values)}."
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
slot_type = values.data.get("type")
|
|
104
|
+
if slot_type != CategoricalSlot.type_name:
|
|
105
|
+
raise ValueError(
|
|
106
|
+
"`values` can only be specified for categorical slots "
|
|
107
|
+
f"(got slot type '{slot_type}')."
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
return v
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
class PatternDomain(BaseModel):
|
|
114
|
+
"""Complete domain that is generated for the default patterns."""
|
|
115
|
+
|
|
116
|
+
actions: List[Text]
|
|
117
|
+
intents: List[Text]
|
|
118
|
+
contexts: Dict[Text, ContextField]
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def build_contexts_from_patterns() -> Dict[str, Dict[str, Any]]:
|
|
122
|
+
"""Builds a dictionary of contexts from the pattern classes.
|
|
123
|
+
|
|
124
|
+
Returns:
|
|
125
|
+
A dictionary where each key is a field name and the value is a dictionary
|
|
126
|
+
"""
|
|
127
|
+
patterns_folder = str(importlib_resources.files(PATTERNS_MODULE_BASE))
|
|
128
|
+
contexts_map: Dict[str, Dict[str, Any]] = {}
|
|
129
|
+
|
|
130
|
+
# Dynamically gather all .py files
|
|
131
|
+
for root, _, files in os.walk(patterns_folder):
|
|
132
|
+
for file in files:
|
|
133
|
+
if not file.endswith(".py"):
|
|
134
|
+
continue
|
|
135
|
+
|
|
136
|
+
try:
|
|
137
|
+
module_name = f"{PATTERNS_MODULE_BASE}.{file[:-3]}"
|
|
138
|
+
module = importlib.import_module(module_name)
|
|
139
|
+
except ImportError:
|
|
140
|
+
continue
|
|
141
|
+
|
|
142
|
+
# Inspect classes in that module
|
|
143
|
+
for _, cls in inspect.getmembers(module, inspect.isclass):
|
|
144
|
+
if not is_dataclass(cls):
|
|
145
|
+
continue
|
|
146
|
+
|
|
147
|
+
# The cls has to be a subclass of PatternFlowStackFrame
|
|
148
|
+
if cls == PatternFlowStackFrame or not issubclass(
|
|
149
|
+
cls, PatternFlowStackFrame
|
|
150
|
+
):
|
|
151
|
+
continue
|
|
152
|
+
|
|
153
|
+
for f in fields(cls):
|
|
154
|
+
field_name = f.name
|
|
155
|
+
if field_name not in contexts_map:
|
|
156
|
+
field_type = CONTEXT_FIELD_TYPES.get(
|
|
157
|
+
field_name, TextSlot.type_name
|
|
158
|
+
)
|
|
159
|
+
contexts_map[field_name] = {
|
|
160
|
+
"patterns": set(),
|
|
161
|
+
"type": field_type,
|
|
162
|
+
}
|
|
163
|
+
values: Optional[Text] = CONTEXT_FIELD_VALUES.get(field_name)
|
|
164
|
+
if values:
|
|
165
|
+
contexts_map[field_name]["values"] = [values]
|
|
166
|
+
|
|
167
|
+
# Add the pattern name to the set
|
|
168
|
+
pattern_name = cls.type()
|
|
169
|
+
contexts_map[field_name]["patterns"].add(pattern_name)
|
|
170
|
+
|
|
171
|
+
# Convert "patterns" from set to list, for a clean final structure
|
|
172
|
+
for field_name, details in contexts_map.items():
|
|
173
|
+
details["patterns"] = sorted(list(details["patterns"]))
|
|
174
|
+
|
|
175
|
+
return contexts_map
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def generate_domain_for_default_patterns() -> PatternDomain:
|
|
179
|
+
"""
|
|
180
|
+
Generate the domain for pattern-based flows as a strongly-typed object.
|
|
181
|
+
|
|
182
|
+
Returns: PatternDomain Pydantic model containing actions, intents and contexts.
|
|
183
|
+
"""
|
|
184
|
+
actions = [action for action in ACTIONS if action not in EXCLUDED_ACTIONS]
|
|
185
|
+
raw_contexts = build_contexts_from_patterns()
|
|
186
|
+
contexts = {
|
|
187
|
+
field_name: ContextField(**details)
|
|
188
|
+
for field_name, details in raw_contexts.items()
|
|
189
|
+
}
|
|
190
|
+
return PatternDomain(actions=actions, intents=INTENTS, contexts=contexts)
|
|
@@ -132,7 +132,7 @@ def validate_state_of_commands(commands: List[Command]) -> None:
|
|
|
132
132
|
if sum(isinstance(c, CancelFlowCommand) for c in commands) > 1:
|
|
133
133
|
structlogger.error(
|
|
134
134
|
"command_processor.validate_state_of_commands.multiple_cancel_flow_commands",
|
|
135
|
-
commands=commands,
|
|
135
|
+
commands=[command.__class__.__name__ for command in commands],
|
|
136
136
|
)
|
|
137
137
|
raise ValueError("There can only be one cancel flow command.")
|
|
138
138
|
|
|
@@ -143,7 +143,7 @@ def validate_state_of_commands(commands: List[Command]) -> None:
|
|
|
143
143
|
if free_form_answer_commands != commands[: len(free_form_answer_commands)]:
|
|
144
144
|
structlogger.error(
|
|
145
145
|
"command_processor.validate_state_of_commands.free_form_answer_commands_not_at_beginning",
|
|
146
|
-
commands=commands,
|
|
146
|
+
commands=[command.__class__.__name__ for command in commands],
|
|
147
147
|
)
|
|
148
148
|
raise ValueError(
|
|
149
149
|
"Free form answer commands must be at start of the predicted command list."
|
|
@@ -153,7 +153,7 @@ def validate_state_of_commands(commands: List[Command]) -> None:
|
|
|
153
153
|
if sum(isinstance(c, CorrectSlotsCommand) for c in commands) > 1:
|
|
154
154
|
structlogger.error(
|
|
155
155
|
"command_processor.validate_state_of_commands.multiple_correct_slots_commands",
|
|
156
|
-
commands=commands,
|
|
156
|
+
commands=[command.__class__.__name__ for command in commands],
|
|
157
157
|
)
|
|
158
158
|
raise ValueError("There can only be one correct slots command.")
|
|
159
159
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
from typing import Any, Dict, List, Text
|
|
3
|
+
from typing import Any, Dict, List, Optional, Text
|
|
4
4
|
|
|
5
5
|
import rasa.dialogue_understanding.processor.command_processor
|
|
6
6
|
from rasa.engine.graph import ExecutionContext, GraphComponent
|
|
@@ -37,8 +37,8 @@ class CommandProcessorComponent(GraphComponent):
|
|
|
37
37
|
self,
|
|
38
38
|
tracker: DialogueStateTracker,
|
|
39
39
|
flows: FlowsList,
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
domain: Optional[Domain] = None,
|
|
41
|
+
story_graph: Optional[StoryGraph] = None,
|
|
42
42
|
) -> List[Event]:
|
|
43
43
|
"""Execute commands to update tracker state."""
|
|
44
44
|
return rasa.dialogue_understanding.processor.command_processor.execute_commands(
|
|
@@ -53,7 +53,8 @@ class FlowStackFrameType(str, Enum):
|
|
|
53
53
|
typ: The string to create the `FlowStackFrameType` from.
|
|
54
54
|
|
|
55
55
|
Returns:
|
|
56
|
-
|
|
56
|
+
The created `FlowStackFrameType`.
|
|
57
|
+
"""
|
|
57
58
|
if typ is None:
|
|
58
59
|
return FlowStackFrameType.REGULAR
|
|
59
60
|
elif typ == FlowStackFrameType.INTERRUPT.value:
|
|
@@ -107,7 +108,8 @@ class BaseFlowStackFrame(DialogueStackFrame):
|
|
|
107
108
|
all_flows: All flows in the assistant.
|
|
108
109
|
|
|
109
110
|
Returns:
|
|
110
|
-
|
|
111
|
+
The current flow.
|
|
112
|
+
"""
|
|
111
113
|
flow = all_flows.flow_by_id(self.flow_id)
|
|
112
114
|
if not flow:
|
|
113
115
|
# we shouldn't ever end up with a frame that belongs to a non
|
|
@@ -122,9 +124,20 @@ class BaseFlowStackFrame(DialogueStackFrame):
|
|
|
122
124
|
all_flows: All flows in the assistant.
|
|
123
125
|
|
|
124
126
|
Returns:
|
|
125
|
-
The current flow step.
|
|
127
|
+
The current flow step.
|
|
128
|
+
"""
|
|
126
129
|
flow = self.flow(all_flows)
|
|
127
|
-
|
|
130
|
+
|
|
131
|
+
step_id = self.step_id
|
|
132
|
+
# in 3.11.4 we added the flow_id as a prefix to the step_id
|
|
133
|
+
# this causes issues when loading old dialogues as the prefix is missing
|
|
134
|
+
# (see https://rasahq.atlassian.net/jira/software/c/projects/ENG/boards/43?selectedIssue=ENG-1939)
|
|
135
|
+
# so we try to find the step by adding the flow prefix to old step_ids as well
|
|
136
|
+
# TODO: remove this in 4.0.0
|
|
137
|
+
alternative_step_id = f"{self.flow_id}_{self.step_id}"
|
|
138
|
+
|
|
139
|
+
step = flow.step_by_id(step_id) or flow.step_by_id(alternative_step_id)
|
|
140
|
+
|
|
128
141
|
if not step:
|
|
129
142
|
# we shouldn't ever end up with a frame that belongs to a non
|
|
130
143
|
# existing step, but if we do, we should raise an error
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
from contextlib import contextmanager
|
|
2
2
|
from typing import Any, Dict, Generator, List, Optional, Text
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
import structlog
|
|
5
|
+
|
|
6
|
+
from rasa.dialogue_understanding.commands import Command, NoopCommand, SetSlotCommand
|
|
5
7
|
from rasa.dialogue_understanding.constants import (
|
|
6
8
|
RASA_RECORD_COMMANDS_AND_PROMPTS_ENV_VAR_NAME,
|
|
7
9
|
)
|
|
@@ -16,7 +18,6 @@ from rasa.shared.nlu.constants import (
|
|
|
16
18
|
KEY_USER_PROMPT,
|
|
17
19
|
PREDICTED_COMMANDS,
|
|
18
20
|
PROMPTS,
|
|
19
|
-
SET_SLOT_COMMAND,
|
|
20
21
|
)
|
|
21
22
|
from rasa.shared.nlu.training_data.message import Message
|
|
22
23
|
from rasa.shared.providers.llm.llm_response import LLMResponse
|
|
@@ -26,6 +27,8 @@ record_commands_and_prompts = get_bool_env_variable(
|
|
|
26
27
|
RASA_RECORD_COMMANDS_AND_PROMPTS_ENV_VAR_NAME, False
|
|
27
28
|
)
|
|
28
29
|
|
|
30
|
+
structlogger = structlog.get_logger()
|
|
31
|
+
|
|
29
32
|
|
|
30
33
|
@contextmanager
|
|
31
34
|
def set_record_commands_and_prompts() -> Generator:
|
|
@@ -144,21 +147,74 @@ def _handle_via_nlu_in_coexistence(
|
|
|
144
147
|
if not tracker:
|
|
145
148
|
return False
|
|
146
149
|
|
|
150
|
+
commands = message.get(COMMANDS, [])
|
|
151
|
+
|
|
152
|
+
# If coexistence routing slot is not active, this setup doesn't
|
|
153
|
+
# support dual routing -> default to CALM
|
|
147
154
|
if not tracker.has_coexistence_routing_slot:
|
|
155
|
+
structlogger.debug(
|
|
156
|
+
"utils.handle_via_nlu_in_coexistence"
|
|
157
|
+
".tracker_missing_route_session_to_calm_slot",
|
|
158
|
+
event_info=(
|
|
159
|
+
f"Tracker doesn't have the '{ROUTE_TO_CALM_SLOT}' slot."
|
|
160
|
+
f"Routing to CALM."
|
|
161
|
+
),
|
|
162
|
+
route_session_to_calm=commands,
|
|
163
|
+
)
|
|
148
164
|
return False
|
|
149
165
|
|
|
166
|
+
# Check if the routing decision is stored in the tracker slot
|
|
167
|
+
# If slot is true -> route to CALM
|
|
168
|
+
# If slot is false -> route to DM1
|
|
150
169
|
value = tracker.get_slot(ROUTE_TO_CALM_SLOT)
|
|
151
170
|
if value is not None:
|
|
171
|
+
structlogger.debug(
|
|
172
|
+
"utils.handle_via_nlu_in_coexistence"
|
|
173
|
+
".tracker_route_session_to_calm_slot_value",
|
|
174
|
+
event_info=(
|
|
175
|
+
f"Tracker slot '{ROUTE_TO_CALM_SLOT}' set to '{value}'. "
|
|
176
|
+
f"Routing to "
|
|
177
|
+
f"{'CALM' if value else 'NLU system'}."
|
|
178
|
+
),
|
|
179
|
+
route_session_to_calm_value_in_tracker=value,
|
|
180
|
+
)
|
|
152
181
|
return not value
|
|
153
182
|
|
|
154
|
-
# routing
|
|
155
|
-
#
|
|
156
|
-
if
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
183
|
+
# Non-sticky routing to DM1 is only allowed if NoopCommand is the sole predicted
|
|
184
|
+
# command. In that case, route to DM1
|
|
185
|
+
if len(commands) == 1 and commands[0].get("command") == NoopCommand.command():
|
|
186
|
+
structlogger.debug(
|
|
187
|
+
"utils.handle_via_nlu_in_coexistence.noop_command_detected",
|
|
188
|
+
event_info="NoopCommand found. Routing to NLU system non-sticky.",
|
|
189
|
+
commands=commands,
|
|
190
|
+
)
|
|
191
|
+
return True
|
|
192
|
+
|
|
193
|
+
# If the slot was reset (e.g. new session), try to infer routing from
|
|
194
|
+
# attached commands. Look for a SetSlotCommand targeting the ROUTE_TO_CALM_SLOT
|
|
195
|
+
for command in message.get(COMMANDS, []):
|
|
196
|
+
# If slot is true -> route to CALM
|
|
197
|
+
# If slot is false -> route to DM1
|
|
198
|
+
if (
|
|
199
|
+
command.get("command") == SetSlotCommand.command()
|
|
200
|
+
and command.get("name") == ROUTE_TO_CALM_SLOT
|
|
201
|
+
):
|
|
202
|
+
structlogger.debug(
|
|
203
|
+
"utils.handle_via_nlu_in_coexistence.set_slot_command_detected",
|
|
204
|
+
event_info=(
|
|
205
|
+
f"SetSlotCommand setting the '{ROUTE_TO_CALM_SLOT}' to "
|
|
206
|
+
f"'{command.get('value')}'. "
|
|
207
|
+
f"Routing to "
|
|
208
|
+
f"{'CALM' if command.get('value') else 'NLU system'}."
|
|
209
|
+
),
|
|
210
|
+
commands=commands,
|
|
211
|
+
)
|
|
212
|
+
return not command.get("value")
|
|
213
|
+
|
|
214
|
+
# If no routing info is available -> default to CALM
|
|
215
|
+
structlogger.debug(
|
|
216
|
+
"utils.handle_via_nlu_in_coexistence.no_routing_info_available",
|
|
217
|
+
event_info="No routing info available. Routing to CALM.",
|
|
218
|
+
commands=commands,
|
|
219
|
+
)
|
|
164
220
|
return False
|
|
@@ -3,9 +3,9 @@ from typing import Any, Dict, Iterator, List, Optional, Tuple
|
|
|
3
3
|
|
|
4
4
|
from pydantic import BaseModel, Field
|
|
5
5
|
|
|
6
|
-
from rasa.core import IntentlessPolicy
|
|
7
6
|
from rasa.core.nlg.contextual_response_rephraser import ContextualResponseRephraser
|
|
8
7
|
from rasa.core.policies.enterprise_search_policy import EnterpriseSearchPolicy
|
|
8
|
+
from rasa.core.policies.intentless_policy import IntentlessPolicy
|
|
9
9
|
from rasa.dialogue_understanding.commands.prompt_command import PromptCommand
|
|
10
10
|
from rasa.dialogue_understanding.generator.command_parser import parse_commands
|
|
11
11
|
from rasa.dialogue_understanding_test.command_comparison import are_command_lists_equal
|
|
@@ -5,10 +5,10 @@ from typing import Any, Dict, List, Optional, Text
|
|
|
5
5
|
import structlog
|
|
6
6
|
from tqdm import tqdm
|
|
7
7
|
|
|
8
|
+
from rasa.core.available_endpoints import AvailableEndpoints
|
|
8
9
|
from rasa.core.channels import CollectingOutputChannel, UserMessage
|
|
9
10
|
from rasa.core.exceptions import AgentNotReady
|
|
10
11
|
from rasa.core.persistor import StorageType
|
|
11
|
-
from rasa.core.utils import AvailableEndpoints
|
|
12
12
|
from rasa.dialogue_understanding.commands import Command
|
|
13
13
|
from rasa.dialogue_understanding.utils import set_record_commands_and_prompts
|
|
14
14
|
from rasa.dialogue_understanding_test.du_test_case import (
|
|
@@ -34,6 +34,7 @@ from rasa.e2e_test.e2e_test_runner import E2ETestRunner
|
|
|
34
34
|
from rasa.shared.core.events import UserUttered
|
|
35
35
|
from rasa.shared.core.trackers import DialogueStateTracker
|
|
36
36
|
from rasa.shared.nlu.constants import PREDICTED_COMMANDS, PROMPTS
|
|
37
|
+
from rasa.shared.utils.llm import create_tracker_for_user_step
|
|
37
38
|
from rasa.utils.endpoints import EndpointConfig
|
|
38
39
|
|
|
39
40
|
structlogger = structlog.get_logger()
|
|
@@ -179,8 +180,9 @@ class DialogueUnderstandingTestRunner:
|
|
|
179
180
|
# create and save the tracker at the time just
|
|
180
181
|
# before the user message was sent
|
|
181
182
|
step_sender_id = f"{sender_id}_{user_step_index}"
|
|
182
|
-
await
|
|
183
|
+
await create_tracker_for_user_step(
|
|
183
184
|
step_sender_id,
|
|
185
|
+
self.agent,
|
|
184
186
|
test_case_tracker,
|
|
185
187
|
user_uttered_event_indices[user_step_index],
|
|
186
188
|
)
|
|
@@ -289,26 +291,6 @@ class DialogueUnderstandingTestRunner:
|
|
|
289
291
|
|
|
290
292
|
return user_uttered_event
|
|
291
293
|
|
|
292
|
-
async def _create_tracker_for_user_step(
|
|
293
|
-
self,
|
|
294
|
-
step_sender_id: str,
|
|
295
|
-
test_case_tracker: DialogueStateTracker,
|
|
296
|
-
index_user_uttered_event: int,
|
|
297
|
-
) -> None:
|
|
298
|
-
"""Creates a tracker for the user step."""
|
|
299
|
-
tracker = test_case_tracker.copy()
|
|
300
|
-
# modify the sender id so that the test case tracker is not overwritten
|
|
301
|
-
tracker.sender_id = step_sender_id
|
|
302
|
-
|
|
303
|
-
if tracker.events:
|
|
304
|
-
# get timestamp of the event just before the user uttered event
|
|
305
|
-
timestamp = tracker.events[index_user_uttered_event - 1].timestamp
|
|
306
|
-
# revert the tracker to the event just before the user uttered event
|
|
307
|
-
tracker = tracker.travel_back_in_time(timestamp)
|
|
308
|
-
|
|
309
|
-
# store the tracker with the unique sender id
|
|
310
|
-
await self.agent.tracker_store.save(tracker)
|
|
311
|
-
|
|
312
294
|
async def _send_user_message(
|
|
313
295
|
self,
|
|
314
296
|
sender_id: str,
|