rasa-pro 3.10.16__py3-none-any.whl → 3.11.0__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 (240) hide show
  1. rasa/__main__.py +31 -15
  2. rasa/api.py +12 -2
  3. rasa/cli/arguments/default_arguments.py +24 -4
  4. rasa/cli/arguments/run.py +15 -0
  5. rasa/cli/arguments/shell.py +5 -1
  6. rasa/cli/arguments/train.py +17 -9
  7. rasa/cli/evaluate.py +7 -7
  8. rasa/cli/inspect.py +19 -7
  9. rasa/cli/interactive.py +1 -0
  10. rasa/cli/llm_fine_tuning.py +11 -14
  11. rasa/cli/project_templates/calm/config.yml +5 -7
  12. rasa/cli/project_templates/calm/endpoints.yml +15 -2
  13. rasa/cli/project_templates/tutorial/config.yml +8 -5
  14. rasa/cli/project_templates/tutorial/data/flows.yml +1 -1
  15. rasa/cli/project_templates/tutorial/data/patterns.yml +5 -0
  16. rasa/cli/project_templates/tutorial/domain.yml +14 -0
  17. rasa/cli/project_templates/tutorial/endpoints.yml +5 -0
  18. rasa/cli/run.py +7 -0
  19. rasa/cli/scaffold.py +4 -2
  20. rasa/cli/studio/upload.py +0 -15
  21. rasa/cli/train.py +14 -53
  22. rasa/cli/utils.py +14 -11
  23. rasa/cli/x.py +7 -7
  24. rasa/constants.py +3 -1
  25. rasa/core/actions/action.py +77 -33
  26. rasa/core/actions/action_hangup.py +29 -0
  27. rasa/core/actions/action_repeat_bot_messages.py +89 -0
  28. rasa/core/actions/e2e_stub_custom_action_executor.py +5 -1
  29. rasa/core/actions/http_custom_action_executor.py +4 -0
  30. rasa/core/agent.py +2 -2
  31. rasa/core/brokers/kafka.py +3 -1
  32. rasa/core/brokers/pika.py +3 -1
  33. rasa/core/channels/__init__.py +10 -6
  34. rasa/core/channels/channel.py +41 -4
  35. rasa/core/channels/development_inspector.py +150 -46
  36. rasa/core/channels/inspector/README.md +1 -1
  37. rasa/core/channels/inspector/dist/assets/{arc-b6e548fe.js → arc-bc141fb2.js} +1 -1
  38. rasa/core/channels/inspector/dist/assets/{c4Diagram-d0fbc5ce-fa03ac9e.js → c4Diagram-d0fbc5ce-be2db283.js} +1 -1
  39. rasa/core/channels/inspector/dist/assets/{classDiagram-936ed81e-ee67392a.js → classDiagram-936ed81e-55366915.js} +1 -1
  40. rasa/core/channels/inspector/dist/assets/{classDiagram-v2-c3cb15f1-9b283fae.js → classDiagram-v2-c3cb15f1-bb529518.js} +1 -1
  41. rasa/core/channels/inspector/dist/assets/{createText-62fc7601-8b6fcc2a.js → createText-62fc7601-b0ec81d6.js} +1 -1
  42. rasa/core/channels/inspector/dist/assets/{edges-f2ad444c-22e77f4f.js → edges-f2ad444c-6166330c.js} +1 -1
  43. rasa/core/channels/inspector/dist/assets/{erDiagram-9d236eb7-60ffc87f.js → erDiagram-9d236eb7-5ccc6a8e.js} +1 -1
  44. rasa/core/channels/inspector/dist/assets/{flowDb-1972c806-9dd802e4.js → flowDb-1972c806-fca3bfe4.js} +1 -1
  45. rasa/core/channels/inspector/dist/assets/{flowDiagram-7ea5b25a-5fa1912f.js → flowDiagram-7ea5b25a-4739080f.js} +1 -1
  46. rasa/core/channels/inspector/dist/assets/flowDiagram-v2-855bc5b3-736177bf.js +1 -0
  47. rasa/core/channels/inspector/dist/assets/{flowchart-elk-definition-abe16c3d-622a1fd2.js → flowchart-elk-definition-abe16c3d-7c1b0e0f.js} +1 -1
  48. rasa/core/channels/inspector/dist/assets/{ganttDiagram-9b5ea136-e285a63a.js → ganttDiagram-9b5ea136-772fd050.js} +1 -1
  49. rasa/core/channels/inspector/dist/assets/{gitGraphDiagram-99d0ae7c-f237bdca.js → gitGraphDiagram-99d0ae7c-8eae1dc9.js} +1 -1
  50. rasa/core/channels/inspector/dist/assets/{index-2c4b9a3b-4b03d70e.js → index-2c4b9a3b-f55afcdf.js} +1 -1
  51. rasa/core/channels/inspector/dist/assets/index-e7cef9de.js +1317 -0
  52. rasa/core/channels/inspector/dist/assets/{infoDiagram-736b4530-72a0fa5f.js → infoDiagram-736b4530-124d4a14.js} +1 -1
  53. rasa/core/channels/inspector/dist/assets/{journeyDiagram-df861f2b-82218c41.js → journeyDiagram-df861f2b-7c4fae44.js} +1 -1
  54. rasa/core/channels/inspector/dist/assets/{layout-78cff630.js → layout-b9885fb6.js} +1 -1
  55. rasa/core/channels/inspector/dist/assets/{line-5038b469.js → line-7c59abb6.js} +1 -1
  56. rasa/core/channels/inspector/dist/assets/{linear-c4fc4098.js → linear-4776f780.js} +1 -1
  57. rasa/core/channels/inspector/dist/assets/{mindmap-definition-beec6740-c33c8ea6.js → mindmap-definition-beec6740-2332c46c.js} +1 -1
  58. rasa/core/channels/inspector/dist/assets/{pieDiagram-dbbf0591-a8d03059.js → pieDiagram-dbbf0591-8fb39303.js} +1 -1
  59. rasa/core/channels/inspector/dist/assets/{quadrantDiagram-4d7f4fd6-6a0e56b2.js → quadrantDiagram-4d7f4fd6-3c7180a2.js} +1 -1
  60. rasa/core/channels/inspector/dist/assets/{requirementDiagram-6fc4c22a-2dc7c7bd.js → requirementDiagram-6fc4c22a-e910bcb8.js} +1 -1
  61. rasa/core/channels/inspector/dist/assets/{sankeyDiagram-8f13d901-2360fe39.js → sankeyDiagram-8f13d901-ead16c89.js} +1 -1
  62. rasa/core/channels/inspector/dist/assets/{sequenceDiagram-b655622a-41b9f9ad.js → sequenceDiagram-b655622a-29a02a19.js} +1 -1
  63. rasa/core/channels/inspector/dist/assets/{stateDiagram-59f0c015-0aad326f.js → stateDiagram-59f0c015-042b3137.js} +1 -1
  64. rasa/core/channels/inspector/dist/assets/{stateDiagram-v2-2b26beab-9847d984.js → stateDiagram-v2-2b26beab-2178c0f3.js} +1 -1
  65. rasa/core/channels/inspector/dist/assets/{styles-080da4f6-564d890e.js → styles-080da4f6-23ffa4fc.js} +1 -1
  66. rasa/core/channels/inspector/dist/assets/{styles-3dcbcfbf-38957613.js → styles-3dcbcfbf-94f59763.js} +1 -1
  67. rasa/core/channels/inspector/dist/assets/{styles-9c745c82-f0fc6921.js → styles-9c745c82-78a6bebc.js} +1 -1
  68. rasa/core/channels/inspector/dist/assets/{svgDrawCommon-4835440b-ef3c5a77.js → svgDrawCommon-4835440b-eae2a6f6.js} +1 -1
  69. rasa/core/channels/inspector/dist/assets/{timeline-definition-5b62e21b-bf3e91c1.js → timeline-definition-5b62e21b-5c968d92.js} +1 -1
  70. rasa/core/channels/inspector/dist/assets/{xychartDiagram-2b33534f-4d4026c0.js → xychartDiagram-2b33534f-fd3db0d5.js} +1 -1
  71. rasa/core/channels/inspector/dist/index.html +18 -17
  72. rasa/core/channels/inspector/index.html +17 -16
  73. rasa/core/channels/inspector/package.json +5 -1
  74. rasa/core/channels/inspector/src/App.tsx +118 -68
  75. rasa/core/channels/inspector/src/components/Chat.tsx +95 -0
  76. rasa/core/channels/inspector/src/components/DiagramFlow.tsx +11 -10
  77. rasa/core/channels/inspector/src/components/DialogueStack.tsx +10 -25
  78. rasa/core/channels/inspector/src/components/LoadingSpinner.tsx +6 -3
  79. rasa/core/channels/inspector/src/helpers/audiostream.ts +165 -0
  80. rasa/core/channels/inspector/src/helpers/formatters.test.ts +10 -0
  81. rasa/core/channels/inspector/src/helpers/formatters.ts +107 -41
  82. rasa/core/channels/inspector/src/helpers/utils.ts +92 -7
  83. rasa/core/channels/inspector/src/types.ts +21 -1
  84. rasa/core/channels/inspector/yarn.lock +94 -1
  85. rasa/core/channels/rest.py +51 -46
  86. rasa/core/channels/socketio.py +28 -1
  87. rasa/core/channels/telegram.py +1 -1
  88. rasa/core/channels/twilio.py +1 -1
  89. rasa/core/channels/{audiocodes.py → voice_ready/audiocodes.py} +122 -69
  90. rasa/core/channels/{voice_aware → voice_ready}/jambonz.py +26 -8
  91. rasa/core/channels/{voice_aware → voice_ready}/jambonz_protocol.py +57 -5
  92. rasa/core/channels/{twilio_voice.py → voice_ready/twilio_voice.py} +64 -28
  93. rasa/core/channels/voice_ready/utils.py +37 -0
  94. rasa/core/channels/voice_stream/asr/__init__.py +0 -0
  95. rasa/core/channels/voice_stream/asr/asr_engine.py +89 -0
  96. rasa/core/channels/voice_stream/asr/asr_event.py +18 -0
  97. rasa/core/channels/voice_stream/asr/azure.py +129 -0
  98. rasa/core/channels/voice_stream/asr/deepgram.py +90 -0
  99. rasa/core/channels/voice_stream/audio_bytes.py +8 -0
  100. rasa/core/channels/voice_stream/browser_audio.py +107 -0
  101. rasa/core/channels/voice_stream/call_state.py +23 -0
  102. rasa/core/channels/voice_stream/tts/__init__.py +0 -0
  103. rasa/core/channels/voice_stream/tts/azure.py +106 -0
  104. rasa/core/channels/voice_stream/tts/cartesia.py +118 -0
  105. rasa/core/channels/voice_stream/tts/tts_cache.py +27 -0
  106. rasa/core/channels/voice_stream/tts/tts_engine.py +58 -0
  107. rasa/core/channels/voice_stream/twilio_media_streams.py +173 -0
  108. rasa/core/channels/voice_stream/util.py +57 -0
  109. rasa/core/channels/voice_stream/voice_channel.py +427 -0
  110. rasa/core/information_retrieval/qdrant.py +1 -0
  111. rasa/core/nlg/contextual_response_rephraser.py +45 -17
  112. rasa/{nlu → core}/persistor.py +203 -68
  113. rasa/core/policies/enterprise_search_policy.py +119 -63
  114. rasa/core/policies/flows/flow_executor.py +15 -22
  115. rasa/core/policies/intentless_policy.py +83 -28
  116. rasa/core/processor.py +25 -0
  117. rasa/core/run.py +12 -2
  118. rasa/core/secrets_manager/constants.py +4 -0
  119. rasa/core/secrets_manager/factory.py +8 -0
  120. rasa/core/secrets_manager/vault.py +11 -1
  121. rasa/core/training/interactive.py +33 -34
  122. rasa/core/utils.py +47 -21
  123. rasa/dialogue_understanding/coexistence/llm_based_router.py +41 -14
  124. rasa/dialogue_understanding/commands/__init__.py +6 -0
  125. rasa/dialogue_understanding/commands/repeat_bot_messages_command.py +60 -0
  126. rasa/dialogue_understanding/commands/session_end_command.py +61 -0
  127. rasa/dialogue_understanding/commands/user_silence_command.py +59 -0
  128. rasa/dialogue_understanding/commands/utils.py +5 -0
  129. rasa/dialogue_understanding/generator/constants.py +2 -0
  130. rasa/dialogue_understanding/generator/flow_retrieval.py +47 -9
  131. rasa/dialogue_understanding/generator/llm_based_command_generator.py +38 -15
  132. rasa/dialogue_understanding/generator/llm_command_generator.py +1 -1
  133. rasa/dialogue_understanding/generator/multi_step/multi_step_llm_command_generator.py +35 -13
  134. rasa/dialogue_understanding/generator/single_step/command_prompt_template.jinja2 +3 -0
  135. rasa/dialogue_understanding/generator/single_step/single_step_llm_command_generator.py +60 -13
  136. rasa/dialogue_understanding/patterns/default_flows_for_patterns.yml +53 -0
  137. rasa/dialogue_understanding/patterns/repeat.py +37 -0
  138. rasa/dialogue_understanding/patterns/user_silence.py +37 -0
  139. rasa/dialogue_understanding/processor/command_processor.py +21 -1
  140. rasa/e2e_test/aggregate_test_stats_calculator.py +1 -11
  141. rasa/e2e_test/assertions.py +136 -61
  142. rasa/e2e_test/assertions_schema.yml +23 -0
  143. rasa/e2e_test/e2e_test_case.py +85 -6
  144. rasa/e2e_test/e2e_test_runner.py +2 -3
  145. rasa/e2e_test/utils/e2e_yaml_utils.py +1 -1
  146. rasa/engine/graph.py +3 -10
  147. rasa/engine/loader.py +12 -0
  148. rasa/engine/recipes/config_files/default_config.yml +0 -3
  149. rasa/engine/recipes/default_recipe.py +0 -1
  150. rasa/engine/recipes/graph_recipe.py +0 -1
  151. rasa/engine/runner/dask.py +2 -2
  152. rasa/engine/storage/local_model_storage.py +12 -42
  153. rasa/engine/storage/storage.py +1 -5
  154. rasa/engine/validation.py +527 -74
  155. rasa/model_manager/__init__.py +0 -0
  156. rasa/model_manager/config.py +40 -0
  157. rasa/model_manager/model_api.py +559 -0
  158. rasa/model_manager/runner_service.py +286 -0
  159. rasa/model_manager/socket_bridge.py +146 -0
  160. rasa/model_manager/studio_jwt_auth.py +86 -0
  161. rasa/model_manager/trainer_service.py +325 -0
  162. rasa/model_manager/utils.py +87 -0
  163. rasa/model_manager/warm_rasa_process.py +187 -0
  164. rasa/model_service.py +112 -0
  165. rasa/model_training.py +42 -23
  166. rasa/nlu/tokenizers/whitespace_tokenizer.py +3 -14
  167. rasa/server.py +4 -2
  168. rasa/shared/constants.py +60 -8
  169. rasa/shared/core/constants.py +13 -0
  170. rasa/shared/core/domain.py +107 -50
  171. rasa/shared/core/events.py +29 -0
  172. rasa/shared/core/flows/flow.py +5 -0
  173. rasa/shared/core/flows/flows_list.py +19 -6
  174. rasa/shared/core/flows/flows_yaml_schema.json +10 -0
  175. rasa/shared/core/flows/utils.py +39 -0
  176. rasa/shared/core/flows/validation.py +121 -0
  177. rasa/shared/core/flows/yaml_flows_io.py +15 -27
  178. rasa/shared/core/slots.py +5 -0
  179. rasa/shared/importers/importer.py +59 -41
  180. rasa/shared/importers/multi_project.py +23 -11
  181. rasa/shared/importers/rasa.py +12 -3
  182. rasa/shared/importers/remote_importer.py +196 -0
  183. rasa/shared/importers/utils.py +3 -1
  184. rasa/shared/nlu/training_data/formats/rasa_yaml.py +18 -3
  185. rasa/shared/nlu/training_data/training_data.py +18 -19
  186. rasa/shared/providers/_configs/litellm_router_client_config.py +220 -0
  187. rasa/shared/providers/_configs/model_group_config.py +167 -0
  188. rasa/shared/providers/_configs/openai_client_config.py +1 -1
  189. rasa/shared/providers/_configs/rasa_llm_client_config.py +73 -0
  190. rasa/shared/providers/_configs/self_hosted_llm_client_config.py +1 -0
  191. rasa/shared/providers/_configs/utils.py +16 -0
  192. rasa/shared/providers/_utils.py +79 -0
  193. rasa/shared/providers/embedding/_base_litellm_embedding_client.py +13 -29
  194. rasa/shared/providers/embedding/azure_openai_embedding_client.py +54 -21
  195. rasa/shared/providers/embedding/default_litellm_embedding_client.py +24 -0
  196. rasa/shared/providers/embedding/litellm_router_embedding_client.py +135 -0
  197. rasa/shared/providers/llm/_base_litellm_client.py +34 -22
  198. rasa/shared/providers/llm/azure_openai_llm_client.py +50 -29
  199. rasa/shared/providers/llm/default_litellm_llm_client.py +24 -0
  200. rasa/shared/providers/llm/litellm_router_llm_client.py +182 -0
  201. rasa/shared/providers/llm/rasa_llm_client.py +112 -0
  202. rasa/shared/providers/llm/self_hosted_llm_client.py +5 -29
  203. rasa/shared/providers/mappings.py +19 -0
  204. rasa/shared/providers/router/__init__.py +0 -0
  205. rasa/shared/providers/router/_base_litellm_router_client.py +183 -0
  206. rasa/shared/providers/router/router_client.py +73 -0
  207. rasa/shared/utils/common.py +40 -24
  208. rasa/shared/utils/health_check/__init__.py +0 -0
  209. rasa/shared/utils/health_check/embeddings_health_check_mixin.py +31 -0
  210. rasa/shared/utils/health_check/health_check.py +258 -0
  211. rasa/shared/utils/health_check/llm_health_check_mixin.py +31 -0
  212. rasa/shared/utils/io.py +27 -6
  213. rasa/shared/utils/llm.py +354 -44
  214. rasa/shared/utils/schemas/events.py +2 -0
  215. rasa/shared/utils/schemas/model_config.yml +0 -10
  216. rasa/shared/utils/yaml.py +181 -38
  217. rasa/studio/data_handler.py +3 -1
  218. rasa/studio/upload.py +160 -74
  219. rasa/telemetry.py +94 -17
  220. rasa/tracing/config.py +3 -1
  221. rasa/tracing/instrumentation/attribute_extractors.py +95 -18
  222. rasa/tracing/instrumentation/instrumentation.py +121 -0
  223. rasa/utils/common.py +5 -0
  224. rasa/utils/endpoints.py +27 -1
  225. rasa/utils/io.py +8 -16
  226. rasa/utils/log_utils.py +9 -2
  227. rasa/utils/sanic_error_handler.py +32 -0
  228. rasa/validator.py +110 -16
  229. rasa/version.py +1 -1
  230. {rasa_pro-3.10.16.dist-info → rasa_pro-3.11.0.dist-info}/METADATA +16 -14
  231. {rasa_pro-3.10.16.dist-info → rasa_pro-3.11.0.dist-info}/RECORD +236 -185
  232. rasa/core/channels/inspector/dist/assets/flowDiagram-v2-855bc5b3-1844e5a5.js +0 -1
  233. rasa/core/channels/inspector/dist/assets/index-a5d3e69d.js +0 -1040
  234. rasa/core/channels/voice_aware/utils.py +0 -20
  235. rasa/llm_fine_tuning/notebooks/unsloth_finetuning.ipynb +0 -407
  236. /rasa/core/channels/{voice_aware → voice_ready}/__init__.py +0 -0
  237. /rasa/core/channels/{voice_native → voice_stream}/__init__.py +0 -0
  238. {rasa_pro-3.10.16.dist-info → rasa_pro-3.11.0.dist-info}/NOTICE +0 -0
  239. {rasa_pro-3.10.16.dist-info → rasa_pro-3.11.0.dist-info}/WHEEL +0 -0
  240. {rasa_pro-3.10.16.dist-info → rasa_pro-3.11.0.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,258 @@
1
+ import os
2
+ import sys
3
+ from typing import Optional, Dict, Any
4
+
5
+ from rasa.shared.constants import (
6
+ LLM_API_HEALTH_CHECK_ENV_VAR,
7
+ MODELS_CONFIG_KEY,
8
+ LLM_API_HEALTH_CHECK_DEFAULT_VALUE,
9
+ )
10
+ from rasa.shared.exceptions import ProviderClientValidationError
11
+ from rasa.shared.providers.embedding.embedding_client import EmbeddingClient
12
+ from rasa.shared.providers.llm.llm_client import LLMClient
13
+ from rasa.shared.utils.llm import llm_factory, structlogger, embedder_factory
14
+
15
+
16
+ def try_instantiate_llm_client(
17
+ custom_llm_config: Optional[Dict],
18
+ default_llm_config: Optional[Dict],
19
+ log_source_function: str,
20
+ log_source_component: str,
21
+ ) -> LLMClient:
22
+ """Validate llm configuration."""
23
+ try:
24
+ return llm_factory(custom_llm_config, default_llm_config)
25
+ except (ProviderClientValidationError, ValueError) as e:
26
+ structlogger.error(
27
+ f"{log_source_function}.llm_instantiation_failed",
28
+ event_info=(
29
+ f"Unable to create the LLM client for component - "
30
+ f"{log_source_component}. "
31
+ f"Please make sure you specified the required environment variables "
32
+ f"and configuration keys. "
33
+ ),
34
+ error=e,
35
+ )
36
+ sys.exit(1)
37
+
38
+
39
+ def try_instantiate_embedder(
40
+ custom_embeddings_config: Optional[Dict],
41
+ default_embeddings_config: Optional[Dict],
42
+ log_source_function: str,
43
+ log_source_component: str,
44
+ ) -> EmbeddingClient:
45
+ """Validate embeddings configuration."""
46
+ try:
47
+ return embedder_factory(custom_embeddings_config, default_embeddings_config)
48
+ except (ProviderClientValidationError, ValueError) as e:
49
+ structlogger.error(
50
+ f"{log_source_function}.embedder_instantiation_failed",
51
+ event_info=(
52
+ f"Unable to create the Embedding client for component - "
53
+ f"{log_source_component}. Please make sure you specified the required "
54
+ f"environment variables and configuration keys."
55
+ ),
56
+ error=e,
57
+ )
58
+ sys.exit(1)
59
+
60
+
61
+ def perform_llm_health_check(
62
+ custom_config: Optional[Dict[str, Any]],
63
+ default_config: Dict[str, Any],
64
+ log_source_function: str,
65
+ log_source_component: str,
66
+ ) -> None:
67
+ """Try to instantiate the LLM Client to validate the provided config.
68
+ If the LLM_API_HEALTH_CHECK environment variable is true, perform a test call
69
+ to the LLM API. If config contains multiple models, perform a test call for each
70
+ model in the model group.
71
+
72
+ This method supports both single model configurations and model group configurations
73
+ (configs that have the `models` key).
74
+ """
75
+ # Instantiate the LLM client or Router LLM client to validate the provided config.
76
+ llm_client = try_instantiate_llm_client(
77
+ custom_config, default_config, log_source_function, log_source_component
78
+ )
79
+
80
+ if is_api_health_check_enabled():
81
+ if (
82
+ custom_config
83
+ and MODELS_CONFIG_KEY in custom_config
84
+ and len(custom_config[MODELS_CONFIG_KEY]) > 1
85
+ ):
86
+ # If the config uses a router, instantiate the LLM client for each model
87
+ # in the model group. This is required to perform a test api call for each
88
+ # model in the group.
89
+ # Note: The Router LLM client is not used here as we need to perform a test
90
+ # api call and not load balance the requests.
91
+ for model_config in custom_config[MODELS_CONFIG_KEY]:
92
+ llm_client = try_instantiate_llm_client(
93
+ model_config,
94
+ default_config,
95
+ log_source_function,
96
+ log_source_component,
97
+ )
98
+ send_test_llm_api_request(
99
+ llm_client, log_source_function, log_source_component
100
+ )
101
+ else:
102
+ # Make a test api call to perform a health check for the LLM client.
103
+ # LLM config from config file and model group config from endpoint config
104
+ # without router are handled here.
105
+ send_test_llm_api_request(
106
+ llm_client,
107
+ log_source_function,
108
+ log_source_component,
109
+ )
110
+ else:
111
+ structlogger.warning(
112
+ f"{log_source_function}.perform_llm_health_check.disabled",
113
+ event_info=(
114
+ f"The {LLM_API_HEALTH_CHECK_ENV_VAR} environment variable is set "
115
+ f"to false, which will disable LLM health check. "
116
+ f"It is recommended to set this variable to true in production "
117
+ f"environments."
118
+ ),
119
+ )
120
+ return None
121
+
122
+
123
+ def perform_embeddings_health_check(
124
+ custom_config: Optional[Dict[str, Any]],
125
+ default_config: Dict[str, Any],
126
+ log_source_function: str,
127
+ log_source_component: str,
128
+ ) -> None:
129
+ """Try to instantiate the Embedder to validate the provided config.
130
+ If the LLM_API_HEALTH_CHECK environment variable is true, perform a test call
131
+ to the Embeddings API. If config contains multiple models, perform a test call for
132
+ each model in the model group.
133
+
134
+ This method supports both single model configurations and model group configurations
135
+ (configs that have the `models` key).
136
+ """
137
+ # Instantiate the Embedder client or the Embedder Router client to validate the
138
+ # provided config. Deprecation warnings and errors are logged here.
139
+ embedder = try_instantiate_embedder(
140
+ custom_config, default_config, log_source_function, log_source_component
141
+ )
142
+
143
+ if is_api_health_check_enabled():
144
+ if (
145
+ custom_config
146
+ and MODELS_CONFIG_KEY in custom_config
147
+ and len(custom_config[MODELS_CONFIG_KEY]) > 1
148
+ ):
149
+ # If the config uses a router, instantiate the Embedder client for each
150
+ # model in the model group. This is required to perform a test api call
151
+ # for every model in the group.
152
+ # Note: The Router Embedding client is not used here as we need to perform
153
+ # a test API call and not load balance the requests.
154
+ for model_config in custom_config[MODELS_CONFIG_KEY]:
155
+ embedder = try_instantiate_embedder(
156
+ model_config,
157
+ default_config,
158
+ log_source_function,
159
+ log_source_component,
160
+ )
161
+ send_test_embeddings_api_request(
162
+ embedder, log_source_function, log_source_component
163
+ )
164
+ else:
165
+ # Make a test api call to perform a health check for the Embedding client.
166
+ # Embeddings config from config file and model group config from endpoint
167
+ # config without router are handled here.
168
+ send_test_embeddings_api_request(
169
+ embedder, log_source_function, log_source_component
170
+ )
171
+ else:
172
+ structlogger.warning(
173
+ f"{log_source_function}" f".perform_embeddings_health_check.disabled",
174
+ event_info=(
175
+ f"The {LLM_API_HEALTH_CHECK_ENV_VAR} environment variable is set "
176
+ f"to false, which will disable embeddings API health check. "
177
+ f"It is recommended to set this variable to true in production "
178
+ f"environments."
179
+ ),
180
+ )
181
+ return None
182
+
183
+
184
+ def send_test_llm_api_request(
185
+ llm_client: LLMClient, log_source_function: str, log_source_component: str
186
+ ) -> None:
187
+ """Sends a test request to the LLM API to perform a health check.
188
+
189
+ Raises:
190
+ Exception: If the API call fails.
191
+ """
192
+ structlogger.info(
193
+ f"{log_source_function}.send_test_llm_api_request",
194
+ event_info=(
195
+ f"Sending a test LLM API request for the component - "
196
+ f"{log_source_component}."
197
+ ),
198
+ config=llm_client.config,
199
+ )
200
+ try:
201
+ llm_client.completion("hello")
202
+ except Exception as e:
203
+ structlogger.error(
204
+ f"{log_source_function}.send_test_llm_api_request_failed",
205
+ event_info=(
206
+ f"Test call to the LLM API failed for component - "
207
+ f"{log_source_component}.",
208
+ ),
209
+ config=llm_client.config,
210
+ error=e,
211
+ )
212
+ sys.exit(1)
213
+
214
+
215
+ def send_test_embeddings_api_request(
216
+ embedder: EmbeddingClient, log_source_function: str, log_source_component: str
217
+ ) -> None:
218
+ """Sends a test request to the Embeddings API to perform a health check.
219
+
220
+ Raises:
221
+ Exception: If the API call fails.
222
+ """
223
+ structlogger.info(
224
+ f"{log_source_function}.send_test_embeddings_api_request",
225
+ event_info=(
226
+ f"Sending a test Embeddings API request for the component - "
227
+ f"{log_source_component}."
228
+ ),
229
+ config=embedder.config,
230
+ )
231
+ try:
232
+ embedder.embed(["hello"])
233
+ except Exception as e:
234
+ structlogger.error(
235
+ f"{log_source_function}.send_test_llm_api_request_failed",
236
+ event_info=(
237
+ f"Test call to the Embeddings API failed for component - "
238
+ f"{log_source_component}."
239
+ ),
240
+ config=embedder.config,
241
+ error=e,
242
+ )
243
+ sys.exit(1)
244
+
245
+
246
+ def is_api_health_check_enabled() -> bool:
247
+ """Determines whether the API health check is enabled based on an environment
248
+ variable.
249
+
250
+ Returns:
251
+ bool: True if the API health check is enabled, False otherwise.
252
+ """
253
+ return (
254
+ os.getenv(
255
+ LLM_API_HEALTH_CHECK_ENV_VAR, LLM_API_HEALTH_CHECK_DEFAULT_VALUE
256
+ ).lower()
257
+ == "true"
258
+ )
@@ -0,0 +1,31 @@
1
+ from typing import Optional, Dict, Any
2
+
3
+
4
+ class LLMHealthCheckMixin:
5
+ """Mixin class that provides methods for performing llm 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_llm_health_check`
10
+ """
11
+
12
+ @staticmethod
13
+ def perform_llm_health_check(
14
+ custom_llm_config: Optional[Dict[str, Any]],
15
+ default_llm_config: Dict[str, Any],
16
+ log_source_method: str,
17
+ log_source_component: str,
18
+ ) -> None:
19
+ """Wraps the `perform_llm_health_check` function to enable
20
+ tracing and instrumentation.
21
+ """
22
+ from rasa.shared.utils.health_check.health_check import (
23
+ perform_llm_health_check,
24
+ )
25
+
26
+ perform_llm_health_check(
27
+ custom_llm_config,
28
+ default_llm_config,
29
+ log_source_method,
30
+ log_source_component,
31
+ )
rasa/shared/utils/io.py CHANGED
@@ -1,18 +1,18 @@
1
- from collections import OrderedDict
2
- from functools import wraps
3
- from hashlib import md5
4
1
  import asyncio
5
2
  import errno
6
3
  import glob
7
4
  import json
8
5
  import logging
9
6
  import os
7
+ import random
8
+ import string
10
9
  import sys
10
+ import warnings
11
+ from collections import OrderedDict
12
+ from functools import wraps
13
+ from hashlib import md5
11
14
  from pathlib import Path
12
15
  from typing import Any, cast, Callable, Dict, List, Optional, Text, Type, TypeVar, Union
13
- import warnings
14
- import random
15
- import string
16
16
 
17
17
  import portalocker
18
18
 
@@ -476,3 +476,24 @@ def suppress_logs(log_level: int = logging.WARNING) -> Callable[[F], F]:
476
476
  return cast(F, sync_wrapper)
477
477
 
478
478
  return decorator
479
+
480
+
481
+ def resolve_environment_variables(
482
+ value: Union[str, List[Any], Dict[str, Any]],
483
+ ) -> Union[str, List[Any], Dict[str, Any]]:
484
+ """Resolve environment variables in a string, list, or dictionary.
485
+
486
+ Args:
487
+ value: The value to resolve environment variables in.
488
+
489
+ Returns:
490
+ The value with environment variables resolved.
491
+ """
492
+ if isinstance(value, str):
493
+ return os.path.expandvars(value)
494
+ elif isinstance(value, list):
495
+ return [resolve_environment_variables(item) for item in value]
496
+ elif isinstance(value, dict):
497
+ return {key: resolve_environment_variables(val) for key, val in value.items()}
498
+ else:
499
+ return value