rasa-pro 3.11.0__py3-none-any.whl → 3.11.0a1__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.
- README.md +396 -17
- rasa/__main__.py +15 -31
- rasa/api.py +1 -5
- rasa/cli/arguments/default_arguments.py +2 -1
- rasa/cli/arguments/shell.py +1 -5
- rasa/cli/arguments/train.py +0 -14
- rasa/cli/e2e_test.py +1 -1
- rasa/cli/evaluate.py +8 -8
- rasa/cli/inspect.py +7 -15
- rasa/cli/interactive.py +0 -1
- rasa/cli/llm_fine_tuning.py +1 -1
- rasa/cli/project_templates/calm/config.yml +7 -5
- rasa/cli/project_templates/calm/endpoints.yml +2 -15
- rasa/cli/project_templates/tutorial/config.yml +5 -8
- rasa/cli/project_templates/tutorial/data/flows.yml +1 -1
- rasa/cli/project_templates/tutorial/data/patterns.yml +0 -5
- rasa/cli/project_templates/tutorial/domain.yml +0 -14
- rasa/cli/project_templates/tutorial/endpoints.yml +0 -5
- rasa/cli/run.py +1 -1
- rasa/cli/scaffold.py +2 -4
- rasa/cli/studio/studio.py +8 -18
- rasa/cli/studio/upload.py +15 -0
- rasa/cli/train.py +0 -3
- rasa/cli/utils.py +1 -6
- rasa/cli/x.py +8 -8
- rasa/constants.py +1 -3
- rasa/core/actions/action.py +33 -75
- rasa/core/actions/e2e_stub_custom_action_executor.py +1 -5
- rasa/core/actions/http_custom_action_executor.py +0 -4
- rasa/core/channels/__init__.py +0 -2
- rasa/core/channels/channel.py +0 -20
- rasa/core/channels/development_inspector.py +3 -10
- rasa/core/channels/inspector/dist/assets/{arc-bc141fb2.js → arc-86942a71.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{c4Diagram-d0fbc5ce-be2db283.js → c4Diagram-d0fbc5ce-b0290676.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{classDiagram-936ed81e-55366915.js → classDiagram-936ed81e-f6405f6e.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{classDiagram-v2-c3cb15f1-bb529518.js → classDiagram-v2-c3cb15f1-ef61ac77.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{createText-62fc7601-b0ec81d6.js → createText-62fc7601-f0411e58.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{edges-f2ad444c-6166330c.js → edges-f2ad444c-7dcc4f3b.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{erDiagram-9d236eb7-5ccc6a8e.js → erDiagram-9d236eb7-e0c092d7.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{flowDb-1972c806-fca3bfe4.js → flowDb-1972c806-fba2e3ce.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{flowDiagram-7ea5b25a-4739080f.js → flowDiagram-7ea5b25a-7a70b71a.js} +1 -1
- rasa/core/channels/inspector/dist/assets/flowDiagram-v2-855bc5b3-24a5f41a.js +1 -0
- rasa/core/channels/inspector/dist/assets/{flowchart-elk-definition-abe16c3d-7c1b0e0f.js → flowchart-elk-definition-abe16c3d-00a59b68.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{ganttDiagram-9b5ea136-772fd050.js → ganttDiagram-9b5ea136-293c91fa.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{gitGraphDiagram-99d0ae7c-8eae1dc9.js → gitGraphDiagram-99d0ae7c-07b2d68c.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{index-2c4b9a3b-f55afcdf.js → index-2c4b9a3b-bc959fbd.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{index-e7cef9de.js → index-3a8a5a28.js} +143 -143
- rasa/core/channels/inspector/dist/assets/{infoDiagram-736b4530-124d4a14.js → infoDiagram-736b4530-4a350f72.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{journeyDiagram-df861f2b-7c4fae44.js → journeyDiagram-df861f2b-af464fb7.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{layout-b9885fb6.js → layout-0071f036.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{line-7c59abb6.js → line-2f73cc83.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{linear-4776f780.js → linear-f014b4cc.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{mindmap-definition-beec6740-2332c46c.js → mindmap-definition-beec6740-d2426fb6.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{pieDiagram-dbbf0591-8fb39303.js → pieDiagram-dbbf0591-776f01a2.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{quadrantDiagram-4d7f4fd6-3c7180a2.js → quadrantDiagram-4d7f4fd6-82e00b57.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{requirementDiagram-6fc4c22a-e910bcb8.js → requirementDiagram-6fc4c22a-ea13c6bb.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{sankeyDiagram-8f13d901-ead16c89.js → sankeyDiagram-8f13d901-1feca7e9.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{sequenceDiagram-b655622a-29a02a19.js → sequenceDiagram-b655622a-070c61d2.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{stateDiagram-59f0c015-042b3137.js → stateDiagram-59f0c015-24f46263.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{stateDiagram-v2-2b26beab-2178c0f3.js → stateDiagram-v2-2b26beab-c9056051.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{styles-080da4f6-23ffa4fc.js → styles-080da4f6-08abc34a.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{styles-3dcbcfbf-94f59763.js → styles-3dcbcfbf-bc74c25a.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{styles-9c745c82-78a6bebc.js → styles-9c745c82-4e5d66de.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{svgDrawCommon-4835440b-eae2a6f6.js → svgDrawCommon-4835440b-849c4517.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{timeline-definition-5b62e21b-5c968d92.js → timeline-definition-5b62e21b-d0fb1598.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{xychartDiagram-2b33534f-fd3db0d5.js → xychartDiagram-2b33534f-04d115e2.js} +1 -1
- rasa/core/channels/inspector/dist/index.html +1 -1
- rasa/core/channels/inspector/src/App.tsx +1 -1
- rasa/core/channels/inspector/src/components/LoadingSpinner.tsx +3 -6
- rasa/core/channels/socketio.py +2 -7
- rasa/core/channels/telegram.py +1 -1
- rasa/core/channels/twilio.py +1 -1
- rasa/core/channels/voice_ready/audiocodes.py +4 -15
- rasa/core/channels/voice_ready/jambonz.py +4 -15
- rasa/core/channels/voice_ready/twilio_voice.py +21 -6
- rasa/core/channels/voice_ready/utils.py +5 -6
- rasa/core/channels/voice_stream/asr/asr_engine.py +1 -19
- rasa/core/channels/voice_stream/asr/asr_event.py +0 -5
- rasa/core/channels/voice_stream/asr/deepgram.py +15 -28
- rasa/core/channels/voice_stream/audio_bytes.py +0 -1
- rasa/core/channels/voice_stream/tts/azure.py +3 -9
- rasa/core/channels/voice_stream/tts/cartesia.py +8 -12
- rasa/core/channels/voice_stream/tts/tts_engine.py +1 -11
- rasa/core/channels/voice_stream/twilio_media_streams.py +19 -28
- rasa/core/channels/voice_stream/util.py +4 -4
- rasa/core/channels/voice_stream/voice_channel.py +42 -222
- rasa/core/featurizers/single_state_featurizer.py +1 -22
- rasa/core/featurizers/tracker_featurizers.py +18 -115
- rasa/core/information_retrieval/qdrant.py +0 -1
- rasa/core/nlg/contextual_response_rephraser.py +25 -44
- rasa/core/persistor.py +34 -191
- rasa/core/policies/enterprise_search_policy.py +60 -119
- rasa/core/policies/flows/flow_executor.py +4 -7
- rasa/core/policies/intentless_policy.py +22 -82
- rasa/core/policies/ted_policy.py +33 -58
- rasa/core/policies/unexpected_intent_policy.py +7 -15
- rasa/core/processor.py +13 -89
- rasa/core/run.py +2 -2
- rasa/core/training/interactive.py +35 -34
- rasa/core/utils.py +22 -58
- rasa/dialogue_understanding/coexistence/llm_based_router.py +12 -39
- rasa/dialogue_understanding/commands/__init__.py +0 -4
- rasa/dialogue_understanding/commands/change_flow_command.py +0 -6
- rasa/dialogue_understanding/commands/utils.py +0 -5
- rasa/dialogue_understanding/generator/constants.py +0 -2
- rasa/dialogue_understanding/generator/flow_retrieval.py +4 -49
- rasa/dialogue_understanding/generator/llm_based_command_generator.py +23 -37
- rasa/dialogue_understanding/generator/multi_step/multi_step_llm_command_generator.py +10 -57
- rasa/dialogue_understanding/generator/nlu_command_adapter.py +1 -19
- rasa/dialogue_understanding/generator/single_step/command_prompt_template.jinja2 +0 -3
- rasa/dialogue_understanding/generator/single_step/single_step_llm_command_generator.py +10 -90
- rasa/dialogue_understanding/patterns/default_flows_for_patterns.yml +0 -53
- rasa/dialogue_understanding/processor/command_processor.py +1 -21
- rasa/e2e_test/assertions.py +16 -133
- rasa/e2e_test/assertions_schema.yml +0 -23
- rasa/e2e_test/e2e_test_case.py +6 -85
- rasa/e2e_test/e2e_test_runner.py +4 -6
- rasa/e2e_test/utils/io.py +1 -3
- rasa/engine/loader.py +0 -12
- rasa/engine/validation.py +11 -541
- rasa/keys +1 -0
- rasa/llm_fine_tuning/notebooks/unsloth_finetuning.ipynb +407 -0
- rasa/model_training.py +7 -29
- rasa/nlu/classifiers/diet_classifier.py +25 -38
- rasa/nlu/classifiers/logistic_regression_classifier.py +9 -22
- rasa/nlu/classifiers/sklearn_intent_classifier.py +16 -37
- rasa/nlu/extractors/crf_entity_extractor.py +50 -93
- rasa/nlu/featurizers/sparse_featurizer/count_vectors_featurizer.py +16 -45
- rasa/nlu/featurizers/sparse_featurizer/lexical_syntactic_featurizer.py +17 -52
- rasa/nlu/featurizers/sparse_featurizer/regex_featurizer.py +3 -5
- rasa/nlu/tokenizers/whitespace_tokenizer.py +14 -3
- rasa/server.py +1 -3
- rasa/shared/constants.py +0 -61
- rasa/shared/core/constants.py +0 -9
- rasa/shared/core/domain.py +5 -8
- rasa/shared/core/flows/flow.py +0 -5
- rasa/shared/core/flows/flows_list.py +1 -5
- rasa/shared/core/flows/flows_yaml_schema.json +0 -10
- rasa/shared/core/flows/validation.py +0 -96
- rasa/shared/core/flows/yaml_flows_io.py +4 -13
- rasa/shared/core/slots.py +0 -5
- rasa/shared/importers/importer.py +2 -19
- rasa/shared/importers/rasa.py +1 -5
- rasa/shared/nlu/training_data/features.py +2 -120
- rasa/shared/nlu/training_data/formats/rasa_yaml.py +3 -18
- rasa/shared/providers/_configs/azure_openai_client_config.py +3 -5
- rasa/shared/providers/_configs/openai_client_config.py +1 -1
- rasa/shared/providers/_configs/self_hosted_llm_client_config.py +0 -1
- rasa/shared/providers/_configs/utils.py +0 -16
- rasa/shared/providers/embedding/_base_litellm_embedding_client.py +29 -18
- rasa/shared/providers/embedding/azure_openai_embedding_client.py +21 -54
- rasa/shared/providers/embedding/default_litellm_embedding_client.py +0 -24
- rasa/shared/providers/llm/_base_litellm_client.py +31 -63
- rasa/shared/providers/llm/azure_openai_llm_client.py +29 -50
- rasa/shared/providers/llm/default_litellm_llm_client.py +0 -24
- rasa/shared/providers/llm/self_hosted_llm_client.py +29 -17
- rasa/shared/providers/mappings.py +0 -19
- rasa/shared/utils/common.py +2 -37
- rasa/shared/utils/io.py +6 -28
- rasa/shared/utils/llm.py +46 -353
- rasa/shared/utils/yaml.py +82 -181
- rasa/studio/auth.py +5 -3
- rasa/studio/config.py +4 -13
- rasa/studio/constants.py +0 -1
- rasa/studio/data_handler.py +4 -13
- rasa/studio/upload.py +80 -175
- rasa/telemetry.py +17 -94
- rasa/tracing/config.py +1 -3
- rasa/tracing/instrumentation/attribute_extractors.py +17 -94
- rasa/tracing/instrumentation/instrumentation.py +0 -121
- rasa/utils/common.py +0 -5
- rasa/utils/endpoints.py +1 -27
- rasa/utils/io.py +81 -7
- rasa/utils/log_utils.py +2 -9
- rasa/utils/tensorflow/model_data.py +193 -2
- rasa/validator.py +4 -110
- rasa/version.py +1 -1
- rasa_pro-3.11.0a1.dist-info/METADATA +576 -0
- {rasa_pro-3.11.0.dist-info → rasa_pro-3.11.0a1.dist-info}/RECORD +182 -216
- rasa/core/actions/action_repeat_bot_messages.py +0 -89
- rasa/core/channels/inspector/dist/assets/flowDiagram-v2-855bc5b3-736177bf.js +0 -1
- rasa/core/channels/inspector/src/helpers/audiostream.ts +0 -165
- rasa/core/channels/voice_stream/asr/azure.py +0 -129
- rasa/core/channels/voice_stream/browser_audio.py +0 -107
- rasa/core/channels/voice_stream/call_state.py +0 -23
- rasa/dialogue_understanding/commands/repeat_bot_messages_command.py +0 -60
- rasa/dialogue_understanding/commands/user_silence_command.py +0 -59
- rasa/dialogue_understanding/patterns/repeat.py +0 -37
- rasa/dialogue_understanding/patterns/user_silence.py +0 -37
- rasa/model_manager/__init__.py +0 -0
- rasa/model_manager/config.py +0 -40
- rasa/model_manager/model_api.py +0 -559
- rasa/model_manager/runner_service.py +0 -286
- rasa/model_manager/socket_bridge.py +0 -146
- rasa/model_manager/studio_jwt_auth.py +0 -86
- rasa/model_manager/trainer_service.py +0 -325
- rasa/model_manager/utils.py +0 -87
- rasa/model_manager/warm_rasa_process.py +0 -187
- rasa/model_service.py +0 -112
- rasa/shared/core/flows/utils.py +0 -39
- rasa/shared/providers/_configs/litellm_router_client_config.py +0 -220
- rasa/shared/providers/_configs/model_group_config.py +0 -167
- rasa/shared/providers/_configs/rasa_llm_client_config.py +0 -73
- rasa/shared/providers/_utils.py +0 -79
- rasa/shared/providers/embedding/litellm_router_embedding_client.py +0 -135
- rasa/shared/providers/llm/litellm_router_llm_client.py +0 -182
- rasa/shared/providers/llm/rasa_llm_client.py +0 -112
- rasa/shared/providers/router/__init__.py +0 -0
- rasa/shared/providers/router/_base_litellm_router_client.py +0 -183
- rasa/shared/providers/router/router_client.py +0 -73
- rasa/shared/utils/health_check/__init__.py +0 -0
- rasa/shared/utils/health_check/embeddings_health_check_mixin.py +0 -31
- rasa/shared/utils/health_check/health_check.py +0 -258
- rasa/shared/utils/health_check/llm_health_check_mixin.py +0 -31
- rasa/utils/sanic_error_handler.py +0 -32
- rasa/utils/tensorflow/feature_array.py +0 -366
- rasa_pro-3.11.0.dist-info/METADATA +0 -198
- {rasa_pro-3.11.0.dist-info → rasa_pro-3.11.0a1.dist-info}/NOTICE +0 -0
- {rasa_pro-3.11.0.dist-info → rasa_pro-3.11.0a1.dist-info}/WHEEL +0 -0
- {rasa_pro-3.11.0.dist-info → rasa_pro-3.11.0a1.dist-info}/entry_points.txt +0 -0
|
@@ -24,7 +24,6 @@ from rasa.dialogue_understanding.generator.constants import (
|
|
|
24
24
|
LLM_CONFIG_KEY,
|
|
25
25
|
USER_INPUT_CONFIG_KEY,
|
|
26
26
|
FLOW_RETRIEVAL_KEY,
|
|
27
|
-
DEFAULT_LLM_CONFIG,
|
|
28
27
|
)
|
|
29
28
|
from rasa.dialogue_understanding.generator.flow_retrieval import FlowRetrieval
|
|
30
29
|
from rasa.dialogue_understanding.generator.llm_based_command_generator import (
|
|
@@ -40,10 +39,7 @@ from rasa.engine.graph import ExecutionContext
|
|
|
40
39
|
from rasa.engine.recipes.default_recipe import DefaultV1Recipe
|
|
41
40
|
from rasa.engine.storage.resource import Resource
|
|
42
41
|
from rasa.engine.storage.storage import ModelStorage
|
|
43
|
-
from rasa.shared.constants import
|
|
44
|
-
RASA_PATTERN_CANNOT_HANDLE_NOT_SUPPORTED,
|
|
45
|
-
EMBEDDINGS_CONFIG_KEY,
|
|
46
|
-
)
|
|
42
|
+
from rasa.shared.constants import RASA_PATTERN_CANNOT_HANDLE_NOT_SUPPORTED
|
|
47
43
|
from rasa.shared.constants import ROUTE_TO_CALM_SLOT
|
|
48
44
|
from rasa.shared.core.flows import FlowStep, Flow, FlowsList
|
|
49
45
|
from rasa.shared.core.flows.steps.collect import CollectInformationFlowStep
|
|
@@ -57,7 +53,6 @@ from rasa.shared.utils.llm import (
|
|
|
57
53
|
tracker_as_readable_transcript,
|
|
58
54
|
sanitize_message_for_prompt,
|
|
59
55
|
allowed_values_for_slot,
|
|
60
|
-
resolve_model_client_config,
|
|
61
56
|
)
|
|
62
57
|
|
|
63
58
|
# multistep template keys
|
|
@@ -75,7 +70,6 @@ DEFAULT_HANDLE_FLOWS_TEMPLATE = importlib.resources.read_text(
|
|
|
75
70
|
DEFAULT_FILL_SLOTS_TEMPLATE = importlib.resources.read_text(
|
|
76
71
|
"rasa.dialogue_understanding.generator.multi_step", "fill_slots_prompt.jinja2"
|
|
77
72
|
).strip()
|
|
78
|
-
MULTI_STEP_LLM_COMMAND_GENERATOR_CONFIG_FILE = "config.json"
|
|
79
73
|
|
|
80
74
|
# dictionary of template names and associated file names and default values
|
|
81
75
|
PROMPT_TEMPLATES = {
|
|
@@ -144,18 +138,7 @@ class MultiStepLLMCommandGenerator(LLMBasedCommandGenerator):
|
|
|
144
138
|
**kwargs: Any,
|
|
145
139
|
) -> "MultiStepLLMCommandGenerator":
|
|
146
140
|
"""Loads trained component (see parent class for full docstring)."""
|
|
147
|
-
|
|
148
|
-
# Perform health check of the LLM client config
|
|
149
|
-
llm_config = resolve_model_client_config(config.get(LLM_CONFIG_KEY, {}))
|
|
150
|
-
cls.perform_llm_health_check(
|
|
151
|
-
llm_config,
|
|
152
|
-
DEFAULT_LLM_CONFIG,
|
|
153
|
-
"multi_step_llm_command_generator.load",
|
|
154
|
-
MultiStepLLMCommandGenerator.__name__,
|
|
155
|
-
)
|
|
156
|
-
|
|
157
141
|
prompts = cls._load_prompt_templates(model_storage, resource)
|
|
158
|
-
|
|
159
142
|
# init base command generator
|
|
160
143
|
command_generator = cls(config, model_storage, resource, prompts)
|
|
161
144
|
# load flow retrieval if enabled
|
|
@@ -163,13 +146,13 @@ class MultiStepLLMCommandGenerator(LLMBasedCommandGenerator):
|
|
|
163
146
|
command_generator.flow_retrieval = cls.load_flow_retrival(
|
|
164
147
|
command_generator.config, model_storage, resource
|
|
165
148
|
)
|
|
166
|
-
|
|
167
149
|
return command_generator
|
|
168
150
|
|
|
169
151
|
def persist(self) -> None:
|
|
170
152
|
"""Persist this component to disk for future loading."""
|
|
153
|
+
# persist prompt template
|
|
171
154
|
self._persist_prompt_templates()
|
|
172
|
-
|
|
155
|
+
# persist flow retrieval
|
|
173
156
|
if self.flow_retrieval is not None:
|
|
174
157
|
self.flow_retrieval.persist()
|
|
175
158
|
|
|
@@ -246,9 +229,9 @@ class MultiStepLLMCommandGenerator(LLMBasedCommandGenerator):
|
|
|
246
229
|
commands: List[Command] = []
|
|
247
230
|
|
|
248
231
|
slot_set_re = re.compile(
|
|
249
|
-
r"""SetSlot\(
|
|
232
|
+
r"""SetSlot\((\"?[a-zA-Z_][a-zA-Z0-9_-]*?\"?), ?(.*)\)"""
|
|
250
233
|
)
|
|
251
|
-
start_flow_re = re.compile(r"StartFlow\(
|
|
234
|
+
start_flow_re = re.compile(r"StartFlow\(([a-zA-Z0-9_-]+?)\)")
|
|
252
235
|
change_flow_re = re.compile(r"ChangeFlow\(\)")
|
|
253
236
|
cancel_flow_re = re.compile(r"CancelFlow\(\)")
|
|
254
237
|
chitchat_re = re.compile(r"ChitChat\(\)")
|
|
@@ -297,19 +280,9 @@ class MultiStepLLMCommandGenerator(LLMBasedCommandGenerator):
|
|
|
297
280
|
commands.append(HumanHandoffCommand())
|
|
298
281
|
elif match := clarify_re.search(action):
|
|
299
282
|
options = sorted([opt.strip() for opt in match.group(1).split(",")])
|
|
300
|
-
# Remove surrounding quotes if present
|
|
301
|
-
cleaned_options = []
|
|
302
|
-
for flow in options:
|
|
303
|
-
if (flow.startswith('"') and flow.endswith('"')) or (
|
|
304
|
-
flow.startswith("'") and flow.endswith("'")
|
|
305
|
-
):
|
|
306
|
-
cleaned_options.append(flow[1:-1])
|
|
307
|
-
else:
|
|
308
|
-
cleaned_options.append(flow)
|
|
309
|
-
# check if flow is valid
|
|
310
283
|
valid_options = [
|
|
311
284
|
flow
|
|
312
|
-
for flow in
|
|
285
|
+
for flow in options
|
|
313
286
|
if flow in flows.user_flow_ids
|
|
314
287
|
and flow not in user_flows_on_the_stack(tracker.stack)
|
|
315
288
|
]
|
|
@@ -320,13 +293,6 @@ class MultiStepLLMCommandGenerator(LLMBasedCommandGenerator):
|
|
|
320
293
|
elif change_flow_re.search(action):
|
|
321
294
|
commands.append(ChangeFlowCommand())
|
|
322
295
|
|
|
323
|
-
if not commands:
|
|
324
|
-
structlogger.debug(
|
|
325
|
-
"multi_step_llm_command_generator.parse_commands",
|
|
326
|
-
message="No commands were parsed from the LLM actions.",
|
|
327
|
-
actions=actions,
|
|
328
|
-
)
|
|
329
|
-
|
|
330
296
|
return commands
|
|
331
297
|
|
|
332
298
|
### Helper methods
|
|
@@ -402,13 +368,6 @@ class MultiStepLLMCommandGenerator(LLMBasedCommandGenerator):
|
|
|
402
368
|
file_path = path / file_name
|
|
403
369
|
rasa.shared.utils.io.write_text_file(template, file_path)
|
|
404
370
|
|
|
405
|
-
def _persist_config(self) -> None:
|
|
406
|
-
"""Persist config as a source of truth for resolved clients."""
|
|
407
|
-
with self._model_storage.write_to(self._resource) as path:
|
|
408
|
-
rasa.shared.utils.io.dump_obj_as_json_to_file(
|
|
409
|
-
path / MULTI_STEP_LLM_COMMAND_GENERATOR_CONFIG_FILE, self.config
|
|
410
|
-
)
|
|
411
|
-
|
|
412
371
|
async def _predict_commands_with_multi_step(
|
|
413
372
|
self,
|
|
414
373
|
message: Message,
|
|
@@ -802,17 +761,11 @@ class MultiStepLLMCommandGenerator(LLMBasedCommandGenerator):
|
|
|
802
761
|
.get(FILE_PATH_KEY),
|
|
803
762
|
DEFAULT_FILL_SLOTS_TEMPLATE,
|
|
804
763
|
)
|
|
805
|
-
|
|
806
|
-
llm_config = resolve_model_client_config(
|
|
807
|
-
config.get(LLM_CONFIG_KEY), MultiStepLLMCommandGenerator.__name__
|
|
808
|
-
)
|
|
809
|
-
embedding_config = resolve_model_client_config(
|
|
810
|
-
config.get(FLOW_RETRIEVAL_KEY, {}).get(EMBEDDINGS_CONFIG_KEY),
|
|
811
|
-
FlowRetrieval.__name__,
|
|
812
|
-
)
|
|
813
|
-
|
|
814
764
|
return deep_container_fingerprint(
|
|
815
|
-
[
|
|
765
|
+
[
|
|
766
|
+
handle_flows_template,
|
|
767
|
+
fill_slots_template,
|
|
768
|
+
]
|
|
816
769
|
)
|
|
817
770
|
|
|
818
771
|
@staticmethod
|
|
@@ -19,7 +19,6 @@ from rasa.engine.storage.storage import ModelStorage
|
|
|
19
19
|
from rasa.shared.constants import ROUTE_TO_CALM_SLOT
|
|
20
20
|
from rasa.shared.core.domain import Domain
|
|
21
21
|
from rasa.shared.core.flows.flows_list import FlowsList
|
|
22
|
-
from rasa.shared.core.flows.steps import CollectInformationFlowStep
|
|
23
22
|
from rasa.shared.core.slot_mappings import (
|
|
24
23
|
SlotFillingManager,
|
|
25
24
|
extract_slot_value,
|
|
@@ -218,24 +217,7 @@ def _issue_set_slot_commands(
|
|
|
218
217
|
commands: List[Command] = []
|
|
219
218
|
domain = domain if domain else Domain.empty()
|
|
220
219
|
slot_filling_manager = SlotFillingManager(domain, tracker, message)
|
|
221
|
-
|
|
222
|
-
# only use slots that don't have ask_before_filling set to True
|
|
223
|
-
available_slot_names = flows.available_slot_names(ask_before_filling=False)
|
|
224
|
-
|
|
225
|
-
# check if the current step is a CollectInformationFlowStep
|
|
226
|
-
# in case it has ask_before_filling set to True, we need to add the
|
|
227
|
-
# slot to the available_slot_names
|
|
228
|
-
if tracker.active_flow:
|
|
229
|
-
flow = flows.flow_by_id(tracker.active_flow)
|
|
230
|
-
step_id = tracker.current_step_id
|
|
231
|
-
if flow is not None:
|
|
232
|
-
current_step = flow.step_by_id(step_id)
|
|
233
|
-
if (
|
|
234
|
-
current_step
|
|
235
|
-
and isinstance(current_step, CollectInformationFlowStep)
|
|
236
|
-
and current_step.ask_before_filling
|
|
237
|
-
):
|
|
238
|
-
available_slot_names.add(current_step.collect)
|
|
220
|
+
available_slot_names = flows.available_slot_names()
|
|
239
221
|
|
|
240
222
|
for _, slot in tracker.slots.items():
|
|
241
223
|
# if a slot is not collected in available flows,
|
|
@@ -41,9 +41,6 @@ Based on this information generate a list of actions you want to take. Your job
|
|
|
41
41
|
* Responding to knowledge-oriented user messages, described by "SearchAndReply()"
|
|
42
42
|
* Responding to a casual, non-task-oriented user message, described by "ChitChat()".
|
|
43
43
|
* Handing off to a human, in case the user seems frustrated or explicitly asks to speak to one, described by "HumanHandoff()".
|
|
44
|
-
{% if is_repeat_command_enabled %}
|
|
45
|
-
* Repeat the last bot messages, described by "RepeatLastBotMessages()". This is useful when the user asks to repeat the last bot messages.
|
|
46
|
-
{% endif %}
|
|
47
44
|
|
|
48
45
|
===
|
|
49
46
|
Write out the actions you want to take, one per line, in the order they should take place.
|
|
@@ -16,13 +16,11 @@ from rasa.dialogue_understanding.commands import (
|
|
|
16
16
|
KnowledgeAnswerCommand,
|
|
17
17
|
ClarifyCommand,
|
|
18
18
|
CannotHandleCommand,
|
|
19
|
-
RepeatBotMessagesCommand,
|
|
20
19
|
)
|
|
21
20
|
from rasa.dialogue_understanding.generator.constants import (
|
|
22
21
|
LLM_CONFIG_KEY,
|
|
23
22
|
USER_INPUT_CONFIG_KEY,
|
|
24
23
|
FLOW_RETRIEVAL_KEY,
|
|
25
|
-
DEFAULT_LLM_CONFIG,
|
|
26
24
|
)
|
|
27
25
|
from rasa.dialogue_understanding.generator.flow_retrieval import (
|
|
28
26
|
FlowRetrieval,
|
|
@@ -39,7 +37,6 @@ from rasa.shared.constants import (
|
|
|
39
37
|
ROUTE_TO_CALM_SLOT,
|
|
40
38
|
PROMPT_CONFIG_KEY,
|
|
41
39
|
PROMPT_TEMPLATE_CONFIG_KEY,
|
|
42
|
-
EMBEDDINGS_CONFIG_KEY,
|
|
43
40
|
)
|
|
44
41
|
from rasa.shared.core.flows import FlowsList
|
|
45
42
|
from rasa.shared.core.trackers import DialogueStateTracker
|
|
@@ -51,9 +48,7 @@ from rasa.shared.utils.llm import (
|
|
|
51
48
|
get_prompt_template,
|
|
52
49
|
tracker_as_readable_transcript,
|
|
53
50
|
sanitize_message_for_prompt,
|
|
54
|
-
resolve_model_client_config,
|
|
55
51
|
)
|
|
56
|
-
from rasa.utils.beta import ensure_beta_feature_is_enabled, BetaNotEnabledException
|
|
57
52
|
from rasa.utils.log_utils import log_llm
|
|
58
53
|
|
|
59
54
|
COMMAND_PROMPT_FILE_NAME = "command_prompt.jinja2"
|
|
@@ -62,7 +57,6 @@ DEFAULT_COMMAND_PROMPT_TEMPLATE = importlib.resources.read_text(
|
|
|
62
57
|
"rasa.dialogue_understanding.generator.single_step",
|
|
63
58
|
"command_prompt_template.jinja2",
|
|
64
59
|
)
|
|
65
|
-
SINGLE_STEP_LLM_COMMAND_GENERATOR_CONFIG_FILE = "config.json"
|
|
66
60
|
|
|
67
61
|
structlogger = structlog.get_logger()
|
|
68
62
|
|
|
@@ -113,7 +107,6 @@ class SingleStepLLMCommandGenerator(LLMBasedCommandGenerator):
|
|
|
113
107
|
)
|
|
114
108
|
|
|
115
109
|
self.trace_prompt_tokens = self.config.get("trace_prompt_tokens", False)
|
|
116
|
-
self.repeat_command_enabled = self.is_repeat_command_enabled()
|
|
117
110
|
|
|
118
111
|
### Implementations of LLMBasedCommandGenerator parent
|
|
119
112
|
@staticmethod
|
|
@@ -137,21 +130,10 @@ class SingleStepLLMCommandGenerator(LLMBasedCommandGenerator):
|
|
|
137
130
|
**kwargs: Any,
|
|
138
131
|
) -> "SingleStepLLMCommandGenerator":
|
|
139
132
|
"""Loads trained component (see parent class for full docstring)."""
|
|
140
|
-
|
|
141
|
-
# Perform health check of the LLM API endpoint
|
|
142
|
-
llm_config = resolve_model_client_config(config.get(LLM_CONFIG_KEY, {}))
|
|
143
|
-
cls.perform_llm_health_check(
|
|
144
|
-
llm_config,
|
|
145
|
-
DEFAULT_LLM_CONFIG,
|
|
146
|
-
"single_step_llm_command_generator.load",
|
|
147
|
-
SingleStepLLMCommandGenerator.__name__,
|
|
148
|
-
)
|
|
149
|
-
|
|
150
133
|
# load prompt template from the model storage.
|
|
151
134
|
prompt_template = cls.load_prompt_template_from_model_storage(
|
|
152
135
|
model_storage, resource, COMMAND_PROMPT_FILE_NAME
|
|
153
136
|
)
|
|
154
|
-
|
|
155
137
|
# init base command generator
|
|
156
138
|
command_generator = cls(config, model_storage, resource, prompt_template)
|
|
157
139
|
# load flow retrieval if enabled
|
|
@@ -159,29 +141,18 @@ class SingleStepLLMCommandGenerator(LLMBasedCommandGenerator):
|
|
|
159
141
|
command_generator.flow_retrieval = cls.load_flow_retrival(
|
|
160
142
|
command_generator.config, model_storage, resource
|
|
161
143
|
)
|
|
162
|
-
|
|
163
144
|
return command_generator
|
|
164
145
|
|
|
165
146
|
def persist(self) -> None:
|
|
166
147
|
"""Persist this component to disk for future loading."""
|
|
167
|
-
|
|
168
|
-
self._persist_config()
|
|
169
|
-
if self.flow_retrieval is not None:
|
|
170
|
-
self.flow_retrieval.persist()
|
|
171
|
-
|
|
172
|
-
def _persist_prompt_template(self) -> None:
|
|
173
|
-
"""Persist prompt template for future loading."""
|
|
148
|
+
# persist prompt template
|
|
174
149
|
with self._model_storage.write_to(self._resource) as path:
|
|
175
150
|
rasa.shared.utils.io.write_text_file(
|
|
176
151
|
self.prompt_template, path / COMMAND_PROMPT_FILE_NAME
|
|
177
152
|
)
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
with self._model_storage.write_to(self._resource) as path:
|
|
182
|
-
rasa.shared.utils.io.dump_obj_as_json_to_file(
|
|
183
|
-
path / SINGLE_STEP_LLM_COMMAND_GENERATOR_CONFIG_FILE, self.config
|
|
184
|
-
)
|
|
153
|
+
# persist flow retrieval
|
|
154
|
+
if self.flow_retrieval is not None:
|
|
155
|
+
self.flow_retrieval.persist()
|
|
185
156
|
|
|
186
157
|
async def predict_commands(
|
|
187
158
|
self,
|
|
@@ -214,12 +185,6 @@ class SingleStepLLMCommandGenerator(LLMBasedCommandGenerator):
|
|
|
214
185
|
|
|
215
186
|
if not commands:
|
|
216
187
|
# no commands are parsed or there's an invalid command
|
|
217
|
-
structlogger.warning(
|
|
218
|
-
"single_step_llm_command_generator.predict_commands",
|
|
219
|
-
message="No commands were predicted as the LLM response could "
|
|
220
|
-
"not be parsed or the LLM responded with an invalid command."
|
|
221
|
-
"Returning a CannotHandleCommand instead.",
|
|
222
|
-
)
|
|
223
188
|
commands = [CannotHandleCommand()]
|
|
224
189
|
|
|
225
190
|
if tracker.has_coexistence_routing_slot:
|
|
@@ -320,17 +285,14 @@ class SingleStepLLMCommandGenerator(LLMBasedCommandGenerator):
|
|
|
320
285
|
|
|
321
286
|
commands: List[Command] = []
|
|
322
287
|
|
|
323
|
-
slot_set_re = re.compile(
|
|
324
|
-
|
|
325
|
-
)
|
|
326
|
-
start_flow_re = re.compile(r"StartFlow\(['\"]?([a-zA-Z0-9_-]+)['\"]?\)")
|
|
288
|
+
slot_set_re = re.compile(r"""SetSlot\(([a-zA-Z_][a-zA-Z0-9_-]*?), ?(.*)\)""")
|
|
289
|
+
start_flow_re = re.compile(r"StartFlow\(([a-zA-Z0-9_-]+?)\)")
|
|
327
290
|
cancel_flow_re = re.compile(r"CancelFlow\(\)")
|
|
328
291
|
chitchat_re = re.compile(r"ChitChat\(\)")
|
|
329
292
|
skip_question_re = re.compile(r"SkipQuestion\(\)")
|
|
330
293
|
knowledge_re = re.compile(r"SearchAndReply\(\)")
|
|
331
294
|
humand_handoff_re = re.compile(r"HumanHandoff\(\)")
|
|
332
|
-
clarify_re = re.compile(r"Clarify\(([
|
|
333
|
-
repeat_re = re.compile(r"RepeatLastBotMessages\(\)")
|
|
295
|
+
clarify_re = re.compile(r"Clarify\(([a-zA-Z0-9_, ]+)\)")
|
|
334
296
|
|
|
335
297
|
for action in actions.strip().splitlines():
|
|
336
298
|
if match := slot_set_re.search(action):
|
|
@@ -357,40 +319,21 @@ class SingleStepLLMCommandGenerator(LLMBasedCommandGenerator):
|
|
|
357
319
|
commands.append(KnowledgeAnswerCommand())
|
|
358
320
|
elif humand_handoff_re.search(action):
|
|
359
321
|
commands.append(HumanHandoffCommand())
|
|
360
|
-
elif repeat_re.search(action):
|
|
361
|
-
commands.append(RepeatBotMessagesCommand())
|
|
362
322
|
elif match := clarify_re.search(action):
|
|
363
323
|
options = sorted([opt.strip() for opt in match.group(1).split(",")])
|
|
364
|
-
# Remove surrounding quotes if present
|
|
365
|
-
cleaned_options = []
|
|
366
|
-
for flow in options:
|
|
367
|
-
if (flow.startswith('"') and flow.endswith('"')) or (
|
|
368
|
-
flow.startswith("'") and flow.endswith("'")
|
|
369
|
-
):
|
|
370
|
-
cleaned_options.append(flow[1:-1])
|
|
371
|
-
else:
|
|
372
|
-
cleaned_options.append(flow)
|
|
373
|
-
# check if flow is valid
|
|
374
324
|
valid_options = [
|
|
375
|
-
flow for flow in
|
|
325
|
+
flow for flow in options if flow in flows.user_flow_ids
|
|
376
326
|
]
|
|
377
327
|
if len(set(valid_options)) == 1:
|
|
378
328
|
commands.extend(cls.start_flow_by_name(valid_options[0], flows))
|
|
379
329
|
elif len(valid_options) > 1:
|
|
380
330
|
commands.append(ClarifyCommand(valid_options))
|
|
381
331
|
|
|
382
|
-
if not commands:
|
|
383
|
-
structlogger.debug(
|
|
384
|
-
"single_step_llm_command_generator.parse_commands",
|
|
385
|
-
message="No commands were parsed from the LLM actions.",
|
|
386
|
-
actions=actions,
|
|
387
|
-
)
|
|
388
|
-
|
|
389
332
|
return commands
|
|
390
333
|
|
|
391
334
|
@classmethod
|
|
392
335
|
def fingerprint_addon(cls: Any, config: Dict[str, Any]) -> Optional[str]:
|
|
393
|
-
"""Add a fingerprint for the graph."""
|
|
336
|
+
"""Add a fingerprint of the knowledge base for the graph."""
|
|
394
337
|
config_prompt = (
|
|
395
338
|
config.get(PROMPT_CONFIG_KEY)
|
|
396
339
|
or config.get(PROMPT_TEMPLATE_CONFIG_KEY)
|
|
@@ -400,16 +343,7 @@ class SingleStepLLMCommandGenerator(LLMBasedCommandGenerator):
|
|
|
400
343
|
config_prompt,
|
|
401
344
|
DEFAULT_COMMAND_PROMPT_TEMPLATE,
|
|
402
345
|
)
|
|
403
|
-
|
|
404
|
-
config.get(LLM_CONFIG_KEY), SingleStepLLMCommandGenerator.__name__
|
|
405
|
-
)
|
|
406
|
-
embedding_config = resolve_model_client_config(
|
|
407
|
-
config.get(FLOW_RETRIEVAL_KEY, {}).get(EMBEDDINGS_CONFIG_KEY),
|
|
408
|
-
FlowRetrieval.__name__,
|
|
409
|
-
)
|
|
410
|
-
return deep_container_fingerprint(
|
|
411
|
-
[prompt_template, llm_config, embedding_config]
|
|
412
|
-
)
|
|
346
|
+
return deep_container_fingerprint(prompt_template)
|
|
413
347
|
|
|
414
348
|
### Helper methods
|
|
415
349
|
def render_template(
|
|
@@ -459,20 +393,6 @@ class SingleStepLLMCommandGenerator(LLMBasedCommandGenerator):
|
|
|
459
393
|
"current_slot": current_slot,
|
|
460
394
|
"current_slot_description": current_slot_description,
|
|
461
395
|
"user_message": latest_user_message,
|
|
462
|
-
"is_repeat_command_enabled": self.repeat_command_enabled,
|
|
463
396
|
}
|
|
464
397
|
|
|
465
398
|
return self.compile_template(self.prompt_template).render(**inputs)
|
|
466
|
-
|
|
467
|
-
def is_repeat_command_enabled(self) -> bool:
|
|
468
|
-
"""Check for feature flag"""
|
|
469
|
-
RASA_PRO_BETA_REPEAT_COMMAND_ENV_VAR_NAME = "RASA_PRO_BETA_REPEAT_COMMAND"
|
|
470
|
-
try:
|
|
471
|
-
ensure_beta_feature_is_enabled(
|
|
472
|
-
"Repeat Command",
|
|
473
|
-
env_flag=RASA_PRO_BETA_REPEAT_COMMAND_ENV_VAR_NAME,
|
|
474
|
-
)
|
|
475
|
-
except BetaNotEnabledException:
|
|
476
|
-
return False
|
|
477
|
-
|
|
478
|
-
return True
|
|
@@ -4,11 +4,6 @@ responses:
|
|
|
4
4
|
utter_ask_rephrase:
|
|
5
5
|
- text: I’m sorry I am unable to understand you, could you please rephrase?
|
|
6
6
|
|
|
7
|
-
utter_ask_still_there:
|
|
8
|
-
- text: "Hello, are you still there?"
|
|
9
|
-
metadata:
|
|
10
|
-
rephrase: True
|
|
11
|
-
|
|
12
7
|
utter_boolean_slot_rejection:
|
|
13
8
|
- text: "Sorry, the value you provided, `{{value}}`, is not valid. Please respond with a valid value."
|
|
14
9
|
metadata:
|
|
@@ -80,11 +75,6 @@ responses:
|
|
|
80
75
|
metadata:
|
|
81
76
|
rephrase: True
|
|
82
77
|
|
|
83
|
-
utter_inform_hangup:
|
|
84
|
-
- text: It seems you are not there anymore. I will hang up shortly.
|
|
85
|
-
metadata:
|
|
86
|
-
rephrase: True
|
|
87
|
-
|
|
88
78
|
utter_internal_error_rasa:
|
|
89
79
|
- text: Sorry, I am having trouble with that. Please try again in a few minutes.
|
|
90
80
|
|
|
@@ -111,15 +101,6 @@ slots:
|
|
|
111
101
|
type: bool
|
|
112
102
|
mappings:
|
|
113
103
|
- type: from_llm
|
|
114
|
-
silence_timeout:
|
|
115
|
-
type: float
|
|
116
|
-
initial_value: 6.0
|
|
117
|
-
max_value: 1000000
|
|
118
|
-
consecutive_silence_timeouts:
|
|
119
|
-
type: float
|
|
120
|
-
initial_value: 0.0
|
|
121
|
-
max_value: 1000000
|
|
122
|
-
|
|
123
104
|
|
|
124
105
|
flows:
|
|
125
106
|
pattern_cancel_flow:
|
|
@@ -236,11 +217,6 @@ flows:
|
|
|
236
217
|
- action: utter_internal_error_rasa
|
|
237
218
|
next: END
|
|
238
219
|
|
|
239
|
-
pattern_repeat_bot_messages:
|
|
240
|
-
description: Voice conversation repair pattern to repeat bot messages
|
|
241
|
-
name: pattern repeat bot messages
|
|
242
|
-
steps:
|
|
243
|
-
- action: action_repeat_bot_messages
|
|
244
220
|
|
|
245
221
|
pattern_restart:
|
|
246
222
|
description: Flow for restarting the conversation
|
|
@@ -270,32 +246,3 @@ flows:
|
|
|
270
246
|
name: pattern skip question
|
|
271
247
|
steps:
|
|
272
248
|
- action: utter_skip_question_answer
|
|
273
|
-
|
|
274
|
-
pattern_user_silence:
|
|
275
|
-
description: Reacting to user silence in voice bots
|
|
276
|
-
name: pattern react to silence
|
|
277
|
-
nlu_trigger:
|
|
278
|
-
- intent: silence_timeout
|
|
279
|
-
persisted_slots:
|
|
280
|
-
- consecutive_silence_timeouts
|
|
281
|
-
steps:
|
|
282
|
-
- noop: true
|
|
283
|
-
next:
|
|
284
|
-
- if: "slots.consecutive_silence_timeouts = 0.0"
|
|
285
|
-
then:
|
|
286
|
-
- set_slots:
|
|
287
|
-
- consecutive_silence_timeouts: 1.0
|
|
288
|
-
- action: action_repeat_bot_messages
|
|
289
|
-
next: END
|
|
290
|
-
- if: "slots.consecutive_silence_timeouts = 1.0"
|
|
291
|
-
then:
|
|
292
|
-
- set_slots:
|
|
293
|
-
- consecutive_silence_timeouts: 2.0
|
|
294
|
-
- action: utter_ask_still_there
|
|
295
|
-
next: END
|
|
296
|
-
- if: "slots.consecutive_silence_timeouts > 1.0"
|
|
297
|
-
then:
|
|
298
|
-
- action: utter_inform_hangup
|
|
299
|
-
- action: action_hangup
|
|
300
|
-
next: END
|
|
301
|
-
- else: END
|
|
@@ -8,7 +8,6 @@ from rasa.dialogue_understanding.commands import (
|
|
|
8
8
|
Command,
|
|
9
9
|
CorrectSlotsCommand,
|
|
10
10
|
CorrectedSlot,
|
|
11
|
-
RepeatBotMessagesCommand,
|
|
12
11
|
SetSlotCommand,
|
|
13
12
|
StartFlowCommand,
|
|
14
13
|
FreeFormAnswerCommand,
|
|
@@ -423,9 +422,6 @@ def clean_up_commands(
|
|
|
423
422
|
elif not tracker.has_coexistence_routing_slot and len(clean_commands) > 1:
|
|
424
423
|
clean_commands = filter_cannot_handle_command_for_skipped_slots(clean_commands)
|
|
425
424
|
|
|
426
|
-
clean_commands = ensure_max_number_of_command_type(
|
|
427
|
-
clean_commands, RepeatBotMessagesCommand, 1
|
|
428
|
-
)
|
|
429
425
|
structlogger.debug(
|
|
430
426
|
"command_processor.clean_up_commands.final_commands",
|
|
431
427
|
command=clean_commands,
|
|
@@ -434,22 +430,6 @@ def clean_up_commands(
|
|
|
434
430
|
return clean_commands
|
|
435
431
|
|
|
436
432
|
|
|
437
|
-
def ensure_max_number_of_command_type(
|
|
438
|
-
commands: List[Command], command_type: Type[Command], n: int
|
|
439
|
-
) -> List[Command]:
|
|
440
|
-
"""Ensures that for a given command type only the first n stay in the list."""
|
|
441
|
-
filtered: List[Command] = []
|
|
442
|
-
count = 0
|
|
443
|
-
for c in commands:
|
|
444
|
-
if isinstance(c, command_type):
|
|
445
|
-
if count >= n:
|
|
446
|
-
continue
|
|
447
|
-
else:
|
|
448
|
-
count += 1
|
|
449
|
-
filtered.append(c)
|
|
450
|
-
return filtered
|
|
451
|
-
|
|
452
|
-
|
|
453
433
|
def clean_up_clarify_command(
|
|
454
434
|
commands_so_far: List[Command],
|
|
455
435
|
all_commands: List[Command],
|
|
@@ -472,7 +452,7 @@ def clean_up_clarify_command(
|
|
|
472
452
|
if not (isinstance(c, SetSlotCommand) and c.name == ROUTE_TO_CALM_SLOT)
|
|
473
453
|
]
|
|
474
454
|
|
|
475
|
-
# if
|
|
455
|
+
# if there are multiple clarify commands, do add the first one
|
|
476
456
|
if all(
|
|
477
457
|
isinstance(c, ClarifyCommand) for c in commands_without_route_to_calm_set_slot
|
|
478
458
|
):
|