rasa-pro 3.11.0__py3-none-any.whl → 3.11.0a2__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 +5 -7
- 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/channel.py +0 -20
- rasa/core/channels/development_inspector.py +2 -8
- rasa/core/channels/inspector/dist/assets/{arc-bc141fb2.js → arc-6852c607.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{c4Diagram-d0fbc5ce-be2db283.js → c4Diagram-d0fbc5ce-acc952b2.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{classDiagram-936ed81e-55366915.js → classDiagram-936ed81e-848a7597.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{classDiagram-v2-c3cb15f1-bb529518.js → classDiagram-v2-c3cb15f1-a73d3e68.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{createText-62fc7601-b0ec81d6.js → createText-62fc7601-e5ee049d.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{edges-f2ad444c-6166330c.js → edges-f2ad444c-771e517e.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{erDiagram-9d236eb7-5ccc6a8e.js → erDiagram-9d236eb7-aa347178.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{flowDb-1972c806-fca3bfe4.js → flowDb-1972c806-651fc57d.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{flowDiagram-7ea5b25a-4739080f.js → flowDiagram-7ea5b25a-ca67804f.js} +1 -1
- rasa/core/channels/inspector/dist/assets/flowDiagram-v2-855bc5b3-587d82d8.js +1 -0
- rasa/core/channels/inspector/dist/assets/{flowchart-elk-definition-abe16c3d-7c1b0e0f.js → flowchart-elk-definition-abe16c3d-2dbc568d.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{ganttDiagram-9b5ea136-772fd050.js → ganttDiagram-9b5ea136-25a65bd8.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{gitGraphDiagram-99d0ae7c-8eae1dc9.js → gitGraphDiagram-99d0ae7c-fdc7378d.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{index-2c4b9a3b-f55afcdf.js → index-2c4b9a3b-6f1fd606.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{index-e7cef9de.js → index-efdd30c1.js} +68 -68
- rasa/core/channels/inspector/dist/assets/{infoDiagram-736b4530-124d4a14.js → infoDiagram-736b4530-cb1a041a.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{journeyDiagram-df861f2b-7c4fae44.js → journeyDiagram-df861f2b-14609879.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{layout-b9885fb6.js → layout-2490f52b.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{line-7c59abb6.js → line-40186f1f.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{linear-4776f780.js → linear-08814e93.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{mindmap-definition-beec6740-2332c46c.js → mindmap-definition-beec6740-1a534584.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{pieDiagram-dbbf0591-8fb39303.js → pieDiagram-dbbf0591-72397b61.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{quadrantDiagram-4d7f4fd6-3c7180a2.js → quadrantDiagram-4d7f4fd6-3bb0b6a3.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{requirementDiagram-6fc4c22a-e910bcb8.js → requirementDiagram-6fc4c22a-57334f61.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{sankeyDiagram-8f13d901-ead16c89.js → sankeyDiagram-8f13d901-111e1297.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{sequenceDiagram-b655622a-29a02a19.js → sequenceDiagram-b655622a-10bcfe62.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{stateDiagram-59f0c015-042b3137.js → stateDiagram-59f0c015-acaf7513.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{stateDiagram-v2-2b26beab-2178c0f3.js → stateDiagram-v2-2b26beab-3ec2a235.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{styles-080da4f6-23ffa4fc.js → styles-080da4f6-62730289.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{styles-3dcbcfbf-94f59763.js → styles-3dcbcfbf-5284ee76.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{styles-9c745c82-78a6bebc.js → styles-9c745c82-642435e3.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{svgDrawCommon-4835440b-eae2a6f6.js → svgDrawCommon-4835440b-b250a350.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{timeline-definition-5b62e21b-5c968d92.js → timeline-definition-5b62e21b-c2b147ed.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{xychartDiagram-2b33534f-fd3db0d5.js → xychartDiagram-2b33534f-f92cfea9.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/helpers/audiostream.ts +16 -77
- 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/browser_audio.py +9 -32
- 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 +5 -32
- 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.0a2.dist-info/METADATA +576 -0
- {rasa_pro-3.11.0.dist-info → rasa_pro-3.11.0a2.dist-info}/RECORD +181 -213
- 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/voice_stream/asr/azure.py +0 -129
- 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.0a2.dist-info}/NOTICE +0 -0
- {rasa_pro-3.11.0.dist-info → rasa_pro-3.11.0a2.dist-info}/WHEEL +0 -0
- {rasa_pro-3.11.0.dist-info → rasa_pro-3.11.0a2.dist-info}/entry_points.txt +0 -0
rasa/model_service.py
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import logging
|
|
2
|
-
|
|
3
|
-
from sanic import Sanic
|
|
4
|
-
import structlog
|
|
5
|
-
|
|
6
|
-
from rasa.cli.scaffold import print_error_and_exit
|
|
7
|
-
from rasa.core.persistor import RemoteStorageType, get_persistor
|
|
8
|
-
from rasa.core.utils import list_routes
|
|
9
|
-
from rasa.model_manager import model_api
|
|
10
|
-
from rasa.model_manager import config
|
|
11
|
-
from rasa.model_manager.config import SERVER_BASE_URL, SERVER_PORT
|
|
12
|
-
from rasa.utils.common import configure_logging_and_warnings
|
|
13
|
-
import rasa.utils.licensing
|
|
14
|
-
from urllib.parse import urlparse
|
|
15
|
-
|
|
16
|
-
from rasa.utils.log_utils import configure_structlog
|
|
17
|
-
from rasa.utils.sanic_error_handler import register_custom_sanic_error_handler
|
|
18
|
-
|
|
19
|
-
structlogger = structlog.get_logger()
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
def url_prefix_from_base_url() -> str:
|
|
23
|
-
"""Return the path prefix from the base URL."""
|
|
24
|
-
# return path without any trailing slashes
|
|
25
|
-
prefix = urlparse(SERVER_BASE_URL).path.rstrip("/") if SERVER_BASE_URL else ""
|
|
26
|
-
|
|
27
|
-
# can't be empty
|
|
28
|
-
return prefix or config.DEFAULT_SERVER_PATH_PREFIX
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
def validate_model_storage_type() -> None:
|
|
32
|
-
"""Validate the storage type if remote storage is used for models."""
|
|
33
|
-
if config.SERVER_MODEL_REMOTE_STORAGE:
|
|
34
|
-
if config.SERVER_MODEL_REMOTE_STORAGE not in RemoteStorageType.list():
|
|
35
|
-
print_error_and_exit(
|
|
36
|
-
f"Invalid storage type '{config.SERVER_MODEL_REMOTE_STORAGE}'. "
|
|
37
|
-
f"Supported storage types: {', '.join(RemoteStorageType.list())}."
|
|
38
|
-
f"Alternatively, unset the remote storage type to store models locally."
|
|
39
|
-
)
|
|
40
|
-
else:
|
|
41
|
-
structlogger.info(
|
|
42
|
-
"model_api.storage.remote_storage_enabled",
|
|
43
|
-
remote_storage=config.SERVER_MODEL_REMOTE_STORAGE,
|
|
44
|
-
)
|
|
45
|
-
# try to create a client to validate the configuration
|
|
46
|
-
get_persistor(config.SERVER_MODEL_REMOTE_STORAGE)
|
|
47
|
-
else:
|
|
48
|
-
structlogger.info(
|
|
49
|
-
"model_api.storage.local_storage_enabled",
|
|
50
|
-
base_path=config.SERVER_BASE_WORKING_DIRECTORY,
|
|
51
|
-
)
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
def _register_update_task(app: Sanic) -> None:
|
|
55
|
-
app.add_task(
|
|
56
|
-
model_api.continuously_update_process_status,
|
|
57
|
-
name="continuously_update_process_status",
|
|
58
|
-
)
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
def main() -> None:
|
|
62
|
-
"""Start the Rasa Model Manager server.
|
|
63
|
-
|
|
64
|
-
The API server can receive requests to train models, run bots, and manage
|
|
65
|
-
the lifecycle of models and bots.
|
|
66
|
-
"""
|
|
67
|
-
log_level = logging.DEBUG
|
|
68
|
-
configure_logging_and_warnings(
|
|
69
|
-
log_level=log_level,
|
|
70
|
-
logging_config_file=None,
|
|
71
|
-
warn_only_once=True,
|
|
72
|
-
filter_repeated_logs=True,
|
|
73
|
-
)
|
|
74
|
-
configure_structlog(log_level, include_time=True)
|
|
75
|
-
|
|
76
|
-
rasa.utils.licensing.validate_license_from_env()
|
|
77
|
-
|
|
78
|
-
try:
|
|
79
|
-
model_api.prepare_working_directories()
|
|
80
|
-
except Exception as e:
|
|
81
|
-
structlogger.error(
|
|
82
|
-
"model_api.prepare_directories.failed",
|
|
83
|
-
error=str(e),
|
|
84
|
-
base_directory=config.SERVER_BASE_WORKING_DIRECTORY,
|
|
85
|
-
)
|
|
86
|
-
print_error_and_exit(
|
|
87
|
-
f"Failed to create working directories. Please make sure the "
|
|
88
|
-
f"server base directory at '{config.SERVER_BASE_WORKING_DIRECTORY}' "
|
|
89
|
-
f"is writable by the current user."
|
|
90
|
-
)
|
|
91
|
-
|
|
92
|
-
validate_model_storage_type()
|
|
93
|
-
|
|
94
|
-
structlogger.debug("model_api.starting_server", port=SERVER_PORT)
|
|
95
|
-
|
|
96
|
-
url_prefix = url_prefix_from_base_url()
|
|
97
|
-
# configure the sanic application
|
|
98
|
-
app = Sanic("RasaModelService")
|
|
99
|
-
app.after_server_start(_register_update_task)
|
|
100
|
-
app.blueprint(model_api.external_blueprint(), url_prefix=url_prefix)
|
|
101
|
-
app.blueprint(model_api.internal_blueprint())
|
|
102
|
-
|
|
103
|
-
# list all routes
|
|
104
|
-
list_routes(app)
|
|
105
|
-
|
|
106
|
-
register_custom_sanic_error_handler(app)
|
|
107
|
-
|
|
108
|
-
app.run(host="0.0.0.0", port=SERVER_PORT, legacy=True, motd=False)
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
if __name__ == "__main__":
|
|
112
|
-
main()
|
rasa/shared/core/flows/utils.py
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
from typing import Set
|
|
2
|
-
from rasa.shared.utils.io import raise_deprecation_warning
|
|
3
|
-
|
|
4
|
-
RESET_PROPERTY_NAME = "reset_after_flow_ends"
|
|
5
|
-
PERSIST_PROPERTY_NAME = "persisted_slots"
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
def warn_deprecated_collect_step_config(flow_id: str, collect_step: str) -> None:
|
|
9
|
-
"""Warns about deprecated reset_after_flow_ends usage in collect steps."""
|
|
10
|
-
raise_deprecation_warning(
|
|
11
|
-
f"Configuring '{RESET_PROPERTY_NAME}' in collect step '{collect_step}' is "
|
|
12
|
-
f"deprecated and will be removed in Rasa Pro 4.0.0. In flow id '{flow_id}', "
|
|
13
|
-
f"please use the '{PERSIST_PROPERTY_NAME}' "
|
|
14
|
-
"property at the flow level instead."
|
|
15
|
-
)
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
def get_duplicate_slot_persistence_config_error_message(
|
|
19
|
-
flow_id: str, collect_step: str
|
|
20
|
-
) -> str:
|
|
21
|
-
"""Returns an error message for duplicate slot persistence configuration."""
|
|
22
|
-
return (
|
|
23
|
-
f"Flow with id '{flow_id}' uses the '{RESET_PROPERTY_NAME}' property "
|
|
24
|
-
f"in collect step '{collect_step}' and also the "
|
|
25
|
-
f"'{PERSIST_PROPERTY_NAME}' property at the flow level. "
|
|
26
|
-
"Please use only one of the two configuration methods."
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
def get_invalid_slot_persistence_config_error_message(
|
|
31
|
-
flow_id: str, invalid_slots: Set[str]
|
|
32
|
-
) -> str:
|
|
33
|
-
"""Returns an error message for invalid slot persistence configuration."""
|
|
34
|
-
return (
|
|
35
|
-
f"Flow with id '{flow_id}' lists slot(s) '{invalid_slots}' in the "
|
|
36
|
-
f"'{PERSIST_PROPERTY_NAME}' property. However these slots "
|
|
37
|
-
f"are neither used in a collect step nor a set_slot step of the flow. "
|
|
38
|
-
f"Please remove such slots from the '{PERSIST_PROPERTY_NAME}' property."
|
|
39
|
-
)
|
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
import copy
|
|
2
|
-
from dataclasses import dataclass, field
|
|
3
|
-
from typing import Any, Dict, List
|
|
4
|
-
|
|
5
|
-
import structlog
|
|
6
|
-
from rasa.shared.constants import (
|
|
7
|
-
ROUTER_CONFIG_KEY,
|
|
8
|
-
MODELS_CONFIG_KEY,
|
|
9
|
-
MODEL_GROUP_ID_CONFIG_KEY,
|
|
10
|
-
MODEL_NAME_CONFIG_KEY,
|
|
11
|
-
LITELLM_PARAMS_KEY,
|
|
12
|
-
PROVIDER_CONFIG_KEY,
|
|
13
|
-
DEPLOYMENT_CONFIG_KEY,
|
|
14
|
-
API_TYPE_CONFIG_KEY,
|
|
15
|
-
MODEL_CONFIG_KEY,
|
|
16
|
-
MODEL_LIST_KEY,
|
|
17
|
-
USE_CHAT_COMPLETIONS_ENDPOINT_CONFIG_KEY,
|
|
18
|
-
)
|
|
19
|
-
from rasa.shared.providers._configs.model_group_config import (
|
|
20
|
-
ModelGroupConfig,
|
|
21
|
-
ModelConfig,
|
|
22
|
-
)
|
|
23
|
-
from rasa.shared.providers.mappings import get_prefix_from_provider
|
|
24
|
-
from rasa.shared.utils.llm import DEPLOYMENT_CENTRIC_PROVIDERS
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
structlogger = structlog.get_logger()
|
|
28
|
-
|
|
29
|
-
_LITELLM_UNSUPPORTED_KEYS = [
|
|
30
|
-
PROVIDER_CONFIG_KEY,
|
|
31
|
-
DEPLOYMENT_CONFIG_KEY,
|
|
32
|
-
API_TYPE_CONFIG_KEY,
|
|
33
|
-
USE_CHAT_COMPLETIONS_ENDPOINT_CONFIG_KEY,
|
|
34
|
-
]
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
@dataclass
|
|
38
|
-
class LiteLLMRouterClientConfig:
|
|
39
|
-
"""Parses configuration for a LiteLLM Router client. The configuration is expected
|
|
40
|
-
to be in the following format:
|
|
41
|
-
|
|
42
|
-
{
|
|
43
|
-
"id": "model_group_id",
|
|
44
|
-
"models": [
|
|
45
|
-
{
|
|
46
|
-
"provider": "provider_name",
|
|
47
|
-
"model": "model_name",
|
|
48
|
-
"api_base": "api_base",
|
|
49
|
-
"api_key": "api_key",
|
|
50
|
-
"api_version": "api_version",
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
"provider": "provider_name",
|
|
54
|
-
"model": "model_name",
|
|
55
|
-
},
|
|
56
|
-
"router": {}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
This configuration is converted into the LiteLLM required format:
|
|
60
|
-
|
|
61
|
-
{
|
|
62
|
-
"id": "model_group_id",
|
|
63
|
-
"model_list": [
|
|
64
|
-
{
|
|
65
|
-
"model_name": "model_group_id",
|
|
66
|
-
"litellm_params": {
|
|
67
|
-
"model": "provider_name/model_name",
|
|
68
|
-
"api_base": "api_base",
|
|
69
|
-
"api_key": "api_key",
|
|
70
|
-
"api_version": "api_version",
|
|
71
|
-
},
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
"model_name": "model_group_id",
|
|
75
|
-
"litellm_params": {
|
|
76
|
-
"model": "provider_name/model_name",
|
|
77
|
-
},
|
|
78
|
-
},
|
|
79
|
-
],
|
|
80
|
-
"router": {},
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
Raises:
|
|
84
|
-
ValueError: If the configuration is missing required keys.
|
|
85
|
-
"""
|
|
86
|
-
|
|
87
|
-
_model_group_config: ModelGroupConfig
|
|
88
|
-
router: Dict[str, Any]
|
|
89
|
-
_use_chat_completions_endpoint: bool = True
|
|
90
|
-
extra_parameters: dict = field(default_factory=dict)
|
|
91
|
-
|
|
92
|
-
@property
|
|
93
|
-
def model_group_id(self) -> str:
|
|
94
|
-
return self._model_group_config.model_group_id
|
|
95
|
-
|
|
96
|
-
@property
|
|
97
|
-
def models(self) -> List[ModelConfig]:
|
|
98
|
-
return self._model_group_config.models
|
|
99
|
-
|
|
100
|
-
@property
|
|
101
|
-
def litellm_model_list(self) -> List[Dict[str, Any]]:
|
|
102
|
-
return self._convert_models_to_litellm_model_list()
|
|
103
|
-
|
|
104
|
-
@property
|
|
105
|
-
def litellm_router_settings(self) -> Dict[str, Any]:
|
|
106
|
-
return self._convert_router_to_litellm_router_settings()
|
|
107
|
-
|
|
108
|
-
@property
|
|
109
|
-
def use_chat_completions_endpoint(self) -> bool:
|
|
110
|
-
return self._use_chat_completions_endpoint
|
|
111
|
-
|
|
112
|
-
def __post_init__(self) -> None:
|
|
113
|
-
if not self.router:
|
|
114
|
-
message = "Router cannot be empty."
|
|
115
|
-
structlogger.error(
|
|
116
|
-
"litellm_router_client_config.validation_error",
|
|
117
|
-
message=message,
|
|
118
|
-
model_group_id=self._model_group_config.model_group_id,
|
|
119
|
-
)
|
|
120
|
-
raise ValueError(message)
|
|
121
|
-
|
|
122
|
-
@classmethod
|
|
123
|
-
def from_dict(cls, config: dict) -> "LiteLLMRouterClientConfig":
|
|
124
|
-
"""Initializes a dataclass from the passed config.
|
|
125
|
-
|
|
126
|
-
Args:
|
|
127
|
-
config: (dict) The config from which to initialize.
|
|
128
|
-
|
|
129
|
-
Raises:
|
|
130
|
-
ValueError: Config is missing required keys.
|
|
131
|
-
|
|
132
|
-
Returns:
|
|
133
|
-
LiteLLMRouterClientConfig
|
|
134
|
-
"""
|
|
135
|
-
model_group_config = ModelGroupConfig.from_dict(config)
|
|
136
|
-
|
|
137
|
-
# Copy config to avoid mutating the original
|
|
138
|
-
config_copy = copy.deepcopy(config)
|
|
139
|
-
# Pop the keys used by ModelGroupConfig
|
|
140
|
-
config_copy.pop(MODEL_GROUP_ID_CONFIG_KEY, None)
|
|
141
|
-
config_copy.pop(MODELS_CONFIG_KEY, None)
|
|
142
|
-
# Get the router settings
|
|
143
|
-
router_settings = config_copy.pop(ROUTER_CONFIG_KEY, {})
|
|
144
|
-
# Get the use_chat_completions_endpoint setting
|
|
145
|
-
use_chat_completions_endpoint = router_settings.get(
|
|
146
|
-
USE_CHAT_COMPLETIONS_ENDPOINT_CONFIG_KEY, True
|
|
147
|
-
)
|
|
148
|
-
# The rest is considered as extra parameters
|
|
149
|
-
extra_parameters = config_copy
|
|
150
|
-
|
|
151
|
-
this = LiteLLMRouterClientConfig(
|
|
152
|
-
_model_group_config=model_group_config,
|
|
153
|
-
router=router_settings,
|
|
154
|
-
_use_chat_completions_endpoint=use_chat_completions_endpoint,
|
|
155
|
-
extra_parameters=extra_parameters,
|
|
156
|
-
)
|
|
157
|
-
return this
|
|
158
|
-
|
|
159
|
-
def to_dict(self) -> dict:
|
|
160
|
-
"""Converts the config instance into a dictionary."""
|
|
161
|
-
d = self._model_group_config.to_dict()
|
|
162
|
-
d[ROUTER_CONFIG_KEY] = self.router
|
|
163
|
-
if self.extra_parameters:
|
|
164
|
-
d.update(self.extra_parameters)
|
|
165
|
-
return d
|
|
166
|
-
|
|
167
|
-
def to_litellm_dict(self) -> dict:
|
|
168
|
-
return {
|
|
169
|
-
**self.extra_parameters,
|
|
170
|
-
MODEL_GROUP_ID_CONFIG_KEY: self.model_group_id,
|
|
171
|
-
MODEL_LIST_KEY: self._convert_models_to_litellm_model_list(),
|
|
172
|
-
ROUTER_CONFIG_KEY: self._convert_router_to_litellm_router_settings(),
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
def _convert_router_to_litellm_router_settings(self) -> Dict[str, Any]:
|
|
176
|
-
_router_settings_copy = copy.deepcopy(self.router)
|
|
177
|
-
_router_settings_copy.pop(USE_CHAT_COMPLETIONS_ENDPOINT_CONFIG_KEY, None)
|
|
178
|
-
return _router_settings_copy
|
|
179
|
-
|
|
180
|
-
def _convert_models_to_litellm_model_list(self) -> List[Dict[str, Any]]:
|
|
181
|
-
litellm_model_list = []
|
|
182
|
-
|
|
183
|
-
for model_config_object in self.models:
|
|
184
|
-
# Convert the model config to a dict representation
|
|
185
|
-
litellm_model_config = model_config_object.to_dict()
|
|
186
|
-
|
|
187
|
-
provider = litellm_model_config[PROVIDER_CONFIG_KEY]
|
|
188
|
-
|
|
189
|
-
# Get the litellm prefixing for the provider
|
|
190
|
-
prefix = get_prefix_from_provider(provider)
|
|
191
|
-
|
|
192
|
-
# Determine whether to use model or deployment key based on the provider.
|
|
193
|
-
litellm_model_name = (
|
|
194
|
-
litellm_model_config[DEPLOYMENT_CONFIG_KEY]
|
|
195
|
-
if provider in DEPLOYMENT_CENTRIC_PROVIDERS
|
|
196
|
-
else litellm_model_config[MODEL_CONFIG_KEY]
|
|
197
|
-
)
|
|
198
|
-
|
|
199
|
-
# Set 'model' to a provider prefixed model name e.g. openai/gpt-4
|
|
200
|
-
litellm_model_config[MODEL_CONFIG_KEY] = (
|
|
201
|
-
litellm_model_name
|
|
202
|
-
if f"{prefix}/" in litellm_model_name
|
|
203
|
-
else f"{prefix}/{litellm_model_name}"
|
|
204
|
-
)
|
|
205
|
-
|
|
206
|
-
# Remove parameters that are None and not supported by LiteLLM.
|
|
207
|
-
litellm_model_config = {
|
|
208
|
-
key: value
|
|
209
|
-
for key, value in litellm_model_config.items()
|
|
210
|
-
if key not in _LITELLM_UNSUPPORTED_KEYS and value is not None
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
litellm_model_list_item = {
|
|
214
|
-
MODEL_NAME_CONFIG_KEY: self.model_group_id,
|
|
215
|
-
LITELLM_PARAMS_KEY: litellm_model_config,
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
litellm_model_list.append(litellm_model_list_item)
|
|
219
|
-
|
|
220
|
-
return litellm_model_list
|
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
from dataclasses import asdict, dataclass, field
|
|
2
|
-
from typing import List, Optional
|
|
3
|
-
|
|
4
|
-
import structlog
|
|
5
|
-
from rasa.shared.constants import (
|
|
6
|
-
API_BASE_CONFIG_KEY,
|
|
7
|
-
API_KEY,
|
|
8
|
-
API_TYPE_CONFIG_KEY,
|
|
9
|
-
API_VERSION_CONFIG_KEY,
|
|
10
|
-
DEPLOYMENT_CONFIG_KEY,
|
|
11
|
-
PROVIDER_CONFIG_KEY,
|
|
12
|
-
MODEL_CONFIG_KEY,
|
|
13
|
-
MODEL_GROUP_ID_CONFIG_KEY,
|
|
14
|
-
MODELS_CONFIG_KEY,
|
|
15
|
-
MODEL_GROUPS_CONFIG_KEY,
|
|
16
|
-
EXTRA_PARAMETERS_KEY,
|
|
17
|
-
)
|
|
18
|
-
from rasa.shared.providers.mappings import get_client_config_class_from_provider
|
|
19
|
-
|
|
20
|
-
structlogger = structlog.get_logger()
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
@dataclass
|
|
24
|
-
class ModelConfig:
|
|
25
|
-
"""Parses the model config.
|
|
26
|
-
|
|
27
|
-
Raises:
|
|
28
|
-
ValueError: If the provider config key is missing in the config.
|
|
29
|
-
"""
|
|
30
|
-
|
|
31
|
-
provider: str
|
|
32
|
-
model: Optional[str] = None
|
|
33
|
-
deployment: Optional[str] = None
|
|
34
|
-
api_base: Optional[str] = None
|
|
35
|
-
api_key: Optional[str] = None
|
|
36
|
-
api_version: Optional[str] = None
|
|
37
|
-
extra_parameters: dict = field(default_factory=dict)
|
|
38
|
-
# Retained for backward compatibility with older configurations,
|
|
39
|
-
# but intentionally not included in extra_parameters
|
|
40
|
-
api_type: Optional[str] = None
|
|
41
|
-
|
|
42
|
-
@classmethod
|
|
43
|
-
def from_dict(cls, config: dict) -> "ModelConfig":
|
|
44
|
-
"""Initializes a dataclass from the passed config. The provider config param is
|
|
45
|
-
used to determine the client config class to use. The client config class takes
|
|
46
|
-
care of resolving config aliases and throwing deprecation warnings.
|
|
47
|
-
|
|
48
|
-
Args:
|
|
49
|
-
config: (dict) The config from which to initialize.
|
|
50
|
-
|
|
51
|
-
Raises:
|
|
52
|
-
ValueError: Config is missing required keys.
|
|
53
|
-
|
|
54
|
-
Returns:
|
|
55
|
-
ModelConfig
|
|
56
|
-
"""
|
|
57
|
-
from rasa.shared.utils.llm import get_provider_from_config
|
|
58
|
-
|
|
59
|
-
# Get the provider from config, this also inferring the provider from
|
|
60
|
-
# deprecated configurations
|
|
61
|
-
provider = get_provider_from_config(config)
|
|
62
|
-
|
|
63
|
-
# Retrieve the client configuration class for the specified provider.
|
|
64
|
-
client_config_clazz = get_client_config_class_from_provider(provider)
|
|
65
|
-
|
|
66
|
-
# Try to instantiate the config object in order to resolve deprecated
|
|
67
|
-
# aliases and throw deprecation warnings.
|
|
68
|
-
client_config_obj = client_config_clazz.from_dict(config)
|
|
69
|
-
|
|
70
|
-
# Convert back to dictionary and instantiate the ModelConfig object.
|
|
71
|
-
client_config = client_config_obj.to_dict()
|
|
72
|
-
|
|
73
|
-
# Check for provider after resolving all aliases
|
|
74
|
-
if PROVIDER_CONFIG_KEY not in client_config:
|
|
75
|
-
raise ValueError(
|
|
76
|
-
f"Missing required key '{PROVIDER_CONFIG_KEY}' in "
|
|
77
|
-
f"'{MODELS_CONFIG_KEY}' config."
|
|
78
|
-
)
|
|
79
|
-
|
|
80
|
-
return ModelConfig(
|
|
81
|
-
provider=client_config.pop(PROVIDER_CONFIG_KEY, None),
|
|
82
|
-
model=client_config.pop(MODEL_CONFIG_KEY, None),
|
|
83
|
-
deployment=client_config.pop(DEPLOYMENT_CONFIG_KEY, None),
|
|
84
|
-
api_type=client_config.pop(API_TYPE_CONFIG_KEY, None),
|
|
85
|
-
api_base=client_config.pop(API_BASE_CONFIG_KEY, None),
|
|
86
|
-
api_key=client_config.pop(API_KEY, None),
|
|
87
|
-
api_version=client_config.pop(API_VERSION_CONFIG_KEY, None),
|
|
88
|
-
extra_parameters=client_config,
|
|
89
|
-
)
|
|
90
|
-
|
|
91
|
-
def to_dict(self) -> dict:
|
|
92
|
-
"""Converts the config instance into a dictionary."""
|
|
93
|
-
d = asdict(self)
|
|
94
|
-
|
|
95
|
-
# Extra parameters should also be on the top level
|
|
96
|
-
d.pop(EXTRA_PARAMETERS_KEY, None)
|
|
97
|
-
d.update(self.extra_parameters)
|
|
98
|
-
|
|
99
|
-
# Remove keys with None values
|
|
100
|
-
return {key: value for key, value in d.items() if value is not None}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
@dataclass
|
|
104
|
-
class ModelGroupConfig:
|
|
105
|
-
"""Parses the models config. The models config is a list of model configs.
|
|
106
|
-
|
|
107
|
-
Raises:
|
|
108
|
-
ValueError: If the model group ID is None or if the models list is empty.
|
|
109
|
-
"""
|
|
110
|
-
|
|
111
|
-
model_group_id: str
|
|
112
|
-
models: List[ModelConfig]
|
|
113
|
-
|
|
114
|
-
def __post_init__(self) -> None:
|
|
115
|
-
if self.model_group_id is None:
|
|
116
|
-
message = "Model group ID cannot be set to None."
|
|
117
|
-
structlogger.error(
|
|
118
|
-
"model_group_config.validation_error",
|
|
119
|
-
message=message,
|
|
120
|
-
model_group_id=self.model_group_id,
|
|
121
|
-
)
|
|
122
|
-
raise ValueError(message)
|
|
123
|
-
if not self.models:
|
|
124
|
-
message = "Models cannot be empty."
|
|
125
|
-
structlogger.error(
|
|
126
|
-
"model_group_config.validation_error",
|
|
127
|
-
message=message,
|
|
128
|
-
model_group_id=self.model_group_id,
|
|
129
|
-
)
|
|
130
|
-
raise ValueError(message)
|
|
131
|
-
|
|
132
|
-
@classmethod
|
|
133
|
-
def from_dict(cls, config: dict) -> "ModelGroupConfig":
|
|
134
|
-
"""Initializes a dataclass from the passed config.
|
|
135
|
-
|
|
136
|
-
Args:
|
|
137
|
-
config: (dict) The config from which to initialize.
|
|
138
|
-
|
|
139
|
-
Raises:
|
|
140
|
-
ValueError: Config is missing required keys.
|
|
141
|
-
|
|
142
|
-
Returns:
|
|
143
|
-
ModelGroupConfig
|
|
144
|
-
"""
|
|
145
|
-
if MODELS_CONFIG_KEY not in config:
|
|
146
|
-
raise ValueError(
|
|
147
|
-
f"Missing required key '{MODELS_CONFIG_KEY}' in "
|
|
148
|
-
f"'{MODEL_GROUPS_CONFIG_KEY}' config."
|
|
149
|
-
)
|
|
150
|
-
|
|
151
|
-
models_config = [
|
|
152
|
-
ModelConfig.from_dict(model_config)
|
|
153
|
-
for model_config in config[MODELS_CONFIG_KEY]
|
|
154
|
-
]
|
|
155
|
-
|
|
156
|
-
return cls(
|
|
157
|
-
model_group_id=config.get(MODEL_GROUP_ID_CONFIG_KEY),
|
|
158
|
-
models=models_config,
|
|
159
|
-
)
|
|
160
|
-
|
|
161
|
-
def to_dict(self) -> dict:
|
|
162
|
-
"""Converts the config instance into a dictionary."""
|
|
163
|
-
d = {
|
|
164
|
-
MODEL_GROUP_ID_CONFIG_KEY: self.model_group_id,
|
|
165
|
-
MODELS_CONFIG_KEY: [model.to_dict() for model in self.models],
|
|
166
|
-
}
|
|
167
|
-
return d
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
from dataclasses import asdict, dataclass, field
|
|
2
|
-
from typing import Optional
|
|
3
|
-
|
|
4
|
-
import structlog
|
|
5
|
-
|
|
6
|
-
from rasa.shared.constants import (
|
|
7
|
-
MODEL_CONFIG_KEY,
|
|
8
|
-
RASA_PROVIDER,
|
|
9
|
-
PROVIDER_CONFIG_KEY,
|
|
10
|
-
API_BASE_CONFIG_KEY,
|
|
11
|
-
)
|
|
12
|
-
from rasa.shared.providers._configs.utils import (
|
|
13
|
-
validate_required_keys,
|
|
14
|
-
)
|
|
15
|
-
|
|
16
|
-
REQUIRED_KEYS = [MODEL_CONFIG_KEY, PROVIDER_CONFIG_KEY, API_BASE_CONFIG_KEY]
|
|
17
|
-
|
|
18
|
-
structlogger = structlog.get_logger()
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
@dataclass
|
|
22
|
-
class RasaLLMClientConfig:
|
|
23
|
-
"""Parses configuration for a Rasa Hosted LiteLLM client,
|
|
24
|
-
checks required keys present.
|
|
25
|
-
|
|
26
|
-
Raises:
|
|
27
|
-
ValueError: Raised in cases of invalid configuration:
|
|
28
|
-
- If any of the required configuration keys are missing.
|
|
29
|
-
"""
|
|
30
|
-
|
|
31
|
-
model: Optional[str]
|
|
32
|
-
api_base: Optional[str]
|
|
33
|
-
# Provider is not used by LiteLLM backend, but we define it here since it's
|
|
34
|
-
# used as switch between different clients.
|
|
35
|
-
provider: str = RASA_PROVIDER
|
|
36
|
-
|
|
37
|
-
extra_parameters: dict = field(default_factory=dict)
|
|
38
|
-
|
|
39
|
-
@classmethod
|
|
40
|
-
def from_dict(cls, config: dict) -> "RasaLLMClientConfig":
|
|
41
|
-
"""
|
|
42
|
-
Initializes a dataclass from the passed config.
|
|
43
|
-
|
|
44
|
-
Args:
|
|
45
|
-
config: (dict) The config from which to initialize.
|
|
46
|
-
|
|
47
|
-
Raises:
|
|
48
|
-
ValueError: Raised in cases of invalid configuration:
|
|
49
|
-
- If any of the required configuration keys are missing.
|
|
50
|
-
- If `api_type` has a value different from `azure`.
|
|
51
|
-
|
|
52
|
-
Returns:
|
|
53
|
-
RasaLLMClientConfig
|
|
54
|
-
"""
|
|
55
|
-
# Validate that required keys are set
|
|
56
|
-
validate_required_keys(config, REQUIRED_KEYS)
|
|
57
|
-
|
|
58
|
-
extra_parameters = {k: v for k, v in config.items() if k not in REQUIRED_KEYS}
|
|
59
|
-
|
|
60
|
-
return cls(
|
|
61
|
-
model=config.get(MODEL_CONFIG_KEY),
|
|
62
|
-
api_base=config.get(API_BASE_CONFIG_KEY),
|
|
63
|
-
provider=config.get(PROVIDER_CONFIG_KEY, RASA_PROVIDER),
|
|
64
|
-
extra_parameters=extra_parameters,
|
|
65
|
-
)
|
|
66
|
-
|
|
67
|
-
def to_dict(self) -> dict:
|
|
68
|
-
"""Converts the config instance into a dictionary."""
|
|
69
|
-
d = asdict(self)
|
|
70
|
-
# Extra parameters should also be on the top level
|
|
71
|
-
d.pop("extra_parameters", None)
|
|
72
|
-
d.update(self.extra_parameters)
|
|
73
|
-
return d
|
rasa/shared/providers/_utils.py
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import structlog
|
|
2
|
-
|
|
3
|
-
from rasa.shared.constants import (
|
|
4
|
-
AWS_ACCESS_KEY_ID_ENV_VAR,
|
|
5
|
-
AWS_ACCESS_KEY_ID_CONFIG_KEY,
|
|
6
|
-
AWS_SECRET_ACCESS_KEY_ENV_VAR,
|
|
7
|
-
AWS_SECRET_ACCESS_KEY_CONFIG_KEY,
|
|
8
|
-
AWS_REGION_NAME_ENV_VAR,
|
|
9
|
-
AWS_REGION_NAME_CONFIG_KEY,
|
|
10
|
-
AWS_SESSION_TOKEN_CONFIG_KEY,
|
|
11
|
-
AWS_SESSION_TOKEN_ENV_VAR,
|
|
12
|
-
)
|
|
13
|
-
from rasa.shared.exceptions import ProviderClientValidationError
|
|
14
|
-
from litellm import validate_environment
|
|
15
|
-
from rasa.shared.providers.embedding._base_litellm_embedding_client import (
|
|
16
|
-
_VALIDATE_ENVIRONMENT_MISSING_KEYS_KEY,
|
|
17
|
-
)
|
|
18
|
-
|
|
19
|
-
structlogger = structlog.get_logger()
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
def validate_aws_setup_for_litellm_clients(
|
|
23
|
-
litellm_model_name: str, litellm_call_kwargs: dict, source_log: str
|
|
24
|
-
) -> None:
|
|
25
|
-
"""Validates the AWS setup for LiteLLM clients to ensure all required
|
|
26
|
-
environment variables or corresponding call kwargs are set.
|
|
27
|
-
|
|
28
|
-
Args:
|
|
29
|
-
litellm_model_name (str): The name of the LiteLLM model being validated.
|
|
30
|
-
litellm_call_kwargs (dict): Additional keyword arguments passed to the client,
|
|
31
|
-
which may include configuration values for AWS credentials.
|
|
32
|
-
source_log (str): The source log identifier for structured logging.
|
|
33
|
-
|
|
34
|
-
Raises:
|
|
35
|
-
ProviderClientValidationError: If any required AWS environment variable
|
|
36
|
-
or corresponding configuration key is missing.
|
|
37
|
-
"""
|
|
38
|
-
|
|
39
|
-
# Mapping of environment variable names to their corresponding config keys
|
|
40
|
-
envs_to_args = {
|
|
41
|
-
AWS_ACCESS_KEY_ID_ENV_VAR: AWS_ACCESS_KEY_ID_CONFIG_KEY,
|
|
42
|
-
AWS_SECRET_ACCESS_KEY_ENV_VAR: AWS_SECRET_ACCESS_KEY_CONFIG_KEY,
|
|
43
|
-
AWS_REGION_NAME_ENV_VAR: AWS_REGION_NAME_CONFIG_KEY,
|
|
44
|
-
AWS_SESSION_TOKEN_ENV_VAR: AWS_SESSION_TOKEN_CONFIG_KEY,
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
# Validate the environment setup for the model
|
|
48
|
-
validation_info = validate_environment(litellm_model_name)
|
|
49
|
-
missing_environment_variables = validation_info.get(
|
|
50
|
-
_VALIDATE_ENVIRONMENT_MISSING_KEYS_KEY, []
|
|
51
|
-
)
|
|
52
|
-
# Filter out missing environment variables that have been set trough arguments
|
|
53
|
-
# in extra parameters
|
|
54
|
-
missing_environment_variables = [
|
|
55
|
-
missing_env_var
|
|
56
|
-
for missing_env_var in missing_environment_variables
|
|
57
|
-
if litellm_call_kwargs.get(envs_to_args.get(missing_env_var)) is None
|
|
58
|
-
]
|
|
59
|
-
|
|
60
|
-
if missing_environment_variables:
|
|
61
|
-
missing_environment_details = [
|
|
62
|
-
(
|
|
63
|
-
f"'{missing_env_var}' environment variable or "
|
|
64
|
-
f"'{envs_to_args.get(missing_env_var)}' config key"
|
|
65
|
-
)
|
|
66
|
-
for missing_env_var in missing_environment_variables
|
|
67
|
-
]
|
|
68
|
-
event_info = (
|
|
69
|
-
f"The following environment variables or configuration keys are "
|
|
70
|
-
f"missing: "
|
|
71
|
-
f"{', '.join(missing_environment_details)}. "
|
|
72
|
-
f"These settings are required for API calls."
|
|
73
|
-
)
|
|
74
|
-
structlogger.error(
|
|
75
|
-
f"{source_log}.validate_aws_environment_variables",
|
|
76
|
-
event_info=event_info,
|
|
77
|
-
missing_environment_variables=missing_environment_variables,
|
|
78
|
-
)
|
|
79
|
-
raise ProviderClientValidationError(event_info)
|