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.

Files changed (220) hide show
  1. README.md +396 -17
  2. rasa/__main__.py +15 -31
  3. rasa/api.py +1 -5
  4. rasa/cli/arguments/default_arguments.py +2 -1
  5. rasa/cli/arguments/shell.py +1 -5
  6. rasa/cli/arguments/train.py +0 -14
  7. rasa/cli/e2e_test.py +1 -1
  8. rasa/cli/evaluate.py +8 -8
  9. rasa/cli/inspect.py +7 -15
  10. rasa/cli/interactive.py +0 -1
  11. rasa/cli/llm_fine_tuning.py +1 -1
  12. rasa/cli/project_templates/calm/config.yml +7 -5
  13. rasa/cli/project_templates/calm/endpoints.yml +2 -15
  14. rasa/cli/project_templates/tutorial/config.yml +5 -8
  15. rasa/cli/project_templates/tutorial/data/flows.yml +1 -1
  16. rasa/cli/project_templates/tutorial/data/patterns.yml +0 -5
  17. rasa/cli/project_templates/tutorial/domain.yml +0 -14
  18. rasa/cli/project_templates/tutorial/endpoints.yml +0 -5
  19. rasa/cli/run.py +1 -1
  20. rasa/cli/scaffold.py +2 -4
  21. rasa/cli/studio/studio.py +8 -18
  22. rasa/cli/studio/upload.py +15 -0
  23. rasa/cli/train.py +0 -3
  24. rasa/cli/utils.py +1 -6
  25. rasa/cli/x.py +8 -8
  26. rasa/constants.py +1 -3
  27. rasa/core/actions/action.py +33 -75
  28. rasa/core/actions/e2e_stub_custom_action_executor.py +1 -5
  29. rasa/core/actions/http_custom_action_executor.py +0 -4
  30. rasa/core/channels/__init__.py +0 -2
  31. rasa/core/channels/channel.py +0 -20
  32. rasa/core/channels/development_inspector.py +3 -10
  33. rasa/core/channels/inspector/dist/assets/{arc-bc141fb2.js → arc-86942a71.js} +1 -1
  34. rasa/core/channels/inspector/dist/assets/{c4Diagram-d0fbc5ce-be2db283.js → c4Diagram-d0fbc5ce-b0290676.js} +1 -1
  35. rasa/core/channels/inspector/dist/assets/{classDiagram-936ed81e-55366915.js → classDiagram-936ed81e-f6405f6e.js} +1 -1
  36. rasa/core/channels/inspector/dist/assets/{classDiagram-v2-c3cb15f1-bb529518.js → classDiagram-v2-c3cb15f1-ef61ac77.js} +1 -1
  37. rasa/core/channels/inspector/dist/assets/{createText-62fc7601-b0ec81d6.js → createText-62fc7601-f0411e58.js} +1 -1
  38. rasa/core/channels/inspector/dist/assets/{edges-f2ad444c-6166330c.js → edges-f2ad444c-7dcc4f3b.js} +1 -1
  39. rasa/core/channels/inspector/dist/assets/{erDiagram-9d236eb7-5ccc6a8e.js → erDiagram-9d236eb7-e0c092d7.js} +1 -1
  40. rasa/core/channels/inspector/dist/assets/{flowDb-1972c806-fca3bfe4.js → flowDb-1972c806-fba2e3ce.js} +1 -1
  41. rasa/core/channels/inspector/dist/assets/{flowDiagram-7ea5b25a-4739080f.js → flowDiagram-7ea5b25a-7a70b71a.js} +1 -1
  42. rasa/core/channels/inspector/dist/assets/flowDiagram-v2-855bc5b3-24a5f41a.js +1 -0
  43. rasa/core/channels/inspector/dist/assets/{flowchart-elk-definition-abe16c3d-7c1b0e0f.js → flowchart-elk-definition-abe16c3d-00a59b68.js} +1 -1
  44. rasa/core/channels/inspector/dist/assets/{ganttDiagram-9b5ea136-772fd050.js → ganttDiagram-9b5ea136-293c91fa.js} +1 -1
  45. rasa/core/channels/inspector/dist/assets/{gitGraphDiagram-99d0ae7c-8eae1dc9.js → gitGraphDiagram-99d0ae7c-07b2d68c.js} +1 -1
  46. rasa/core/channels/inspector/dist/assets/{index-2c4b9a3b-f55afcdf.js → index-2c4b9a3b-bc959fbd.js} +1 -1
  47. rasa/core/channels/inspector/dist/assets/{index-e7cef9de.js → index-3a8a5a28.js} +143 -143
  48. rasa/core/channels/inspector/dist/assets/{infoDiagram-736b4530-124d4a14.js → infoDiagram-736b4530-4a350f72.js} +1 -1
  49. rasa/core/channels/inspector/dist/assets/{journeyDiagram-df861f2b-7c4fae44.js → journeyDiagram-df861f2b-af464fb7.js} +1 -1
  50. rasa/core/channels/inspector/dist/assets/{layout-b9885fb6.js → layout-0071f036.js} +1 -1
  51. rasa/core/channels/inspector/dist/assets/{line-7c59abb6.js → line-2f73cc83.js} +1 -1
  52. rasa/core/channels/inspector/dist/assets/{linear-4776f780.js → linear-f014b4cc.js} +1 -1
  53. rasa/core/channels/inspector/dist/assets/{mindmap-definition-beec6740-2332c46c.js → mindmap-definition-beec6740-d2426fb6.js} +1 -1
  54. rasa/core/channels/inspector/dist/assets/{pieDiagram-dbbf0591-8fb39303.js → pieDiagram-dbbf0591-776f01a2.js} +1 -1
  55. rasa/core/channels/inspector/dist/assets/{quadrantDiagram-4d7f4fd6-3c7180a2.js → quadrantDiagram-4d7f4fd6-82e00b57.js} +1 -1
  56. rasa/core/channels/inspector/dist/assets/{requirementDiagram-6fc4c22a-e910bcb8.js → requirementDiagram-6fc4c22a-ea13c6bb.js} +1 -1
  57. rasa/core/channels/inspector/dist/assets/{sankeyDiagram-8f13d901-ead16c89.js → sankeyDiagram-8f13d901-1feca7e9.js} +1 -1
  58. rasa/core/channels/inspector/dist/assets/{sequenceDiagram-b655622a-29a02a19.js → sequenceDiagram-b655622a-070c61d2.js} +1 -1
  59. rasa/core/channels/inspector/dist/assets/{stateDiagram-59f0c015-042b3137.js → stateDiagram-59f0c015-24f46263.js} +1 -1
  60. rasa/core/channels/inspector/dist/assets/{stateDiagram-v2-2b26beab-2178c0f3.js → stateDiagram-v2-2b26beab-c9056051.js} +1 -1
  61. rasa/core/channels/inspector/dist/assets/{styles-080da4f6-23ffa4fc.js → styles-080da4f6-08abc34a.js} +1 -1
  62. rasa/core/channels/inspector/dist/assets/{styles-3dcbcfbf-94f59763.js → styles-3dcbcfbf-bc74c25a.js} +1 -1
  63. rasa/core/channels/inspector/dist/assets/{styles-9c745c82-78a6bebc.js → styles-9c745c82-4e5d66de.js} +1 -1
  64. rasa/core/channels/inspector/dist/assets/{svgDrawCommon-4835440b-eae2a6f6.js → svgDrawCommon-4835440b-849c4517.js} +1 -1
  65. rasa/core/channels/inspector/dist/assets/{timeline-definition-5b62e21b-5c968d92.js → timeline-definition-5b62e21b-d0fb1598.js} +1 -1
  66. rasa/core/channels/inspector/dist/assets/{xychartDiagram-2b33534f-fd3db0d5.js → xychartDiagram-2b33534f-04d115e2.js} +1 -1
  67. rasa/core/channels/inspector/dist/index.html +1 -1
  68. rasa/core/channels/inspector/src/App.tsx +1 -1
  69. rasa/core/channels/inspector/src/components/LoadingSpinner.tsx +3 -6
  70. rasa/core/channels/socketio.py +2 -7
  71. rasa/core/channels/telegram.py +1 -1
  72. rasa/core/channels/twilio.py +1 -1
  73. rasa/core/channels/voice_ready/audiocodes.py +4 -15
  74. rasa/core/channels/voice_ready/jambonz.py +4 -15
  75. rasa/core/channels/voice_ready/twilio_voice.py +21 -6
  76. rasa/core/channels/voice_ready/utils.py +5 -6
  77. rasa/core/channels/voice_stream/asr/asr_engine.py +1 -19
  78. rasa/core/channels/voice_stream/asr/asr_event.py +0 -5
  79. rasa/core/channels/voice_stream/asr/deepgram.py +15 -28
  80. rasa/core/channels/voice_stream/audio_bytes.py +0 -1
  81. rasa/core/channels/voice_stream/tts/azure.py +3 -9
  82. rasa/core/channels/voice_stream/tts/cartesia.py +8 -12
  83. rasa/core/channels/voice_stream/tts/tts_engine.py +1 -11
  84. rasa/core/channels/voice_stream/twilio_media_streams.py +19 -28
  85. rasa/core/channels/voice_stream/util.py +4 -4
  86. rasa/core/channels/voice_stream/voice_channel.py +42 -222
  87. rasa/core/featurizers/single_state_featurizer.py +1 -22
  88. rasa/core/featurizers/tracker_featurizers.py +18 -115
  89. rasa/core/information_retrieval/qdrant.py +0 -1
  90. rasa/core/nlg/contextual_response_rephraser.py +25 -44
  91. rasa/core/persistor.py +34 -191
  92. rasa/core/policies/enterprise_search_policy.py +60 -119
  93. rasa/core/policies/flows/flow_executor.py +4 -7
  94. rasa/core/policies/intentless_policy.py +22 -82
  95. rasa/core/policies/ted_policy.py +33 -58
  96. rasa/core/policies/unexpected_intent_policy.py +7 -15
  97. rasa/core/processor.py +13 -89
  98. rasa/core/run.py +2 -2
  99. rasa/core/training/interactive.py +35 -34
  100. rasa/core/utils.py +22 -58
  101. rasa/dialogue_understanding/coexistence/llm_based_router.py +12 -39
  102. rasa/dialogue_understanding/commands/__init__.py +0 -4
  103. rasa/dialogue_understanding/commands/change_flow_command.py +0 -6
  104. rasa/dialogue_understanding/commands/utils.py +0 -5
  105. rasa/dialogue_understanding/generator/constants.py +0 -2
  106. rasa/dialogue_understanding/generator/flow_retrieval.py +4 -49
  107. rasa/dialogue_understanding/generator/llm_based_command_generator.py +23 -37
  108. rasa/dialogue_understanding/generator/multi_step/multi_step_llm_command_generator.py +10 -57
  109. rasa/dialogue_understanding/generator/nlu_command_adapter.py +1 -19
  110. rasa/dialogue_understanding/generator/single_step/command_prompt_template.jinja2 +0 -3
  111. rasa/dialogue_understanding/generator/single_step/single_step_llm_command_generator.py +10 -90
  112. rasa/dialogue_understanding/patterns/default_flows_for_patterns.yml +0 -53
  113. rasa/dialogue_understanding/processor/command_processor.py +1 -21
  114. rasa/e2e_test/assertions.py +16 -133
  115. rasa/e2e_test/assertions_schema.yml +0 -23
  116. rasa/e2e_test/e2e_test_case.py +6 -85
  117. rasa/e2e_test/e2e_test_runner.py +4 -6
  118. rasa/e2e_test/utils/io.py +1 -3
  119. rasa/engine/loader.py +0 -12
  120. rasa/engine/validation.py +11 -541
  121. rasa/keys +1 -0
  122. rasa/llm_fine_tuning/notebooks/unsloth_finetuning.ipynb +407 -0
  123. rasa/model_training.py +7 -29
  124. rasa/nlu/classifiers/diet_classifier.py +25 -38
  125. rasa/nlu/classifiers/logistic_regression_classifier.py +9 -22
  126. rasa/nlu/classifiers/sklearn_intent_classifier.py +16 -37
  127. rasa/nlu/extractors/crf_entity_extractor.py +50 -93
  128. rasa/nlu/featurizers/sparse_featurizer/count_vectors_featurizer.py +16 -45
  129. rasa/nlu/featurizers/sparse_featurizer/lexical_syntactic_featurizer.py +17 -52
  130. rasa/nlu/featurizers/sparse_featurizer/regex_featurizer.py +3 -5
  131. rasa/nlu/tokenizers/whitespace_tokenizer.py +14 -3
  132. rasa/server.py +1 -3
  133. rasa/shared/constants.py +0 -61
  134. rasa/shared/core/constants.py +0 -9
  135. rasa/shared/core/domain.py +5 -8
  136. rasa/shared/core/flows/flow.py +0 -5
  137. rasa/shared/core/flows/flows_list.py +1 -5
  138. rasa/shared/core/flows/flows_yaml_schema.json +0 -10
  139. rasa/shared/core/flows/validation.py +0 -96
  140. rasa/shared/core/flows/yaml_flows_io.py +4 -13
  141. rasa/shared/core/slots.py +0 -5
  142. rasa/shared/importers/importer.py +2 -19
  143. rasa/shared/importers/rasa.py +1 -5
  144. rasa/shared/nlu/training_data/features.py +2 -120
  145. rasa/shared/nlu/training_data/formats/rasa_yaml.py +3 -18
  146. rasa/shared/providers/_configs/azure_openai_client_config.py +3 -5
  147. rasa/shared/providers/_configs/openai_client_config.py +1 -1
  148. rasa/shared/providers/_configs/self_hosted_llm_client_config.py +0 -1
  149. rasa/shared/providers/_configs/utils.py +0 -16
  150. rasa/shared/providers/embedding/_base_litellm_embedding_client.py +29 -18
  151. rasa/shared/providers/embedding/azure_openai_embedding_client.py +21 -54
  152. rasa/shared/providers/embedding/default_litellm_embedding_client.py +0 -24
  153. rasa/shared/providers/llm/_base_litellm_client.py +31 -63
  154. rasa/shared/providers/llm/azure_openai_llm_client.py +29 -50
  155. rasa/shared/providers/llm/default_litellm_llm_client.py +0 -24
  156. rasa/shared/providers/llm/self_hosted_llm_client.py +29 -17
  157. rasa/shared/providers/mappings.py +0 -19
  158. rasa/shared/utils/common.py +2 -37
  159. rasa/shared/utils/io.py +6 -28
  160. rasa/shared/utils/llm.py +46 -353
  161. rasa/shared/utils/yaml.py +82 -181
  162. rasa/studio/auth.py +5 -3
  163. rasa/studio/config.py +4 -13
  164. rasa/studio/constants.py +0 -1
  165. rasa/studio/data_handler.py +4 -13
  166. rasa/studio/upload.py +80 -175
  167. rasa/telemetry.py +17 -94
  168. rasa/tracing/config.py +1 -3
  169. rasa/tracing/instrumentation/attribute_extractors.py +17 -94
  170. rasa/tracing/instrumentation/instrumentation.py +0 -121
  171. rasa/utils/common.py +0 -5
  172. rasa/utils/endpoints.py +1 -27
  173. rasa/utils/io.py +81 -7
  174. rasa/utils/log_utils.py +2 -9
  175. rasa/utils/tensorflow/model_data.py +193 -2
  176. rasa/validator.py +4 -110
  177. rasa/version.py +1 -1
  178. rasa_pro-3.11.0a1.dist-info/METADATA +576 -0
  179. {rasa_pro-3.11.0.dist-info → rasa_pro-3.11.0a1.dist-info}/RECORD +182 -216
  180. rasa/core/actions/action_repeat_bot_messages.py +0 -89
  181. rasa/core/channels/inspector/dist/assets/flowDiagram-v2-855bc5b3-736177bf.js +0 -1
  182. rasa/core/channels/inspector/src/helpers/audiostream.ts +0 -165
  183. rasa/core/channels/voice_stream/asr/azure.py +0 -129
  184. rasa/core/channels/voice_stream/browser_audio.py +0 -107
  185. rasa/core/channels/voice_stream/call_state.py +0 -23
  186. rasa/dialogue_understanding/commands/repeat_bot_messages_command.py +0 -60
  187. rasa/dialogue_understanding/commands/user_silence_command.py +0 -59
  188. rasa/dialogue_understanding/patterns/repeat.py +0 -37
  189. rasa/dialogue_understanding/patterns/user_silence.py +0 -37
  190. rasa/model_manager/__init__.py +0 -0
  191. rasa/model_manager/config.py +0 -40
  192. rasa/model_manager/model_api.py +0 -559
  193. rasa/model_manager/runner_service.py +0 -286
  194. rasa/model_manager/socket_bridge.py +0 -146
  195. rasa/model_manager/studio_jwt_auth.py +0 -86
  196. rasa/model_manager/trainer_service.py +0 -325
  197. rasa/model_manager/utils.py +0 -87
  198. rasa/model_manager/warm_rasa_process.py +0 -187
  199. rasa/model_service.py +0 -112
  200. rasa/shared/core/flows/utils.py +0 -39
  201. rasa/shared/providers/_configs/litellm_router_client_config.py +0 -220
  202. rasa/shared/providers/_configs/model_group_config.py +0 -167
  203. rasa/shared/providers/_configs/rasa_llm_client_config.py +0 -73
  204. rasa/shared/providers/_utils.py +0 -79
  205. rasa/shared/providers/embedding/litellm_router_embedding_client.py +0 -135
  206. rasa/shared/providers/llm/litellm_router_llm_client.py +0 -182
  207. rasa/shared/providers/llm/rasa_llm_client.py +0 -112
  208. rasa/shared/providers/router/__init__.py +0 -0
  209. rasa/shared/providers/router/_base_litellm_router_client.py +0 -183
  210. rasa/shared/providers/router/router_client.py +0 -73
  211. rasa/shared/utils/health_check/__init__.py +0 -0
  212. rasa/shared/utils/health_check/embeddings_health_check_mixin.py +0 -31
  213. rasa/shared/utils/health_check/health_check.py +0 -258
  214. rasa/shared/utils/health_check/llm_health_check_mixin.py +0 -31
  215. rasa/utils/sanic_error_handler.py +0 -32
  216. rasa/utils/tensorflow/feature_array.py +0 -366
  217. rasa_pro-3.11.0.dist-info/METADATA +0 -198
  218. {rasa_pro-3.11.0.dist-info → rasa_pro-3.11.0a1.dist-info}/NOTICE +0 -0
  219. {rasa_pro-3.11.0.dist-info → rasa_pro-3.11.0a1.dist-info}/WHEEL +0 -0
  220. {rasa_pro-3.11.0.dist-info → rasa_pro-3.11.0a1.dist-info}/entry_points.txt +0 -0
rasa/shared/utils/llm.py CHANGED
@@ -1,5 +1,3 @@
1
- import json
2
- from copy import deepcopy
3
1
  from functools import wraps
4
2
  from typing import (
5
3
  Any,
@@ -13,19 +11,14 @@ from typing import (
13
11
  Union,
14
12
  cast,
15
13
  )
16
-
14
+ import json
17
15
  import structlog
18
16
 
19
17
  import rasa.shared.utils.io
20
- from rasa.core.utils import AvailableEndpoints
21
18
  from rasa.shared.constants import (
22
19
  RASA_PATTERN_INTERNAL_ERROR_USER_INPUT_TOO_LONG,
23
20
  RASA_PATTERN_INTERNAL_ERROR_USER_INPUT_EMPTY,
24
21
  PROVIDER_CONFIG_KEY,
25
- MODEL_GROUP_CONFIG_KEY,
26
- MODEL_GROUP_ID_CONFIG_KEY,
27
- MODELS_CONFIG_KEY,
28
- ROUTER_CONFIG_KEY,
29
22
  )
30
23
  from rasa.shared.core.events import BotUttered, UserUttered
31
24
  from rasa.shared.core.slots import Slot, BooleanSlot, CategoricalSlot
@@ -35,7 +28,7 @@ from rasa.shared.engine.caching import (
35
28
  from rasa.shared.exceptions import (
36
29
  FileIOException,
37
30
  FileNotFoundException,
38
- InvalidConfigException,
31
+ ProviderClientValidationError,
39
32
  )
40
33
  from rasa.shared.providers._configs.azure_openai_client_config import (
41
34
  is_azure_openai_config,
@@ -58,11 +51,11 @@ from rasa.shared.providers.mappings import (
58
51
  HUGGINGFACE_LOCAL_EMBEDDING_PROVIDER,
59
52
  get_client_config_class_from_provider,
60
53
  )
54
+ from rasa.shared.utils.cli import print_error_and_exit
61
55
 
62
56
  if TYPE_CHECKING:
63
57
  from rasa.shared.core.trackers import DialogueStateTracker
64
58
 
65
-
66
59
  structlogger = structlog.get_logger()
67
60
 
68
61
  USER = "USER"
@@ -83,8 +76,6 @@ DEFAULT_OPENAI_MAX_GENERATED_TOKENS = 256
83
76
 
84
77
  DEFAULT_MAX_USER_INPUT_CHARACTERS = 420
85
78
 
86
- DEPLOYMENT_CENTRIC_PROVIDERS = [AZURE_OPENAI_PROVIDER]
87
-
88
79
  # Placeholder messages used in the transcript for
89
80
  # instances where user input results in an error
90
81
  ERROR_PLACEHOLDER = {
@@ -253,75 +244,7 @@ def sanitize_message_for_prompt(text: Optional[str]) -> str:
253
244
  def combine_custom_and_default_config(
254
245
  custom_config: Optional[Dict[str, Any]], default_config: Dict[str, Any]
255
246
  ) -> Dict[Text, Any]:
256
- """Merges the given model configuration with the default configuration.
257
-
258
- This method supports both single model configurations and model group configurations
259
- (configs that have the `models` key).
260
-
261
- If `custom_config` is a single model configuration, it merges `custom_config` with
262
- `default_config`, which is also a single model configuration.
263
-
264
- If `custom_config` is a model group configuration (contains the `models` key), it
265
- applies the merging process to each model configuration within the group
266
- individually, merging each with the `default_config`.
267
-
268
- Note that `default_config` is always a single model configuration.
269
-
270
- The method ensures that the provider is set and all deprecated keys are resolved,
271
- resulting in a valid client configuration.
272
-
273
- Args:
274
- custom_config: The custom configuration containing values to overwrite defaults.
275
- Can be a single model configuration or a model group configuration with a
276
- `models` key.
277
- default_config: The default configuration, which is a single model
278
- configuration.
279
-
280
- Returns:
281
- The merged configuration, either a single model configuration or a model group
282
- configuration with merged models.
283
- """
284
- if custom_config and MODELS_CONFIG_KEY in custom_config:
285
- return _combine_model_groups_configs_with_default_config(
286
- custom_config, default_config
287
- )
288
- else:
289
- return _combine_single_model_configs(custom_config, default_config)
290
-
291
-
292
- def _combine_model_groups_configs_with_default_config(
293
- model_group_config: Dict[str, Any], default_config: Dict[str, Any]
294
- ) -> Dict[Text, Any]:
295
- """Merges each model configuration within a model group with the default
296
- configuration.
297
-
298
- This method processes model group configurations by applying the merging process to
299
- each model configuration within the group individually.
300
-
301
- Args:
302
- model_group_config: The model group configuration containing a list of model
303
- configurations under the `models` key.
304
- default_config: The default configuration for a single model.
305
-
306
- Returns:
307
- The merged model group configuration with each model configuration merged
308
- with the default configuration.
309
- """
310
- model_group_config = deepcopy(model_group_config)
311
- model_group_config_combined_with_defaults = [
312
- _combine_single_model_configs(model_config, default_config)
313
- for model_config in model_group_config[MODELS_CONFIG_KEY]
314
- ]
315
- # Update the custom models config with the combined config.
316
- model_group_config[MODELS_CONFIG_KEY] = model_group_config_combined_with_defaults
317
- return model_group_config
318
-
319
-
320
- @_cache_combine_custom_and_default_configs
321
- def _combine_single_model_configs(
322
- custom_config: Optional[Dict[str, Any]], default_config: Dict[str, Any]
323
- ) -> Dict[Text, Any]:
324
- """Merges the given model config with the default config.
247
+ """Merges the given llm config with the default config.
325
248
 
326
249
  This method guarantees that the provider is set and all the deprecated keys are
327
250
  resolved. Hence, produces only a valid client config.
@@ -406,105 +329,6 @@ def llm_factory(
406
329
  ) -> LLMClient:
407
330
  """Creates an LLM from the given config.
408
331
 
409
- If the config is using the old syntax, e.g. defining the llm client directly in
410
- config.yaml, then standalone client is initialised (no routing).
411
-
412
- If the config uses the using the new, model group syntax, defined in the
413
- endpoints.yml, then router client is initialised if there are more than one model
414
- within the group.
415
-
416
- Examples:
417
- The config below will result in a standalone client:
418
- ```
419
- {
420
- "provider": "openai",
421
- "model": "gpt-4",
422
- "timeout": 10,
423
- "num_retries": 3,
424
- }
425
- ```
426
-
427
- The config below will also result in a standalone client:
428
- ```
429
- {
430
- "id": "model-group-id",
431
- "models": [
432
- {"provider": "openai", "model": "gpt-4", "api_key": "test"},
433
- ],
434
- }
435
- ```
436
-
437
- The config below will result in a router client:
438
- ```
439
- {
440
- "id": "test-model-group-id",
441
- "models": [
442
- {"provider": "openai", "model": "gpt-4", "api_key": "test"},
443
- {
444
- "provider": "azure",
445
- "deployment": "test-deployment",
446
- "api_key": "test",
447
- "api_base": "test-api-base",
448
- },
449
- ],
450
- "router": {"routing_strategy": "test"},
451
- }
452
- ```
453
-
454
- Args:
455
- custom_config: The custom config containing values to overwrite defaults.
456
- default_config: The default config.
457
-
458
- Returns:
459
- Instantiated client based on the configuration.
460
- """
461
- if custom_config:
462
- if ROUTER_CONFIG_KEY in custom_config:
463
- return llm_router_factory(custom_config, default_config)
464
- if MODELS_CONFIG_KEY in custom_config:
465
- return llm_client_factory(
466
- custom_config[MODELS_CONFIG_KEY][0], default_config
467
- )
468
- return llm_client_factory(custom_config, default_config)
469
-
470
-
471
- def llm_router_factory(
472
- router_config: Dict[str, Any], default_model_config: Dict[str, Any], **kwargs: Any
473
- ) -> LLMClient:
474
- """Creates an LLM Router using the provided configurations.
475
-
476
- This function initializes an LLM Router based on the given router configuration,
477
- which includes multiple model configurations. For each model specified in the router
478
- configuration, any missing parameters are supplemented using the default model
479
- configuration.
480
-
481
- Args:
482
- router_config: The full router configuration containing multiple model
483
- configurations. Each model's configuration can override parameters from the
484
- default model configuration.
485
- default_model_config: The default configuration parameters for a single model.
486
- These defaults are used to fill in any missing parameters in each model's
487
- configuration within the router.
488
-
489
- Returns:
490
- An instance that conforms to both `LLMClient` and `RouterClient` protocols
491
- representing the configured LLM Router.
492
- """
493
- from rasa.shared.providers.llm.litellm_router_llm_client import (
494
- LiteLLMRouterLLMClient,
495
- )
496
-
497
- combined_config = _combine_model_groups_configs_with_default_config(
498
- router_config, default_model_config
499
- )
500
- return LiteLLMRouterLLMClient.from_config(combined_config)
501
-
502
-
503
- def llm_client_factory(
504
- custom_config: Optional[Dict[str, Any]], default_config: Dict[str, Any]
505
- ) -> LLMClient:
506
- """Creates an LLM from the given config.
507
-
508
332
  Args:
509
333
  custom_config: The custom config containing values to overwrite defaults
510
334
  default_config: The default config.
@@ -526,110 +350,6 @@ def llm_client_factory(
526
350
  @_cache_factory
527
351
  def embedder_factory(
528
352
  custom_config: Optional[Dict[str, Any]], default_config: Dict[str, Any]
529
- ) -> EmbeddingClient:
530
- """Creates an embedding client from the given config.
531
-
532
- If the config is using the old syntax, e.g. defining the llm client directly in
533
- config.yaml, then standalone client is initialised (no routing).
534
-
535
- If the config uses the using the new, model group syntax, defined in the
536
- endpoints.yml, then router client is initialised if there are more than one model
537
- within the group and the router is defined.
538
-
539
- Examples:
540
- The config below will result in a standalone client:
541
- ```
542
- {
543
- "provider": "openai",
544
- "model": "text-embedding-3-small",
545
- "timeout": 10,
546
- "num_retries": 3,
547
- }
548
- ```
549
-
550
- The config below will also result in a standalone client:
551
- ```
552
- {
553
- "id": "model-group-id",
554
- "models": [
555
- {
556
- "provider": "openai",
557
- "model": "test-embedding-3-small",
558
- "api_key": "test"
559
- },
560
- ],
561
- }
562
- ```
563
-
564
- The config below will result in a router client:
565
- ```
566
- {
567
- "id": "test-model-group-id",
568
- "models": [
569
- {"provider": "openai", "model": "gpt-4", "api_key": "test"},
570
- {
571
- "provider": "azure",
572
- "deployment": "test-deployment",
573
- "api_key": "test",
574
- "api_base": "test-api-base",
575
- },
576
- ],
577
- "router": {"routing_strategy": "test"},
578
- }
579
- ```
580
-
581
- Args:
582
- custom_config: The custom config containing values to overwrite defaults.
583
- default_config: The default config.
584
-
585
- Returns:
586
- Instantiated client based on the configuration.
587
- """
588
- if custom_config:
589
- if ROUTER_CONFIG_KEY in custom_config:
590
- return embedder_router_factory(custom_config, default_config)
591
- if MODELS_CONFIG_KEY in custom_config:
592
- return embedder_client_factory(
593
- custom_config[MODELS_CONFIG_KEY][0], default_config
594
- )
595
- return embedder_client_factory(custom_config, default_config)
596
-
597
-
598
- def embedder_router_factory(
599
- router_config: Dict[str, Any], default_model_config: Dict[str, Any], **kwargs: Any
600
- ) -> EmbeddingClient:
601
- """Creates an Embedder Router using the provided configurations.
602
-
603
- This function initializes an Embedder Router based on the given router
604
- configuration, which includes multiple model configurations. For each model
605
- specified in the router configuration, any missing parameters are supplemented using
606
- the default model configuration.
607
-
608
- Args:
609
- router_config: The full router configuration containing multiple model
610
- configurations. Each model's configuration can override parameters from the
611
- default model configuration.
612
- default_model_config: The default configuration parameters for a single model.
613
- These defaults are used to fill in any missing parameters in each model's
614
- configuration within the router.
615
-
616
- Returns:
617
- An instance that conforms to both `EmbeddingClient` and `RouterClient` protocols
618
- representing the configured Embedding Router.
619
- """
620
- from rasa.shared.providers.embedding.litellm_router_embedding_client import (
621
- LiteLLMRouterEmbeddingClient,
622
- )
623
-
624
- combined_config = _combine_model_groups_configs_with_default_config(
625
- router_config, default_model_config
626
- )
627
-
628
- return LiteLLMRouterEmbeddingClient.from_config(combined_config)
629
-
630
-
631
- def embedder_client_factory(
632
- custom_config: Optional[Dict[str, Any]], default_config: Dict[str, Any]
633
353
  ) -> EmbeddingClient:
634
354
  """Creates an Embedder from the given config.
635
355
 
@@ -685,76 +405,49 @@ def allowed_values_for_slot(slot: Slot) -> Union[str, None]:
685
405
  return None
686
406
 
687
407
 
688
- def resolve_model_client_config(
689
- model_config: Optional[Dict[str, Any]], component_name: Optional[str] = None
690
- ) -> Optional[Dict[str, Any]]:
691
- """Resolve the model group in the model config.
692
-
693
- 1. If the config is pointing to a model group, the corresponding model group
694
- of the endpoints.yml is returned.
695
- 2. If the config is using the old syntax, e.g. defining the llm
696
- directly in config.yml, the config is returned as is.
697
- 3. If the config is already resolved, return it as is.
698
-
699
- Args:
700
- model_config: The model config to be resolved.
701
- component_name: The name of the component.
702
- component_name: The method of the component.
703
-
704
- Returns:
705
- The resolved llm config.
706
- """
707
-
708
- def _raise_invalid_config_exception(reason: str) -> None:
709
- """Helper function to raise InvalidConfigException with a formatted message."""
710
- if component_name:
711
- message = (
712
- f"Could not resolve model group '{model_group_id}'"
713
- f" for component '{component_name}'."
714
- )
715
- else:
716
- message = f"Could not resolve model group '{model_group_id}'."
717
- message += f" {reason}"
718
- raise InvalidConfigException(message)
719
-
720
- if model_config is None:
721
- return None
722
-
723
- # Config is already resolved or defines a client without model groups
724
- if MODEL_GROUP_CONFIG_KEY not in model_config:
725
- return model_config
726
-
727
- model_group_id = model_config.get(MODEL_GROUP_CONFIG_KEY)
728
-
729
- endpoints = AvailableEndpoints.get_instance()
730
- if endpoints.model_groups is None:
731
- _raise_invalid_config_exception(
732
- reason=(
733
- "No model group with that id found in endpoints.yml. "
734
- "Please make sure to define the model group."
735
- )
408
+ def try_instantiate_llm_client(
409
+ custom_llm_config: Optional[Dict],
410
+ default_llm_config: Optional[Dict],
411
+ log_source_function: str,
412
+ log_source_component: str,
413
+ ) -> LLMClient:
414
+ """Validate llm configuration."""
415
+ try:
416
+ return llm_factory(custom_llm_config, default_llm_config)
417
+ except (ProviderClientValidationError, ValueError) as e:
418
+ structlogger.error(
419
+ f"{log_source_function}.llm_instantiation_failed",
420
+ message="Unable to instantiate LLM client.",
421
+ error=e,
736
422
  )
423
+ print_error_and_exit(
424
+ f"Unable to create the LLM client for component - {log_source_component}. "
425
+ f"Please make sure you specified the required environment variables. "
426
+ f"Error: {e}"
427
+ )
428
+
737
429
 
738
- copy_model_groups = deepcopy(endpoints.model_groups)
739
- model_group = [
740
- model_group
741
- for model_group in copy_model_groups # type: ignore[union-attr]
742
- if model_group.get(MODEL_GROUP_ID_CONFIG_KEY) == model_group_id
743
- ]
744
-
745
- if len(model_group) == 0:
746
- _raise_invalid_config_exception(
747
- reason=(
748
- "No model group with that id found in endpoints.yml. "
749
- "Please make sure to define the model group."
750
- )
430
+ def llm_api_health_check(
431
+ llm_client: LLMClient, log_source_function: str, log_source_component: str
432
+ ) -> None:
433
+ """Perform a health check on the LLM API."""
434
+ structlogger.info(
435
+ f"{log_source_function}.llm_api_call",
436
+ event_info=(
437
+ f"Performing a health check on the LLM API for the component - "
438
+ f"{log_source_component}."
439
+ ),
440
+ config=llm_client.config,
441
+ )
442
+ try:
443
+ llm_client.completion("hello")
444
+ except Exception as e:
445
+ structlogger.error(
446
+ f"{log_source_function}.llm_api_call_failed",
447
+ event_info="call to the LLM API failed.",
448
+ error=e,
751
449
  )
752
- if len(model_group) > 1:
753
- _raise_invalid_config_exception(
754
- reason=(
755
- "Multiple model groups with that id found in endpoints.yml. "
756
- "Please make sure to define the model group just once."
757
- )
450
+ print_error_and_exit(
451
+ f"Call to the LLM API failed for component - {log_source_component}. "
452
+ f"Error: {e}"
758
453
  )
759
-
760
- return model_group[0]