rasa-pro 3.11.0a4.dev3__py3-none-any.whl → 3.11.0rc2__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 (184) hide show
  1. rasa/__main__.py +22 -12
  2. rasa/api.py +1 -1
  3. rasa/cli/arguments/default_arguments.py +1 -2
  4. rasa/cli/arguments/shell.py +5 -1
  5. rasa/cli/e2e_test.py +1 -1
  6. rasa/cli/evaluate.py +8 -8
  7. rasa/cli/inspect.py +6 -4
  8. rasa/cli/llm_fine_tuning.py +1 -1
  9. rasa/cli/project_templates/calm/config.yml +5 -7
  10. rasa/cli/project_templates/calm/endpoints.yml +8 -0
  11. rasa/cli/project_templates/tutorial/config.yml +8 -5
  12. rasa/cli/project_templates/tutorial/data/flows.yml +1 -1
  13. rasa/cli/project_templates/tutorial/data/patterns.yml +5 -0
  14. rasa/cli/project_templates/tutorial/domain.yml +14 -0
  15. rasa/cli/project_templates/tutorial/endpoints.yml +7 -7
  16. rasa/cli/run.py +1 -1
  17. rasa/cli/scaffold.py +4 -2
  18. rasa/cli/studio/studio.py +18 -8
  19. rasa/cli/utils.py +5 -0
  20. rasa/cli/x.py +8 -8
  21. rasa/constants.py +1 -1
  22. rasa/core/actions/action_repeat_bot_messages.py +17 -0
  23. rasa/core/channels/channel.py +20 -0
  24. rasa/core/channels/inspector/dist/assets/{arc-6852c607.js → arc-bc141fb2.js} +1 -1
  25. rasa/core/channels/inspector/dist/assets/{c4Diagram-d0fbc5ce-acc952b2.js → c4Diagram-d0fbc5ce-be2db283.js} +1 -1
  26. rasa/core/channels/inspector/dist/assets/{classDiagram-936ed81e-848a7597.js → classDiagram-936ed81e-55366915.js} +1 -1
  27. rasa/core/channels/inspector/dist/assets/{classDiagram-v2-c3cb15f1-a73d3e68.js → classDiagram-v2-c3cb15f1-bb529518.js} +1 -1
  28. rasa/core/channels/inspector/dist/assets/{createText-62fc7601-e5ee049d.js → createText-62fc7601-b0ec81d6.js} +1 -1
  29. rasa/core/channels/inspector/dist/assets/{edges-f2ad444c-771e517e.js → edges-f2ad444c-6166330c.js} +1 -1
  30. rasa/core/channels/inspector/dist/assets/{erDiagram-9d236eb7-aa347178.js → erDiagram-9d236eb7-5ccc6a8e.js} +1 -1
  31. rasa/core/channels/inspector/dist/assets/{flowDb-1972c806-651fc57d.js → flowDb-1972c806-fca3bfe4.js} +1 -1
  32. rasa/core/channels/inspector/dist/assets/{flowDiagram-7ea5b25a-ca67804f.js → flowDiagram-7ea5b25a-4739080f.js} +1 -1
  33. rasa/core/channels/inspector/dist/assets/flowDiagram-v2-855bc5b3-736177bf.js +1 -0
  34. rasa/core/channels/inspector/dist/assets/{flowchart-elk-definition-abe16c3d-2dbc568d.js → flowchart-elk-definition-abe16c3d-7c1b0e0f.js} +1 -1
  35. rasa/core/channels/inspector/dist/assets/{ganttDiagram-9b5ea136-25a65bd8.js → ganttDiagram-9b5ea136-772fd050.js} +1 -1
  36. rasa/core/channels/inspector/dist/assets/{gitGraphDiagram-99d0ae7c-fdc7378d.js → gitGraphDiagram-99d0ae7c-8eae1dc9.js} +1 -1
  37. rasa/core/channels/inspector/dist/assets/{index-2c4b9a3b-6f1fd606.js → index-2c4b9a3b-f55afcdf.js} +1 -1
  38. rasa/core/channels/inspector/dist/assets/{index-efdd30c1.js → index-e7cef9de.js} +68 -68
  39. rasa/core/channels/inspector/dist/assets/{infoDiagram-736b4530-cb1a041a.js → infoDiagram-736b4530-124d4a14.js} +1 -1
  40. rasa/core/channels/inspector/dist/assets/{journeyDiagram-df861f2b-14609879.js → journeyDiagram-df861f2b-7c4fae44.js} +1 -1
  41. rasa/core/channels/inspector/dist/assets/{layout-2490f52b.js → layout-b9885fb6.js} +1 -1
  42. rasa/core/channels/inspector/dist/assets/{line-40186f1f.js → line-7c59abb6.js} +1 -1
  43. rasa/core/channels/inspector/dist/assets/{linear-08814e93.js → linear-4776f780.js} +1 -1
  44. rasa/core/channels/inspector/dist/assets/{mindmap-definition-beec6740-1a534584.js → mindmap-definition-beec6740-2332c46c.js} +1 -1
  45. rasa/core/channels/inspector/dist/assets/{pieDiagram-dbbf0591-72397b61.js → pieDiagram-dbbf0591-8fb39303.js} +1 -1
  46. rasa/core/channels/inspector/dist/assets/{quadrantDiagram-4d7f4fd6-3bb0b6a3.js → quadrantDiagram-4d7f4fd6-3c7180a2.js} +1 -1
  47. rasa/core/channels/inspector/dist/assets/{requirementDiagram-6fc4c22a-57334f61.js → requirementDiagram-6fc4c22a-e910bcb8.js} +1 -1
  48. rasa/core/channels/inspector/dist/assets/{sankeyDiagram-8f13d901-111e1297.js → sankeyDiagram-8f13d901-ead16c89.js} +1 -1
  49. rasa/core/channels/inspector/dist/assets/{sequenceDiagram-b655622a-10bcfe62.js → sequenceDiagram-b655622a-29a02a19.js} +1 -1
  50. rasa/core/channels/inspector/dist/assets/{stateDiagram-59f0c015-acaf7513.js → stateDiagram-59f0c015-042b3137.js} +1 -1
  51. rasa/core/channels/inspector/dist/assets/{stateDiagram-v2-2b26beab-3ec2a235.js → stateDiagram-v2-2b26beab-2178c0f3.js} +1 -1
  52. rasa/core/channels/inspector/dist/assets/{styles-080da4f6-62730289.js → styles-080da4f6-23ffa4fc.js} +1 -1
  53. rasa/core/channels/inspector/dist/assets/{styles-3dcbcfbf-5284ee76.js → styles-3dcbcfbf-94f59763.js} +1 -1
  54. rasa/core/channels/inspector/dist/assets/{styles-9c745c82-642435e3.js → styles-9c745c82-78a6bebc.js} +1 -1
  55. rasa/core/channels/inspector/dist/assets/{svgDrawCommon-4835440b-b250a350.js → svgDrawCommon-4835440b-eae2a6f6.js} +1 -1
  56. rasa/core/channels/inspector/dist/assets/{timeline-definition-5b62e21b-c2b147ed.js → timeline-definition-5b62e21b-5c968d92.js} +1 -1
  57. rasa/core/channels/inspector/dist/assets/{xychartDiagram-2b33534f-f92cfea9.js → xychartDiagram-2b33534f-fd3db0d5.js} +1 -1
  58. rasa/core/channels/inspector/dist/index.html +1 -1
  59. rasa/core/channels/inspector/src/App.tsx +1 -1
  60. rasa/core/channels/inspector/src/helpers/audiostream.ts +77 -16
  61. rasa/core/channels/socketio.py +2 -1
  62. rasa/core/channels/telegram.py +1 -1
  63. rasa/core/channels/twilio.py +1 -1
  64. rasa/core/channels/voice_ready/audiocodes.py +12 -0
  65. rasa/core/channels/voice_ready/jambonz.py +15 -4
  66. rasa/core/channels/voice_ready/twilio_voice.py +6 -21
  67. rasa/core/channels/voice_stream/asr/asr_event.py +5 -0
  68. rasa/core/channels/voice_stream/asr/azure.py +122 -0
  69. rasa/core/channels/voice_stream/asr/deepgram.py +16 -6
  70. rasa/core/channels/voice_stream/audio_bytes.py +1 -0
  71. rasa/core/channels/voice_stream/browser_audio.py +31 -8
  72. rasa/core/channels/voice_stream/call_state.py +23 -0
  73. rasa/core/channels/voice_stream/tts/azure.py +6 -2
  74. rasa/core/channels/voice_stream/tts/cartesia.py +10 -6
  75. rasa/core/channels/voice_stream/tts/tts_engine.py +1 -0
  76. rasa/core/channels/voice_stream/twilio_media_streams.py +27 -18
  77. rasa/core/channels/voice_stream/util.py +4 -4
  78. rasa/core/channels/voice_stream/voice_channel.py +189 -39
  79. rasa/core/featurizers/single_state_featurizer.py +22 -1
  80. rasa/core/featurizers/tracker_featurizers.py +115 -18
  81. rasa/core/nlg/contextual_response_rephraser.py +32 -30
  82. rasa/core/persistor.py +86 -39
  83. rasa/core/policies/enterprise_search_policy.py +119 -60
  84. rasa/core/policies/flows/flow_executor.py +7 -4
  85. rasa/core/policies/intentless_policy.py +78 -22
  86. rasa/core/policies/ted_policy.py +58 -33
  87. rasa/core/policies/unexpected_intent_policy.py +15 -7
  88. rasa/core/processor.py +25 -0
  89. rasa/core/training/interactive.py +34 -35
  90. rasa/core/utils.py +8 -3
  91. rasa/dialogue_understanding/coexistence/llm_based_router.py +39 -12
  92. rasa/dialogue_understanding/commands/change_flow_command.py +6 -0
  93. rasa/dialogue_understanding/commands/user_silence_command.py +59 -0
  94. rasa/dialogue_understanding/commands/utils.py +5 -0
  95. rasa/dialogue_understanding/generator/constants.py +2 -0
  96. rasa/dialogue_understanding/generator/flow_retrieval.py +49 -4
  97. rasa/dialogue_understanding/generator/llm_based_command_generator.py +37 -23
  98. rasa/dialogue_understanding/generator/multi_step/multi_step_llm_command_generator.py +57 -10
  99. rasa/dialogue_understanding/generator/nlu_command_adapter.py +19 -1
  100. rasa/dialogue_understanding/generator/single_step/single_step_llm_command_generator.py +71 -11
  101. rasa/dialogue_understanding/patterns/default_flows_for_patterns.yml +39 -0
  102. rasa/dialogue_understanding/patterns/user_silence.py +37 -0
  103. rasa/dialogue_understanding/processor/command_processor.py +21 -1
  104. rasa/e2e_test/e2e_test_case.py +85 -6
  105. rasa/e2e_test/e2e_test_runner.py +4 -2
  106. rasa/e2e_test/utils/io.py +1 -1
  107. rasa/engine/validation.py +316 -10
  108. rasa/model_manager/config.py +15 -3
  109. rasa/model_manager/model_api.py +15 -7
  110. rasa/model_manager/runner_service.py +8 -6
  111. rasa/model_manager/socket_bridge.py +6 -3
  112. rasa/model_manager/trainer_service.py +7 -5
  113. rasa/model_manager/utils.py +28 -7
  114. rasa/model_service.py +9 -2
  115. rasa/model_training.py +2 -0
  116. rasa/nlu/classifiers/diet_classifier.py +38 -25
  117. rasa/nlu/classifiers/logistic_regression_classifier.py +22 -9
  118. rasa/nlu/classifiers/sklearn_intent_classifier.py +37 -16
  119. rasa/nlu/extractors/crf_entity_extractor.py +93 -50
  120. rasa/nlu/featurizers/sparse_featurizer/count_vectors_featurizer.py +45 -16
  121. rasa/nlu/featurizers/sparse_featurizer/lexical_syntactic_featurizer.py +52 -17
  122. rasa/nlu/featurizers/sparse_featurizer/regex_featurizer.py +5 -3
  123. rasa/nlu/tokenizers/whitespace_tokenizer.py +3 -14
  124. rasa/server.py +3 -1
  125. rasa/shared/constants.py +36 -3
  126. rasa/shared/core/constants.py +7 -0
  127. rasa/shared/core/domain.py +26 -0
  128. rasa/shared/core/flows/flow.py +5 -0
  129. rasa/shared/core/flows/flows_list.py +5 -1
  130. rasa/shared/core/flows/flows_yaml_schema.json +10 -0
  131. rasa/shared/core/flows/utils.py +39 -0
  132. rasa/shared/core/flows/validation.py +96 -0
  133. rasa/shared/core/slots.py +5 -0
  134. rasa/shared/nlu/training_data/features.py +120 -2
  135. rasa/shared/providers/_configs/azure_openai_client_config.py +5 -3
  136. rasa/shared/providers/_configs/litellm_router_client_config.py +200 -0
  137. rasa/shared/providers/_configs/model_group_config.py +167 -0
  138. rasa/shared/providers/_configs/openai_client_config.py +1 -1
  139. rasa/shared/providers/_configs/rasa_llm_client_config.py +73 -0
  140. rasa/shared/providers/_configs/self_hosted_llm_client_config.py +1 -0
  141. rasa/shared/providers/_configs/utils.py +16 -0
  142. rasa/shared/providers/embedding/_base_litellm_embedding_client.py +18 -29
  143. rasa/shared/providers/embedding/azure_openai_embedding_client.py +54 -21
  144. rasa/shared/providers/embedding/litellm_router_embedding_client.py +135 -0
  145. rasa/shared/providers/llm/_base_litellm_client.py +37 -31
  146. rasa/shared/providers/llm/azure_openai_llm_client.py +50 -29
  147. rasa/shared/providers/llm/litellm_router_llm_client.py +127 -0
  148. rasa/shared/providers/llm/rasa_llm_client.py +112 -0
  149. rasa/shared/providers/llm/self_hosted_llm_client.py +1 -1
  150. rasa/shared/providers/mappings.py +19 -0
  151. rasa/shared/providers/router/__init__.py +0 -0
  152. rasa/shared/providers/router/_base_litellm_router_client.py +149 -0
  153. rasa/shared/providers/router/router_client.py +73 -0
  154. rasa/shared/utils/common.py +8 -0
  155. rasa/shared/utils/health_check/__init__.py +0 -0
  156. rasa/shared/utils/health_check/embeddings_health_check_mixin.py +31 -0
  157. rasa/shared/utils/health_check/health_check.py +256 -0
  158. rasa/shared/utils/health_check/llm_health_check_mixin.py +31 -0
  159. rasa/shared/utils/io.py +28 -6
  160. rasa/shared/utils/llm.py +353 -46
  161. rasa/shared/utils/yaml.py +111 -73
  162. rasa/studio/auth.py +3 -5
  163. rasa/studio/config.py +13 -4
  164. rasa/studio/constants.py +1 -0
  165. rasa/studio/data_handler.py +10 -3
  166. rasa/studio/upload.py +81 -26
  167. rasa/telemetry.py +92 -17
  168. rasa/tracing/config.py +2 -0
  169. rasa/tracing/instrumentation/attribute_extractors.py +94 -17
  170. rasa/tracing/instrumentation/instrumentation.py +121 -0
  171. rasa/utils/common.py +5 -0
  172. rasa/utils/io.py +7 -81
  173. rasa/utils/log_utils.py +9 -2
  174. rasa/utils/sanic_error_handler.py +32 -0
  175. rasa/utils/tensorflow/feature_array.py +366 -0
  176. rasa/utils/tensorflow/model_data.py +2 -193
  177. rasa/validator.py +70 -0
  178. rasa/version.py +1 -1
  179. {rasa_pro-3.11.0a4.dev3.dist-info → rasa_pro-3.11.0rc2.dist-info}/METADATA +11 -10
  180. {rasa_pro-3.11.0a4.dev3.dist-info → rasa_pro-3.11.0rc2.dist-info}/RECORD +183 -163
  181. rasa/core/channels/inspector/dist/assets/flowDiagram-v2-855bc5b3-587d82d8.js +0 -1
  182. {rasa_pro-3.11.0a4.dev3.dist-info → rasa_pro-3.11.0rc2.dist-info}/NOTICE +0 -0
  183. {rasa_pro-3.11.0a4.dev3.dist-info → rasa_pro-3.11.0rc2.dist-info}/WHEEL +0 -0
  184. {rasa_pro-3.11.0a4.dev3.dist-info → rasa_pro-3.11.0rc2.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,112 @@
1
+ from typing import Any, Dict, Optional
2
+
3
+ import structlog
4
+
5
+ from rasa.shared.constants import (
6
+ RASA_PROVIDER,
7
+ OPENAI_PROVIDER,
8
+ )
9
+ from rasa.shared.providers._configs.rasa_llm_client_config import (
10
+ RasaLLMClientConfig,
11
+ )
12
+ from rasa.utils.licensing import retrieve_license_from_env
13
+ from rasa.shared.providers.llm._base_litellm_client import _BaseLiteLLMClient
14
+
15
+
16
+ structlogger = structlog.get_logger()
17
+
18
+
19
+ class RasaLLMClient(_BaseLiteLLMClient):
20
+ """A client for interfacing with a Rasa-Hosted LLM endpoint that uses
21
+
22
+ Parameters:
23
+ model (str): The model or deployment name.
24
+ api_base (str): The base URL of the API endpoint.
25
+ kwargs: Any: Additional configuration parameters that can include, but
26
+ are not limited to model parameters and lite-llm specific
27
+ parameters. These parameters will be passed to the
28
+ completion/acompletion calls. To see what it can include, visit:
29
+
30
+ Raises:
31
+ ProviderClientValidationError: If validation of the client setup fails.
32
+ ProviderClientAPIException: If the API request fails.
33
+ """
34
+
35
+ def __init__(
36
+ self,
37
+ model: str,
38
+ api_base: str,
39
+ **kwargs: Any,
40
+ ):
41
+ super().__init__() # type: ignore
42
+ self._model = model
43
+ self._api_base = api_base
44
+ self._use_chat_completions_endpoint = True
45
+ self._extra_parameters = kwargs or {}
46
+
47
+ @property
48
+ def model(self) -> str:
49
+ return self._model
50
+
51
+ @property
52
+ def api_base(self) -> Optional[str]:
53
+ """
54
+ Returns the base API URL for the openai llm client.
55
+ """
56
+ return self._api_base
57
+
58
+ @property
59
+ def provider(self) -> str:
60
+ """
61
+ Returns the provider name for the self hosted llm client.
62
+
63
+ Returns:
64
+ String representing the provider name.
65
+ """
66
+ return RASA_PROVIDER
67
+
68
+ @property
69
+ def _litellm_model_name(self) -> str:
70
+ return f"{OPENAI_PROVIDER}/{self._model}"
71
+
72
+ @property
73
+ def _litellm_extra_parameters(self) -> Dict[str, Any]:
74
+ return self._extra_parameters
75
+
76
+ @property
77
+ def config(self) -> dict:
78
+ return RasaLLMClientConfig(
79
+ model=self._model,
80
+ api_base=self._api_base,
81
+ extra_parameters=self._extra_parameters,
82
+ ).to_dict()
83
+
84
+ @property
85
+ def _completion_fn_args(self) -> Dict[str, Any]:
86
+ """Returns the completion arguments for invoking a call through
87
+ LiteLLM's completion functions.
88
+ """
89
+ fn_args = super()._completion_fn_args
90
+ fn_args.update(
91
+ {"api_base": self.api_base, "api_key": retrieve_license_from_env()}
92
+ )
93
+ return fn_args
94
+
95
+ @classmethod
96
+ def from_config(cls, config: Dict[str, Any]) -> "RasaLLMClient":
97
+ try:
98
+ client_config = RasaLLMClientConfig.from_dict(config)
99
+ except ValueError as e:
100
+ message = "Cannot instantiate a client from the passed configuration."
101
+ structlogger.error(
102
+ "rasa_llm_client.from_config.error",
103
+ message=message,
104
+ config=config,
105
+ original_error=e,
106
+ )
107
+ raise
108
+ return cls(
109
+ model=client_config.model,
110
+ api_base=client_config.api_base,
111
+ **client_config.extra_parameters,
112
+ )
@@ -160,7 +160,7 @@ class SelfHostedLLMClient(_BaseLiteLLMClient):
160
160
  """Returns the value of LiteLLM's model parameter to be used in
161
161
  completion/acompletion in LiteLLM format:
162
162
 
163
- <openai>/<model or deployment name>
163
+ <hosted_vllm>/<model or deployment name>
164
164
  """
165
165
  if self.model and f"{SELF_HOSTED_VLLM_PREFIX}/" not in self.model:
166
166
  return f"{SELF_HOSTED_VLLM_PREFIX}/{self.model}"
@@ -5,6 +5,8 @@ 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,
8
10
  )
9
11
  from rasa.shared.providers.embedding.azure_openai_embedding_client import (
10
12
  AzureOpenAIEmbeddingClient,
@@ -24,6 +26,7 @@ from rasa.shared.providers.llm.default_litellm_llm_client import DefaultLiteLLMC
24
26
  from rasa.shared.providers.llm.llm_client import LLMClient
25
27
  from rasa.shared.providers.llm.openai_llm_client import OpenAILLMClient
26
28
  from rasa.shared.providers.llm.self_hosted_llm_client import SelfHostedLLMClient
29
+ from rasa.shared.providers.llm.rasa_llm_client import RasaLLMClient
27
30
  from rasa.shared.providers._configs.azure_openai_client_config import (
28
31
  AzureOpenAIClientConfig,
29
32
  )
@@ -37,12 +40,15 @@ from rasa.shared.providers._configs.openai_client_config import OpenAIClientConf
37
40
  from rasa.shared.providers._configs.self_hosted_llm_client_config import (
38
41
  SelfHostedLLMClientConfig,
39
42
  )
43
+ from rasa.shared.providers._configs.rasa_llm_client_config import RasaLLMClientConfig
44
+
40
45
  from rasa.shared.providers._configs.client_config import ClientConfig
41
46
 
42
47
  _provider_to_llm_client_mapping: Dict[str, Type[LLMClient]] = {
43
48
  OPENAI_PROVIDER: OpenAILLMClient,
44
49
  AZURE_OPENAI_PROVIDER: AzureOpenAILLMClient,
45
50
  SELF_HOSTED_PROVIDER: SelfHostedLLMClient,
51
+ RASA_PROVIDER: RasaLLMClient,
46
52
  }
47
53
 
48
54
  _provider_to_embedding_client_mapping: Dict[str, Type[EmbeddingClient]] = {
@@ -56,6 +62,15 @@ _provider_to_client_config_class_mapping: Dict[str, Type] = {
56
62
  AZURE_OPENAI_PROVIDER: AzureOpenAIClientConfig,
57
63
  HUGGINGFACE_LOCAL_EMBEDDING_PROVIDER: HuggingFaceLocalEmbeddingClientConfig,
58
64
  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,
59
74
  }
60
75
 
61
76
 
@@ -73,3 +88,7 @@ def get_client_config_class_from_provider(provider: str) -> Type[ClientConfig]:
73
88
  return _provider_to_client_config_class_mapping.get(
74
89
  provider, DefaultLiteLLMClientConfig
75
90
  )
91
+
92
+
93
+ def get_prefix_from_provider(provider: str) -> str:
94
+ return _provider_to_prefix_mapping.get(provider, provider)
File without changes
@@ -0,0 +1,149 @@
1
+ from typing import Any, Dict, List
2
+ import structlog
3
+
4
+ from litellm import Router
5
+
6
+ from rasa.shared.constants import (
7
+ MODEL_LIST_KEY,
8
+ MODEL_GROUP_ID_CONFIG_KEY,
9
+ ROUTER_CONFIG_KEY,
10
+ )
11
+ from rasa.shared.exceptions import ProviderClientValidationError
12
+ from rasa.shared.providers._configs.litellm_router_client_config import (
13
+ LiteLLMRouterClientConfig,
14
+ )
15
+ from rasa.shared.utils.io import resolve_environment_variables
16
+
17
+ structlogger = structlog.get_logger()
18
+
19
+
20
+ class _BaseLiteLLMRouterClient:
21
+ """An abstract base class for LiteLLM Router clients.
22
+
23
+ This class defines the interface and common functionality for all the router clients
24
+ based on LiteLLM.
25
+
26
+ The class is made private to prevent it from being part of the public-facing
27
+ interface, as it serves as an internal base class for specific implementations of
28
+ router clients that are based on LiteLLM router implementation.
29
+
30
+ Parameters:
31
+ model_group_id (str): The model group ID.
32
+ model_configurations (List[Dict[str, Any]]): The list of model configurations.
33
+ router_settings (Dict[str, Any]): The router settings.
34
+ kwargs (Optional[Dict[str, Any]]): Additional configuration parameters.
35
+
36
+ Raises:
37
+ ProviderClientValidationError: If validation of the client setup fails.
38
+ """
39
+
40
+ def __init__(
41
+ self,
42
+ model_group_id: str,
43
+ model_configurations: List[Dict[str, Any]],
44
+ router_settings: Dict[str, Any],
45
+ **kwargs: Any,
46
+ ):
47
+ self._model_group_id = model_group_id
48
+ self._model_configurations = model_configurations
49
+ self._router_settings = router_settings
50
+ self._extra_parameters = kwargs or {}
51
+ try:
52
+ resolved_model_configurations = (
53
+ self._resolve_env_vars_in_model_configurations()
54
+ )
55
+ self._router_client = Router(
56
+ model_list=resolved_model_configurations, **router_settings
57
+ )
58
+ except Exception as e:
59
+ event_info = "Cannot instantiate a router client."
60
+ structlogger.error(
61
+ "_base_litellm_router_client.init.error",
62
+ event_info=event_info,
63
+ model_group_id=model_group_id,
64
+ models=model_configurations,
65
+ router=router_settings,
66
+ original_error=e,
67
+ )
68
+ raise ProviderClientValidationError(f"{event_info} Original error: {e}")
69
+
70
+ @classmethod
71
+ def from_config(cls, config: Dict[str, Any]) -> "_BaseLiteLLMRouterClient":
72
+ """Instantiates a LiteLLM Router Embedding client from a configuration dict.
73
+
74
+ Args:
75
+ config: (Dict[str, Any]) The configuration dictionary.
76
+
77
+ Returns:
78
+ LiteLLMRouterLLMClient: The instantiated LiteLLM Router LLM client.
79
+
80
+ Raises:
81
+ ValueError: If the configuration is invalid.
82
+ """
83
+ try:
84
+ client_config = LiteLLMRouterClientConfig.from_dict(config)
85
+ except (KeyError, ValueError) as e:
86
+ message = "Cannot instantiate a client from the passed configuration."
87
+ structlogger.error(
88
+ "litellm_router_llm_client.from_config.error",
89
+ message=message,
90
+ config=config,
91
+ original_error=e,
92
+ )
93
+ raise
94
+
95
+ return cls(
96
+ model_group_id=client_config.model_group_id,
97
+ model_configurations=client_config.litellm_model_list,
98
+ router_settings=client_config.router,
99
+ **client_config.extra_parameters,
100
+ )
101
+
102
+ @property
103
+ def model_group_id(self) -> str:
104
+ """Returns the model group ID for the LiteLLM Router client."""
105
+ return self._model_group_id
106
+
107
+ @property
108
+ def model_configurations(self) -> List[Dict[str, Any]]:
109
+ """Returns the model configurations for the LiteLLM Router client."""
110
+ return self._model_configurations
111
+
112
+ @property
113
+ def router_settings(self) -> Dict[str, Any]:
114
+ """Returns the router settings for the LiteLLM Router client."""
115
+ return self._router_settings
116
+
117
+ @property
118
+ def router_client(self) -> Router:
119
+ """Returns the instantiated LiteLLM Router client."""
120
+ return self._router_client
121
+
122
+ @property
123
+ def _litellm_extra_parameters(self) -> Dict[str, Any]:
124
+ """
125
+ Returns the extra parameters for the LiteLLM Router client.
126
+
127
+ Returns:
128
+ Dictionary containing the model parameters.
129
+ """
130
+ return self._extra_parameters
131
+
132
+ @property
133
+ def config(self) -> Dict:
134
+ """Returns the configuration for the LiteLLM Router client in LiteLLM format."""
135
+ return {
136
+ MODEL_GROUP_ID_CONFIG_KEY: self.model_group_id,
137
+ MODEL_LIST_KEY: self.model_configurations,
138
+ ROUTER_CONFIG_KEY: self.router_settings,
139
+ **self._litellm_extra_parameters,
140
+ }
141
+
142
+ def _resolve_env_vars_in_model_configurations(self) -> List:
143
+ model_configuration_with_resolved_keys = []
144
+ for model_configuration in self.model_configurations:
145
+ resolved_model_configuration = resolve_environment_variables(
146
+ model_configuration
147
+ )
148
+ model_configuration_with_resolved_keys.append(resolved_model_configuration)
149
+ return model_configuration_with_resolved_keys
@@ -0,0 +1,73 @@
1
+ from typing import Any, Dict, List, Protocol, runtime_checkable
2
+
3
+
4
+ @runtime_checkable
5
+ class RouterClient(Protocol):
6
+ """
7
+ Protocol for a Router client that specifies the interface for interacting
8
+ with the API.
9
+ """
10
+
11
+ @classmethod
12
+ def from_config(cls, config: dict) -> "RouterClient":
13
+ """
14
+ Initializes the router client with the given configuration.
15
+
16
+ This class method should be implemented to parse the given
17
+ configuration and create an instance of an router client.
18
+ """
19
+ ...
20
+
21
+ @property
22
+ def config(self) -> Dict:
23
+ """
24
+ Returns the configuration for that the router client is initialized with.
25
+
26
+ This property should be implemented to return a dictionary containing
27
+ the client configuration settings for the router client.
28
+ """
29
+ ...
30
+
31
+ @property
32
+ def router_settings(self) -> Dict[str, Any]:
33
+ """
34
+ Returns the router settings for the Router client.
35
+
36
+ This property should be implemented to return a dictionary containing
37
+ the router settings for the router client.
38
+ """
39
+ ...
40
+
41
+ @property
42
+ def model_group_id(self) -> str:
43
+ """
44
+ Returns the model group ID for the Router client.
45
+
46
+ This property should be implemented to return the model group ID
47
+ for the router client.
48
+ """
49
+ ...
50
+
51
+ @property
52
+ def model_configurations(self) -> List[Dict[str, Any]]:
53
+ """
54
+ Returns the list of model configurations for the Router client.
55
+
56
+ This property should be implemented to return the list of model configurations
57
+ for the router client as a list of dictionaries.
58
+
59
+ Each dictionary should contain the model configuration.
60
+ Ideally, the `ModelGroupConfig` should parse the model configurations
61
+ and generate this list of dictionaries.
62
+ """
63
+ ...
64
+
65
+ @property
66
+ def router_client(self) -> object:
67
+ """
68
+ Returns the instantiated Router client.
69
+
70
+ This property should be implemented to return the instantiated
71
+ Router client.
72
+ """
73
+ ...
@@ -190,6 +190,14 @@ def mark_as_experimental_feature(feature_name: Text) -> None:
190
190
  )
191
191
 
192
192
 
193
+ def mark_as_beta_feature(feature_name: Text) -> None:
194
+ """Warns users that they are using a beta feature."""
195
+ logger.warning(
196
+ f"🔬 Beta Feature: {feature_name} is in beta. It may have unexpected"
197
+ "behaviour and might be changed in the future."
198
+ )
199
+
200
+
193
201
  def arguments_of(func: Callable) -> List[Text]:
194
202
  """Return the parameters of the function `func` as a list of names."""
195
203
  import inspect
File without changes
@@ -0,0 +1,31 @@
1
+ from typing import Optional, Dict, Any
2
+
3
+
4
+ class EmbeddingsHealthCheckMixin:
5
+ """Mixin class that provides methods for performing embeddings health checks during
6
+ training and inference within components.
7
+
8
+ This mixin offers static methods that wrap the following health check functions:
9
+ - `perform_embeddings_health_check`
10
+ """
11
+
12
+ @staticmethod
13
+ def perform_embeddings_health_check(
14
+ custom_embeddings_config: Optional[Dict[str, Any]],
15
+ default_embeddings_config: Dict[str, Any],
16
+ log_source_method: str,
17
+ log_source_component: str,
18
+ ) -> None:
19
+ """Wraps the `perform_embeddings_health_check` function to enable
20
+ tracing and instrumentation.
21
+ """
22
+ from rasa.shared.utils.health_check.health_check import (
23
+ perform_embeddings_health_check,
24
+ )
25
+
26
+ perform_embeddings_health_check(
27
+ custom_embeddings_config,
28
+ default_embeddings_config,
29
+ log_source_method,
30
+ log_source_component,
31
+ )