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
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import logging
|
|
2
1
|
from abc import abstractmethod
|
|
3
2
|
from typing import Dict, List, Any, Union
|
|
4
3
|
|
|
4
|
+
import logging
|
|
5
5
|
import structlog
|
|
6
6
|
from litellm import (
|
|
7
7
|
completion,
|
|
@@ -9,7 +9,6 @@ from litellm import (
|
|
|
9
9
|
validate_environment,
|
|
10
10
|
)
|
|
11
11
|
|
|
12
|
-
from rasa.shared.constants import API_BASE_CONFIG_KEY, API_KEY
|
|
13
12
|
from rasa.shared.exceptions import (
|
|
14
13
|
ProviderClientAPIException,
|
|
15
14
|
ProviderClientValidationError,
|
|
@@ -19,7 +18,7 @@ from rasa.shared.providers._ssl_verification_utils import (
|
|
|
19
18
|
ensure_ssl_certificates_for_litellm_openai_based_clients,
|
|
20
19
|
)
|
|
21
20
|
from rasa.shared.providers.llm.llm_response import LLMResponse, LLMUsage
|
|
22
|
-
from rasa.shared.utils.io import suppress_logs
|
|
21
|
+
from rasa.shared.utils.io import suppress_logs
|
|
23
22
|
|
|
24
23
|
structlogger = structlog.get_logger()
|
|
25
24
|
|
|
@@ -30,7 +29,8 @@ logging.getLogger("LiteLLM").setLevel(logging.WARNING)
|
|
|
30
29
|
|
|
31
30
|
|
|
32
31
|
class _BaseLiteLLMClient:
|
|
33
|
-
"""
|
|
32
|
+
"""
|
|
33
|
+
An abstract base class for LiteLLM clients.
|
|
34
34
|
|
|
35
35
|
This class defines the interface and common functionality for all clients
|
|
36
36
|
based on LiteLLM.
|
|
@@ -99,14 +99,11 @@ class _BaseLiteLLMClient:
|
|
|
99
99
|
ProviderClientValidationError if validation fails.
|
|
100
100
|
"""
|
|
101
101
|
self._validate_environment_variables()
|
|
102
|
+
self._validate_api_key_not_in_config()
|
|
102
103
|
|
|
103
104
|
def _validate_environment_variables(self) -> None:
|
|
104
105
|
"""Validate that the required environment variables are set."""
|
|
105
|
-
validation_info = validate_environment(
|
|
106
|
-
self._litellm_model_name,
|
|
107
|
-
api_key=self._litellm_extra_parameters.get(API_KEY),
|
|
108
|
-
api_base=self._litellm_extra_parameters.get(API_BASE_CONFIG_KEY),
|
|
109
|
-
)
|
|
106
|
+
validation_info = validate_environment(self._litellm_model_name)
|
|
110
107
|
if missing_environment_variables := validation_info.get(
|
|
111
108
|
_VALIDATE_ENVIRONMENT_MISSING_KEYS_KEY
|
|
112
109
|
):
|
|
@@ -121,65 +118,61 @@ class _BaseLiteLLMClient:
|
|
|
121
118
|
)
|
|
122
119
|
raise ProviderClientValidationError(event_info)
|
|
123
120
|
|
|
121
|
+
def _validate_api_key_not_in_config(self) -> None:
|
|
122
|
+
if "api_key" in self._litellm_extra_parameters:
|
|
123
|
+
event_info = (
|
|
124
|
+
"API Key is set through `api_key` extra parameter."
|
|
125
|
+
"Set API keys through environment variables."
|
|
126
|
+
)
|
|
127
|
+
structlogger.error(
|
|
128
|
+
"base_litellm_client.validate_api_key_not_in_config",
|
|
129
|
+
event_info=event_info,
|
|
130
|
+
)
|
|
131
|
+
raise ProviderClientValidationError(event_info)
|
|
132
|
+
|
|
124
133
|
@suppress_logs(log_level=logging.WARNING)
|
|
125
134
|
def completion(self, messages: Union[List[str], str]) -> LLMResponse:
|
|
126
|
-
"""
|
|
135
|
+
"""
|
|
136
|
+
Synchronously generate completions for given list of messages.
|
|
127
137
|
|
|
128
138
|
Args:
|
|
129
139
|
messages: List of messages or a single message to generate the
|
|
130
140
|
completion for.
|
|
131
|
-
|
|
132
141
|
Returns:
|
|
133
142
|
List of message completions.
|
|
134
|
-
|
|
135
143
|
Raises:
|
|
136
144
|
ProviderClientAPIException: If the API request fails.
|
|
137
145
|
"""
|
|
138
146
|
try:
|
|
139
147
|
formatted_messages = self._format_messages(messages)
|
|
140
|
-
|
|
141
|
-
|
|
148
|
+
response = completion(
|
|
149
|
+
messages=formatted_messages, **self._completion_fn_args
|
|
150
|
+
)
|
|
142
151
|
return self._format_response(response)
|
|
143
152
|
except Exception as e:
|
|
144
153
|
raise ProviderClientAPIException(e)
|
|
145
154
|
|
|
146
155
|
@suppress_logs(log_level=logging.WARNING)
|
|
147
156
|
async def acompletion(self, messages: Union[List[str], str]) -> LLMResponse:
|
|
148
|
-
"""
|
|
157
|
+
"""
|
|
158
|
+
Asynchronously generate completions for given list of messages.
|
|
149
159
|
|
|
150
160
|
Args:
|
|
151
161
|
messages: List of messages or a single message to generate the
|
|
152
162
|
completion for.
|
|
153
|
-
|
|
154
163
|
Returns:
|
|
155
164
|
List of message completions.
|
|
156
|
-
|
|
157
165
|
Raises:
|
|
158
166
|
ProviderClientAPIException: If the API request fails.
|
|
159
167
|
"""
|
|
160
168
|
try:
|
|
161
169
|
formatted_messages = self._format_messages(messages)
|
|
162
|
-
|
|
163
|
-
|
|
170
|
+
response = await acompletion(
|
|
171
|
+
messages=formatted_messages, **self._completion_fn_args
|
|
172
|
+
)
|
|
164
173
|
return self._format_response(response)
|
|
165
174
|
except Exception as e:
|
|
166
|
-
|
|
167
|
-
from rasa.shared.providers.llm.self_hosted_llm_client import (
|
|
168
|
-
SelfHostedLLMClient,
|
|
169
|
-
)
|
|
170
|
-
|
|
171
|
-
if isinstance(self, SelfHostedLLMClient):
|
|
172
|
-
message = (
|
|
173
|
-
"If you are using 'provider=self-hosted' to call a hosted vllm "
|
|
174
|
-
"server make sure your config is correctly setup. You should have "
|
|
175
|
-
"the following mandatory keys in your config: "
|
|
176
|
-
"provider=self-hosted; "
|
|
177
|
-
"model='<your-vllm-model-name>'; "
|
|
178
|
-
"api_base='your-hosted-vllm-serv'."
|
|
179
|
-
"In case you are getting OpenAI connection errors, such as missing "
|
|
180
|
-
"API key, your configuration is incorrect."
|
|
181
|
-
)
|
|
182
|
-
raise ProviderClientAPIException(e, message)
|
|
175
|
+
raise ProviderClientAPIException(e)
|
|
183
176
|
|
|
184
177
|
def _format_messages(self, messages: Union[List[str], str]) -> List[Dict[str, str]]:
|
|
185
178
|
"""Formats messages (or a single message) to OpenAI format."""
|
|
@@ -221,35 +214,10 @@ class _BaseLiteLLMClient:
|
|
|
221
214
|
)
|
|
222
215
|
return formatted_response
|
|
223
216
|
|
|
224
|
-
def _format_text_completion_response(self, response: Any) -> LLMResponse:
|
|
225
|
-
"""Parses the LiteLLM text completion response to Rasa format."""
|
|
226
|
-
formatted_response = LLMResponse(
|
|
227
|
-
id=response.id,
|
|
228
|
-
created=response.created,
|
|
229
|
-
choices=[choice.text for choice in response.choices],
|
|
230
|
-
model=response.model,
|
|
231
|
-
)
|
|
232
|
-
if (usage := response.usage) is not None:
|
|
233
|
-
prompt_tokens = (
|
|
234
|
-
num_tokens
|
|
235
|
-
if isinstance(num_tokens := usage.prompt_tokens, (int, float))
|
|
236
|
-
else 0
|
|
237
|
-
)
|
|
238
|
-
completion_tokens = (
|
|
239
|
-
num_tokens
|
|
240
|
-
if isinstance(num_tokens := usage.completion_tokens, (int, float))
|
|
241
|
-
else 0
|
|
242
|
-
)
|
|
243
|
-
formatted_response.usage = LLMUsage(prompt_tokens, completion_tokens)
|
|
244
|
-
structlogger.debug(
|
|
245
|
-
"base_litellm_client.formatted_response",
|
|
246
|
-
formatted_response=formatted_response.to_dict(),
|
|
247
|
-
)
|
|
248
|
-
return formatted_response
|
|
249
|
-
|
|
250
217
|
@staticmethod
|
|
251
218
|
def _ensure_certificates() -> None:
|
|
252
|
-
"""
|
|
219
|
+
"""
|
|
220
|
+
Configures SSL certificates for LiteLLM. This method is invoked during
|
|
253
221
|
client initialization.
|
|
254
222
|
|
|
255
223
|
LiteLLM may utilize `openai` clients or other providers that require
|
|
@@ -17,7 +17,6 @@ from rasa.shared.constants import (
|
|
|
17
17
|
OPENAI_API_KEY_ENV_VAR,
|
|
18
18
|
AZURE_API_TYPE_ENV_VAR,
|
|
19
19
|
AZURE_OPENAI_PROVIDER,
|
|
20
|
-
API_KEY,
|
|
21
20
|
)
|
|
22
21
|
from rasa.shared.exceptions import ProviderClientValidationError
|
|
23
22
|
from rasa.shared.providers._configs.azure_openai_client_config import (
|
|
@@ -30,7 +29,8 @@ structlogger = structlog.get_logger()
|
|
|
30
29
|
|
|
31
30
|
|
|
32
31
|
class AzureOpenAILLMClient(_BaseLiteLLMClient):
|
|
33
|
-
"""
|
|
32
|
+
"""
|
|
33
|
+
A client for interfacing with Azure's OpenAI LLM deployments.
|
|
34
34
|
|
|
35
35
|
Parameters:
|
|
36
36
|
deployment (str): The deployment name.
|
|
@@ -80,7 +80,11 @@ class AzureOpenAILLMClient(_BaseLiteLLMClient):
|
|
|
80
80
|
or os.getenv(OPENAI_API_VERSION_ENV_VAR)
|
|
81
81
|
)
|
|
82
82
|
|
|
83
|
-
|
|
83
|
+
# API key can be set through OPENAI_API_KEY too,
|
|
84
|
+
# because of the backward compatibility
|
|
85
|
+
self._api_key = os.getenv(AZURE_API_KEY_ENV_VAR) or os.getenv(
|
|
86
|
+
OPENAI_API_KEY_ENV_VAR
|
|
87
|
+
)
|
|
84
88
|
|
|
85
89
|
# Not used by LiteLLM, here for backward compatibility
|
|
86
90
|
self._api_type = (
|
|
@@ -113,6 +117,11 @@ class AzureOpenAILLMClient(_BaseLiteLLMClient):
|
|
|
113
117
|
"env_var": AZURE_API_VERSION_ENV_VAR,
|
|
114
118
|
"deprecated_var": OPENAI_API_VERSION_ENV_VAR,
|
|
115
119
|
},
|
|
120
|
+
"API Key": {
|
|
121
|
+
"current_value": self._api_key,
|
|
122
|
+
"env_var": AZURE_API_KEY_ENV_VAR,
|
|
123
|
+
"deprecated_var": OPENAI_API_KEY_ENV_VAR,
|
|
124
|
+
},
|
|
116
125
|
}
|
|
117
126
|
|
|
118
127
|
deprecation_warning_message = (
|
|
@@ -145,51 +154,10 @@ class AzureOpenAILLMClient(_BaseLiteLLMClient):
|
|
|
145
154
|
)
|
|
146
155
|
raise_deprecation_warning(message=message)
|
|
147
156
|
|
|
148
|
-
def _resolve_api_key_env_var(self) -> str:
|
|
149
|
-
"""Resolves the environment variable to use for the API key.
|
|
150
|
-
|
|
151
|
-
Returns:
|
|
152
|
-
str: The env variable in dollar syntax format to use for the API key.
|
|
153
|
-
"""
|
|
154
|
-
if API_KEY in self._extra_parameters:
|
|
155
|
-
# API key is set to an env var in the config itself
|
|
156
|
-
# in case the model is defined in the endpoints.yml
|
|
157
|
-
return self._extra_parameters[API_KEY]
|
|
158
|
-
|
|
159
|
-
if os.getenv(AZURE_API_KEY_ENV_VAR) is not None:
|
|
160
|
-
return "${AZURE_API_KEY}"
|
|
161
|
-
|
|
162
|
-
if os.getenv(OPENAI_API_KEY_ENV_VAR) is not None:
|
|
163
|
-
# API key can be set through OPENAI_API_KEY too,
|
|
164
|
-
# because of the backward compatibility
|
|
165
|
-
raise_deprecation_warning(
|
|
166
|
-
message=(
|
|
167
|
-
f"Usage of '{OPENAI_API_KEY_ENV_VAR}' environment variable "
|
|
168
|
-
"for setting the API key for Azure OpenAI "
|
|
169
|
-
"client is deprecated and will be removed "
|
|
170
|
-
f"in 4.0.0. Please use '{AZURE_API_KEY_ENV_VAR}' "
|
|
171
|
-
"environment variable."
|
|
172
|
-
)
|
|
173
|
-
)
|
|
174
|
-
return "${OPENAI_API_KEY}"
|
|
175
|
-
|
|
176
|
-
structlogger.error(
|
|
177
|
-
"azure_openai_llm_client.api_key_not_set",
|
|
178
|
-
event_info=(
|
|
179
|
-
"API key not set, it is required for API calls. "
|
|
180
|
-
f"Set it either via the environment variable"
|
|
181
|
-
f"'{AZURE_API_KEY_ENV_VAR}' or directly"
|
|
182
|
-
f"via the config key '{API_KEY}'."
|
|
183
|
-
),
|
|
184
|
-
)
|
|
185
|
-
raise ProviderClientValidationError(
|
|
186
|
-
f"Missing required environment variable/config key '{API_KEY}' for "
|
|
187
|
-
f"API calls."
|
|
188
|
-
)
|
|
189
|
-
|
|
190
157
|
@classmethod
|
|
191
158
|
def from_config(cls, config: Dict[str, Any]) -> "AzureOpenAILLMClient":
|
|
192
|
-
"""
|
|
159
|
+
"""
|
|
160
|
+
Initializes the client from given configuration.
|
|
193
161
|
|
|
194
162
|
Args:
|
|
195
163
|
config (Dict[str, Any]): Configuration.
|
|
@@ -244,17 +212,23 @@ class AzureOpenAILLMClient(_BaseLiteLLMClient):
|
|
|
244
212
|
|
|
245
213
|
@property
|
|
246
214
|
def model(self) -> Optional[str]:
|
|
247
|
-
"""
|
|
215
|
+
"""
|
|
216
|
+
Returns the name of the model deployed on Azure.
|
|
217
|
+
"""
|
|
248
218
|
return self._model
|
|
249
219
|
|
|
250
220
|
@property
|
|
251
221
|
def api_base(self) -> Optional[str]:
|
|
252
|
-
"""
|
|
222
|
+
"""
|
|
223
|
+
Returns the API base URL for the Azure OpenAI llm client.
|
|
224
|
+
"""
|
|
253
225
|
return self._api_base
|
|
254
226
|
|
|
255
227
|
@property
|
|
256
228
|
def api_version(self) -> Optional[str]:
|
|
257
|
-
"""
|
|
229
|
+
"""
|
|
230
|
+
Returns the API version for the Azure OpenAI llm client.
|
|
231
|
+
"""
|
|
258
232
|
return self._api_version
|
|
259
233
|
|
|
260
234
|
@property
|
|
@@ -287,7 +261,7 @@ class AzureOpenAILLMClient(_BaseLiteLLMClient):
|
|
|
287
261
|
{
|
|
288
262
|
"api_base": self.api_base,
|
|
289
263
|
"api_version": self.api_version,
|
|
290
|
-
"api_key": self.
|
|
264
|
+
"api_key": self._api_key,
|
|
291
265
|
}
|
|
292
266
|
)
|
|
293
267
|
return fn_args
|
|
@@ -331,6 +305,11 @@ class AzureOpenAILLMClient(_BaseLiteLLMClient):
|
|
|
331
305
|
"env_var": None,
|
|
332
306
|
"config_key": DEPLOYMENT_CONFIG_KEY,
|
|
333
307
|
},
|
|
308
|
+
"API Key": {
|
|
309
|
+
"current_value": self._api_key,
|
|
310
|
+
"env_var": AZURE_API_KEY_ENV_VAR,
|
|
311
|
+
"config_key": None,
|
|
312
|
+
},
|
|
334
313
|
}
|
|
335
314
|
|
|
336
315
|
missing_settings = [
|
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
from typing import Dict, Any
|
|
2
2
|
|
|
3
|
-
from rasa.shared.constants import (
|
|
4
|
-
AWS_BEDROCK_PROVIDER,
|
|
5
|
-
AWS_SAGEMAKER_PROVIDER,
|
|
6
|
-
)
|
|
7
3
|
from rasa.shared.providers._configs.default_litellm_client_config import (
|
|
8
4
|
DefaultLiteLLMClientConfig,
|
|
9
5
|
)
|
|
10
|
-
from rasa.shared.providers._utils import validate_aws_setup_for_litellm_clients
|
|
11
6
|
from rasa.shared.providers.llm._base_litellm_client import _BaseLiteLLMClient
|
|
12
7
|
|
|
13
8
|
|
|
@@ -87,22 +82,3 @@ class DefaultLiteLLMClient(_BaseLiteLLMClient):
|
|
|
87
82
|
to the client provider and deployed model.
|
|
88
83
|
"""
|
|
89
84
|
return self._extra_parameters
|
|
90
|
-
|
|
91
|
-
def validate_client_setup(self) -> None:
|
|
92
|
-
# TODO: Temporarily change the environment variable validation for AWS setup
|
|
93
|
-
# (Bedrock and SageMaker) until resolved by either:
|
|
94
|
-
# 1. An update from the LiteLLM package addressing the issue.
|
|
95
|
-
# 2. The implementation of a Bedrock client on our end.
|
|
96
|
-
# ---
|
|
97
|
-
# This fix ensures a consistent user experience for Bedrock (and
|
|
98
|
-
# SageMaker) in Rasa by allowing AWS secrets to be provided as extra
|
|
99
|
-
# parameters without triggering validation errors due to missing AWS
|
|
100
|
-
# environment variables.
|
|
101
|
-
if self.provider.lower() in [AWS_BEDROCK_PROVIDER, AWS_SAGEMAKER_PROVIDER]:
|
|
102
|
-
validate_aws_setup_for_litellm_clients(
|
|
103
|
-
self._litellm_model_name,
|
|
104
|
-
self._litellm_extra_parameters,
|
|
105
|
-
"default_litellm_llm_client",
|
|
106
|
-
)
|
|
107
|
-
else:
|
|
108
|
-
super().validate_client_setup()
|
|
@@ -4,20 +4,15 @@ from litellm import (
|
|
|
4
4
|
atext_completion,
|
|
5
5
|
)
|
|
6
6
|
import logging
|
|
7
|
-
import os
|
|
8
7
|
import structlog
|
|
9
8
|
|
|
10
|
-
from rasa.shared.constants import
|
|
11
|
-
SELF_HOSTED_VLLM_PREFIX,
|
|
12
|
-
SELF_HOSTED_VLLM_API_KEY_ENV_VAR,
|
|
13
|
-
API_KEY,
|
|
14
|
-
)
|
|
9
|
+
from rasa.shared.constants import OPENAI_PROVIDER
|
|
15
10
|
from rasa.shared.providers._configs.self_hosted_llm_client_config import (
|
|
16
11
|
SelfHostedLLMClientConfig,
|
|
17
12
|
)
|
|
18
13
|
from rasa.shared.exceptions import ProviderClientAPIException
|
|
19
14
|
from rasa.shared.providers.llm._base_litellm_client import _BaseLiteLLMClient
|
|
20
|
-
from rasa.shared.providers.llm.llm_response import LLMResponse
|
|
15
|
+
from rasa.shared.providers.llm.llm_response import LLMResponse, LLMUsage
|
|
21
16
|
from rasa.shared.utils.io import suppress_logs
|
|
22
17
|
|
|
23
18
|
structlogger = structlog.get_logger()
|
|
@@ -62,8 +57,6 @@ class SelfHostedLLMClient(_BaseLiteLLMClient):
|
|
|
62
57
|
self._api_version = api_version
|
|
63
58
|
self._use_chat_completions_endpoint = use_chat_completions_endpoint
|
|
64
59
|
self._extra_parameters = kwargs or {}
|
|
65
|
-
if self._extra_parameters.get(API_KEY) is None:
|
|
66
|
-
self._apply_dummy_api_key_if_missing()
|
|
67
60
|
|
|
68
61
|
@classmethod
|
|
69
62
|
def from_config(cls, config: Dict[str, Any]) -> "SelfHostedLLMClient":
|
|
@@ -162,10 +155,10 @@ class SelfHostedLLMClient(_BaseLiteLLMClient):
|
|
|
162
155
|
"""Returns the value of LiteLLM's model parameter to be used in
|
|
163
156
|
completion/acompletion in LiteLLM format:
|
|
164
157
|
|
|
165
|
-
<
|
|
158
|
+
<openai>/<model or deployment name>
|
|
166
159
|
"""
|
|
167
|
-
if self.model and f"{
|
|
168
|
-
return f"{
|
|
160
|
+
if self.model and f"{OPENAI_PROVIDER}/" not in self.model:
|
|
161
|
+
return f"{OPENAI_PROVIDER}/{self.model}"
|
|
169
162
|
return self.model
|
|
170
163
|
|
|
171
164
|
@property
|
|
@@ -261,9 +254,28 @@ class SelfHostedLLMClient(_BaseLiteLLMClient):
|
|
|
261
254
|
return super().completion(messages)
|
|
262
255
|
return self._text_completion(messages)
|
|
263
256
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
257
|
+
def _format_text_completion_response(self, response: Any) -> LLMResponse:
|
|
258
|
+
"""Parses the LiteLLM text completion response to Rasa format."""
|
|
259
|
+
formatted_response = LLMResponse(
|
|
260
|
+
id=response.id,
|
|
261
|
+
created=response.created,
|
|
262
|
+
choices=[choice.text for choice in response.choices],
|
|
263
|
+
model=response.model,
|
|
264
|
+
)
|
|
265
|
+
if (usage := response.usage) is not None:
|
|
266
|
+
prompt_tokens = (
|
|
267
|
+
num_tokens
|
|
268
|
+
if isinstance(num_tokens := usage.prompt_tokens, (int, float))
|
|
269
|
+
else 0
|
|
269
270
|
)
|
|
271
|
+
completion_tokens = (
|
|
272
|
+
num_tokens
|
|
273
|
+
if isinstance(num_tokens := usage.completion_tokens, (int, float))
|
|
274
|
+
else 0
|
|
275
|
+
)
|
|
276
|
+
formatted_response.usage = LLMUsage(prompt_tokens, completion_tokens)
|
|
277
|
+
structlogger.debug(
|
|
278
|
+
"base_litellm_client.formatted_response",
|
|
279
|
+
formatted_response=formatted_response.to_dict(),
|
|
280
|
+
)
|
|
281
|
+
return formatted_response
|
|
@@ -5,8 +5,6 @@ from rasa.shared.constants import (
|
|
|
5
5
|
HUGGINGFACE_LOCAL_EMBEDDING_PROVIDER,
|
|
6
6
|
OPENAI_PROVIDER,
|
|
7
7
|
SELF_HOSTED_PROVIDER,
|
|
8
|
-
RASA_PROVIDER,
|
|
9
|
-
SELF_HOSTED_VLLM_PREFIX,
|
|
10
8
|
)
|
|
11
9
|
from rasa.shared.providers.embedding.azure_openai_embedding_client import (
|
|
12
10
|
AzureOpenAIEmbeddingClient,
|
|
@@ -26,7 +24,6 @@ from rasa.shared.providers.llm.default_litellm_llm_client import DefaultLiteLLMC
|
|
|
26
24
|
from rasa.shared.providers.llm.llm_client import LLMClient
|
|
27
25
|
from rasa.shared.providers.llm.openai_llm_client import OpenAILLMClient
|
|
28
26
|
from rasa.shared.providers.llm.self_hosted_llm_client import SelfHostedLLMClient
|
|
29
|
-
from rasa.shared.providers.llm.rasa_llm_client import RasaLLMClient
|
|
30
27
|
from rasa.shared.providers._configs.azure_openai_client_config import (
|
|
31
28
|
AzureOpenAIClientConfig,
|
|
32
29
|
)
|
|
@@ -40,15 +37,12 @@ from rasa.shared.providers._configs.openai_client_config import OpenAIClientConf
|
|
|
40
37
|
from rasa.shared.providers._configs.self_hosted_llm_client_config import (
|
|
41
38
|
SelfHostedLLMClientConfig,
|
|
42
39
|
)
|
|
43
|
-
from rasa.shared.providers._configs.rasa_llm_client_config import RasaLLMClientConfig
|
|
44
|
-
|
|
45
40
|
from rasa.shared.providers._configs.client_config import ClientConfig
|
|
46
41
|
|
|
47
42
|
_provider_to_llm_client_mapping: Dict[str, Type[LLMClient]] = {
|
|
48
43
|
OPENAI_PROVIDER: OpenAILLMClient,
|
|
49
44
|
AZURE_OPENAI_PROVIDER: AzureOpenAILLMClient,
|
|
50
45
|
SELF_HOSTED_PROVIDER: SelfHostedLLMClient,
|
|
51
|
-
RASA_PROVIDER: RasaLLMClient,
|
|
52
46
|
}
|
|
53
47
|
|
|
54
48
|
_provider_to_embedding_client_mapping: Dict[str, Type[EmbeddingClient]] = {
|
|
@@ -62,15 +56,6 @@ _provider_to_client_config_class_mapping: Dict[str, Type] = {
|
|
|
62
56
|
AZURE_OPENAI_PROVIDER: AzureOpenAIClientConfig,
|
|
63
57
|
HUGGINGFACE_LOCAL_EMBEDDING_PROVIDER: HuggingFaceLocalEmbeddingClientConfig,
|
|
64
58
|
SELF_HOSTED_PROVIDER: SelfHostedLLMClientConfig,
|
|
65
|
-
RASA_PROVIDER: RasaLLMClientConfig,
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
_provider_to_prefix_mapping: Dict[str, str] = {
|
|
70
|
-
# Specify the provider name as the key and its corresponding prefix as the value
|
|
71
|
-
# for providers where the prefix differs from the provider name.
|
|
72
|
-
SELF_HOSTED_PROVIDER: SELF_HOSTED_VLLM_PREFIX,
|
|
73
|
-
RASA_PROVIDER: OPENAI_PROVIDER,
|
|
74
59
|
}
|
|
75
60
|
|
|
76
61
|
|
|
@@ -88,7 +73,3 @@ def get_client_config_class_from_provider(provider: str) -> Type[ClientConfig]:
|
|
|
88
73
|
return _provider_to_client_config_class_mapping.get(
|
|
89
74
|
provider, DefaultLiteLLMClientConfig
|
|
90
75
|
)
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
def get_prefix_from_provider(provider: str) -> str:
|
|
94
|
-
return _provider_to_prefix_mapping.get(provider, provider)
|
rasa/shared/utils/common.py
CHANGED
|
@@ -3,16 +3,14 @@ import functools
|
|
|
3
3
|
import importlib
|
|
4
4
|
import inspect
|
|
5
5
|
import logging
|
|
6
|
-
import os
|
|
7
6
|
import pkgutil
|
|
8
7
|
import sys
|
|
9
8
|
from types import ModuleType
|
|
10
|
-
from typing import
|
|
9
|
+
from typing import Text, Dict, Optional, Any, List, Callable, Collection, Type
|
|
11
10
|
|
|
12
11
|
import rasa.shared.utils.io
|
|
13
|
-
from rasa.exceptions import MissingDependencyException
|
|
14
12
|
from rasa.shared.constants import DOCS_URL_MIGRATION_GUIDE
|
|
15
|
-
from rasa.shared.exceptions import
|
|
13
|
+
from rasa.shared.exceptions import RasaException
|
|
16
14
|
|
|
17
15
|
logger = logging.getLogger(__name__)
|
|
18
16
|
|
|
@@ -192,14 +190,6 @@ def mark_as_experimental_feature(feature_name: Text) -> None:
|
|
|
192
190
|
)
|
|
193
191
|
|
|
194
192
|
|
|
195
|
-
def mark_as_beta_feature(feature_name: Text) -> None:
|
|
196
|
-
"""Warns users that they are using a beta feature."""
|
|
197
|
-
logger.warning(
|
|
198
|
-
f"🔬 Beta Feature: {feature_name} is in beta. It may have unexpected "
|
|
199
|
-
"behaviour and might be changed in the future."
|
|
200
|
-
)
|
|
201
|
-
|
|
202
|
-
|
|
203
193
|
def arguments_of(func: Callable) -> List[Text]:
|
|
204
194
|
"""Return the parameters of the function `func` as a list of names."""
|
|
205
195
|
import inspect
|
|
@@ -297,28 +287,3 @@ def warn_and_exit_if_module_path_contains_rasa_plus(
|
|
|
297
287
|
docs=DOCS_URL_MIGRATION_GUIDE,
|
|
298
288
|
)
|
|
299
289
|
sys.exit(1)
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
def validate_environment(
|
|
303
|
-
required_env_vars: Sequence[str],
|
|
304
|
-
required_packages: Sequence[str],
|
|
305
|
-
component_name: str,
|
|
306
|
-
) -> None:
|
|
307
|
-
"""Make sure all needed requirements for a component are met.
|
|
308
|
-
Args:
|
|
309
|
-
required_env_vars: List of environment variables that should be set
|
|
310
|
-
required_packages: List of packages that should be installed
|
|
311
|
-
component_name: component name that needs the requirements
|
|
312
|
-
"""
|
|
313
|
-
for e in required_env_vars:
|
|
314
|
-
if not os.environ.get(e):
|
|
315
|
-
raise ProviderClientValidationError(
|
|
316
|
-
f"Missing environment variable for {component_name}: {e}"
|
|
317
|
-
)
|
|
318
|
-
for p in required_packages:
|
|
319
|
-
try:
|
|
320
|
-
importlib.import_module(p)
|
|
321
|
-
except ImportError:
|
|
322
|
-
raise MissingDependencyException(
|
|
323
|
-
f"Missing package for {component_name}: {p}"
|
|
324
|
-
)
|
rasa/shared/utils/io.py
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
|
+
from collections import OrderedDict
|
|
2
|
+
from functools import wraps
|
|
3
|
+
from hashlib import md5
|
|
1
4
|
import asyncio
|
|
2
5
|
import errno
|
|
3
6
|
import glob
|
|
4
7
|
import json
|
|
5
8
|
import logging
|
|
6
9
|
import os
|
|
7
|
-
import random
|
|
8
|
-
import string
|
|
9
10
|
import sys
|
|
10
|
-
import warnings
|
|
11
|
-
from collections import OrderedDict
|
|
12
|
-
from functools import wraps
|
|
13
|
-
from hashlib import md5
|
|
14
11
|
from pathlib import Path
|
|
15
12
|
from typing import Any, cast, Callable, Dict, List, Optional, Text, Type, TypeVar, Union
|
|
16
|
-
|
|
13
|
+
import warnings
|
|
14
|
+
import random
|
|
15
|
+
import string
|
|
17
16
|
import portalocker
|
|
18
17
|
|
|
19
18
|
from rasa.shared.constants import (
|
|
@@ -476,24 +475,3 @@ def suppress_logs(log_level: int = logging.WARNING) -> Callable[[F], F]:
|
|
|
476
475
|
return cast(F, sync_wrapper)
|
|
477
476
|
|
|
478
477
|
return decorator
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
def resolve_environment_variables(
|
|
482
|
-
value: Union[str, List[Any], Dict[str, Any]],
|
|
483
|
-
) -> Union[str, List[Any], Dict[str, Any]]:
|
|
484
|
-
"""Resolve environment variables in a string, list, or dictionary.
|
|
485
|
-
|
|
486
|
-
Args:
|
|
487
|
-
value: The value to resolve environment variables in.
|
|
488
|
-
|
|
489
|
-
Returns:
|
|
490
|
-
The value with environment variables resolved.
|
|
491
|
-
"""
|
|
492
|
-
if isinstance(value, str):
|
|
493
|
-
return os.path.expandvars(value)
|
|
494
|
-
elif isinstance(value, list):
|
|
495
|
-
return [resolve_environment_variables(item) for item in value]
|
|
496
|
-
elif isinstance(value, dict):
|
|
497
|
-
return {key: resolve_environment_variables(val) for key, val in value.items()}
|
|
498
|
-
else:
|
|
499
|
-
return value
|