rasa-pro 3.11.0rc1__py3-none-any.whl → 3.11.0rc3__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.
- rasa/cli/inspect.py +2 -0
- rasa/cli/studio/studio.py +18 -8
- rasa/core/actions/action_repeat_bot_messages.py +17 -0
- rasa/core/channels/channel.py +17 -0
- rasa/core/channels/development_inspector.py +4 -1
- rasa/core/channels/voice_ready/audiocodes.py +15 -4
- rasa/core/channels/voice_ready/jambonz.py +13 -2
- rasa/core/channels/voice_ready/twilio_voice.py +6 -21
- rasa/core/channels/voice_stream/asr/asr_event.py +1 -1
- rasa/core/channels/voice_stream/asr/azure.py +5 -7
- rasa/core/channels/voice_stream/asr/deepgram.py +13 -11
- rasa/core/channels/voice_stream/voice_channel.py +61 -19
- rasa/core/nlg/contextual_response_rephraser.py +20 -12
- rasa/core/policies/enterprise_search_policy.py +32 -72
- rasa/core/policies/intentless_policy.py +34 -72
- rasa/dialogue_understanding/coexistence/llm_based_router.py +18 -33
- rasa/dialogue_understanding/generator/constants.py +0 -2
- rasa/dialogue_understanding/generator/flow_retrieval.py +33 -50
- rasa/dialogue_understanding/generator/llm_based_command_generator.py +12 -40
- rasa/dialogue_understanding/generator/multi_step/multi_step_llm_command_generator.py +18 -20
- rasa/dialogue_understanding/generator/nlu_command_adapter.py +19 -1
- rasa/dialogue_understanding/generator/single_step/single_step_llm_command_generator.py +26 -22
- rasa/dialogue_understanding/patterns/default_flows_for_patterns.yml +9 -0
- rasa/dialogue_understanding/processor/command_processor.py +21 -1
- rasa/e2e_test/e2e_test_case.py +85 -6
- rasa/engine/validation.py +88 -60
- rasa/model_service.py +3 -0
- rasa/nlu/tokenizers/whitespace_tokenizer.py +3 -14
- rasa/server.py +3 -1
- rasa/shared/constants.py +5 -5
- rasa/shared/core/constants.py +1 -1
- rasa/shared/core/domain.py +0 -26
- rasa/shared/core/flows/flows_list.py +5 -1
- rasa/shared/providers/_configs/litellm_router_client_config.py +29 -9
- rasa/shared/providers/embedding/_base_litellm_embedding_client.py +6 -14
- rasa/shared/providers/embedding/litellm_router_embedding_client.py +1 -1
- rasa/shared/providers/llm/_base_litellm_client.py +32 -1
- rasa/shared/providers/llm/litellm_router_llm_client.py +56 -1
- rasa/shared/providers/llm/self_hosted_llm_client.py +4 -28
- rasa/shared/providers/router/_base_litellm_router_client.py +35 -1
- rasa/shared/utils/common.py +1 -1
- rasa/shared/utils/health_check/__init__.py +0 -0
- rasa/shared/utils/health_check/embeddings_health_check_mixin.py +31 -0
- rasa/shared/utils/health_check/health_check.py +256 -0
- rasa/shared/utils/health_check/llm_health_check_mixin.py +31 -0
- rasa/shared/utils/llm.py +5 -2
- rasa/shared/utils/yaml.py +102 -62
- rasa/studio/auth.py +3 -5
- rasa/studio/config.py +13 -4
- rasa/studio/constants.py +1 -0
- rasa/studio/data_handler.py +10 -3
- rasa/studio/upload.py +21 -10
- rasa/telemetry.py +15 -1
- rasa/tracing/config.py +3 -1
- rasa/tracing/instrumentation/attribute_extractors.py +20 -0
- rasa/tracing/instrumentation/instrumentation.py +121 -0
- rasa/utils/common.py +5 -0
- rasa/utils/io.py +8 -16
- rasa/utils/sanic_error_handler.py +32 -0
- rasa/version.py +1 -1
- {rasa_pro-3.11.0rc1.dist-info → rasa_pro-3.11.0rc3.dist-info}/METADATA +3 -2
- {rasa_pro-3.11.0rc1.dist-info → rasa_pro-3.11.0rc3.dist-info}/RECORD +65 -61
- rasa/shared/utils/health_check.py +0 -533
- {rasa_pro-3.11.0rc1.dist-info → rasa_pro-3.11.0rc3.dist-info}/NOTICE +0 -0
- {rasa_pro-3.11.0rc1.dist-info → rasa_pro-3.11.0rc3.dist-info}/WHEEL +0 -0
- {rasa_pro-3.11.0rc1.dist-info → rasa_pro-3.11.0rc3.dist-info}/entry_points.txt +0 -0
|
@@ -1,533 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
from typing import Optional, Dict, Any
|
|
3
|
-
|
|
4
|
-
from rasa.shared.constants import (
|
|
5
|
-
LLM_API_HEALTH_CHECK_ENV_VAR,
|
|
6
|
-
MODELS_CONFIG_KEY,
|
|
7
|
-
MODEL_GROUP_ID_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.cli import print_error_and_exit
|
|
14
|
-
from rasa.shared.utils.llm import llm_factory, structlogger, embedder_factory
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
def try_instantiate_llm_client(
|
|
18
|
-
custom_llm_config: Optional[Dict],
|
|
19
|
-
default_llm_config: Optional[Dict],
|
|
20
|
-
log_source_function: str,
|
|
21
|
-
log_source_component: str,
|
|
22
|
-
) -> LLMClient:
|
|
23
|
-
"""Validate llm configuration."""
|
|
24
|
-
try:
|
|
25
|
-
return llm_factory(custom_llm_config, default_llm_config)
|
|
26
|
-
except (ProviderClientValidationError, ValueError) as e:
|
|
27
|
-
structlogger.error(
|
|
28
|
-
f"{log_source_function}.llm_instantiation_failed",
|
|
29
|
-
message="Unable to instantiate LLM client.",
|
|
30
|
-
error=e,
|
|
31
|
-
)
|
|
32
|
-
print_error_and_exit(
|
|
33
|
-
f"Unable to create the LLM client for component - {log_source_component}. "
|
|
34
|
-
f"Please make sure you specified the required environment variables "
|
|
35
|
-
f"and configuration keys. "
|
|
36
|
-
f"Error: {e}"
|
|
37
|
-
)
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
def try_instantiate_embedder(
|
|
41
|
-
custom_embeddings_config: Optional[Dict],
|
|
42
|
-
default_embeddings_config: Optional[Dict],
|
|
43
|
-
log_source_function: str,
|
|
44
|
-
log_source_component: str,
|
|
45
|
-
) -> EmbeddingClient:
|
|
46
|
-
"""Validate embeddings configuration."""
|
|
47
|
-
try:
|
|
48
|
-
return embedder_factory(custom_embeddings_config, default_embeddings_config)
|
|
49
|
-
except (ProviderClientValidationError, ValueError) as e:
|
|
50
|
-
structlogger.error(
|
|
51
|
-
f"{log_source_function}.embedder_instantiation_failed",
|
|
52
|
-
message="Unable to instantiate Embedding client.",
|
|
53
|
-
error=e,
|
|
54
|
-
)
|
|
55
|
-
print_error_and_exit(
|
|
56
|
-
f"Unable to create the Embedding client for component - "
|
|
57
|
-
f"{log_source_component}. Please make sure you specified the required "
|
|
58
|
-
f"environment variables and configuration keys. Error: {e}"
|
|
59
|
-
)
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
def perform_training_time_llm_health_check(
|
|
63
|
-
custom_config: Optional[Dict[str, Any]],
|
|
64
|
-
default_config: Dict[str, Any],
|
|
65
|
-
log_source_function: str,
|
|
66
|
-
log_source_component: str,
|
|
67
|
-
) -> Optional[str]:
|
|
68
|
-
"""Try to instantiate the LLM Client to validate the provided config.
|
|
69
|
-
If the LLM_API_HEALTH_CHECK environment variable is true, perform a test call
|
|
70
|
-
to the LLM API. If config contains multiple models, perform a consistency
|
|
71
|
-
check for the model group.
|
|
72
|
-
|
|
73
|
-
This method supports both single model configurations and model group configurations
|
|
74
|
-
(configs that have the `models` key).
|
|
75
|
-
|
|
76
|
-
Returns:
|
|
77
|
-
model name from the API response or `None` if LLM_API_HEALTH_CHECK is false
|
|
78
|
-
"""
|
|
79
|
-
llm_client = try_instantiate_llm_client(
|
|
80
|
-
custom_config, default_config, log_source_function, log_source_component
|
|
81
|
-
)
|
|
82
|
-
|
|
83
|
-
if (
|
|
84
|
-
os.getenv(
|
|
85
|
-
LLM_API_HEALTH_CHECK_ENV_VAR, LLM_API_HEALTH_CHECK_DEFAULT_VALUE
|
|
86
|
-
).lower()
|
|
87
|
-
== "true"
|
|
88
|
-
):
|
|
89
|
-
train_model_name: Optional[str] = None
|
|
90
|
-
if (
|
|
91
|
-
custom_config
|
|
92
|
-
and MODELS_CONFIG_KEY in custom_config
|
|
93
|
-
and len(custom_config[MODELS_CONFIG_KEY]) > 1
|
|
94
|
-
):
|
|
95
|
-
train_model_name = perform_llm_model_group_consistency_check(
|
|
96
|
-
custom_config,
|
|
97
|
-
default_config,
|
|
98
|
-
log_source_function,
|
|
99
|
-
log_source_component,
|
|
100
|
-
)
|
|
101
|
-
else:
|
|
102
|
-
train_model_name = send_test_llm_api_request(
|
|
103
|
-
llm_client,
|
|
104
|
-
log_source_function,
|
|
105
|
-
log_source_component,
|
|
106
|
-
)
|
|
107
|
-
return train_model_name
|
|
108
|
-
else:
|
|
109
|
-
structlogger.warning(
|
|
110
|
-
f"{log_source_function}.perform_training_time_llm_health_check.disabled",
|
|
111
|
-
event_info=(
|
|
112
|
-
f"The {LLM_API_HEALTH_CHECK_ENV_VAR} environment variable is set "
|
|
113
|
-
f"to false, which will disable model consistency check. "
|
|
114
|
-
f"It is recommended to set this variable to true in production "
|
|
115
|
-
f"environments."
|
|
116
|
-
),
|
|
117
|
-
)
|
|
118
|
-
return None
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
def perform_training_time_embeddings_health_check(
|
|
122
|
-
custom_config: Optional[Dict[str, Any]],
|
|
123
|
-
default_config: Dict[str, Any],
|
|
124
|
-
log_source_function: str,
|
|
125
|
-
log_source_component: str,
|
|
126
|
-
) -> Optional[str]:
|
|
127
|
-
"""Try to instantiate the Embedder to validate the provided config.
|
|
128
|
-
If the LLM_API_HEALTH_CHECK environment variable is true, perform a test call
|
|
129
|
-
to the Embeddings API. If config contains multiple models, perform a consistency
|
|
130
|
-
check for the model group.
|
|
131
|
-
|
|
132
|
-
This method supports both single model configurations and model group configurations
|
|
133
|
-
(configs that have the `models` key).
|
|
134
|
-
|
|
135
|
-
Returns:
|
|
136
|
-
model name from the API response or `None` if LLM_API_HEALTH_CHECK is false
|
|
137
|
-
"""
|
|
138
|
-
if (
|
|
139
|
-
os.getenv(
|
|
140
|
-
LLM_API_HEALTH_CHECK_ENV_VAR, LLM_API_HEALTH_CHECK_DEFAULT_VALUE
|
|
141
|
-
).lower()
|
|
142
|
-
== "true"
|
|
143
|
-
):
|
|
144
|
-
train_model_name: Optional[str] = None
|
|
145
|
-
if (
|
|
146
|
-
custom_config
|
|
147
|
-
and MODELS_CONFIG_KEY in custom_config
|
|
148
|
-
and len(custom_config[MODELS_CONFIG_KEY]) > 1
|
|
149
|
-
):
|
|
150
|
-
train_model_name = perform_embeddings_model_group_consistency_check(
|
|
151
|
-
custom_config,
|
|
152
|
-
default_config,
|
|
153
|
-
log_source_function,
|
|
154
|
-
log_source_component,
|
|
155
|
-
)
|
|
156
|
-
else:
|
|
157
|
-
embedder = try_instantiate_embedder(
|
|
158
|
-
custom_config, default_config, log_source_function, log_source_component
|
|
159
|
-
)
|
|
160
|
-
train_model_name = send_test_embeddings_api_request(
|
|
161
|
-
embedder, log_source_function, log_source_component
|
|
162
|
-
)
|
|
163
|
-
return train_model_name
|
|
164
|
-
else:
|
|
165
|
-
structlogger.warning(
|
|
166
|
-
f"{log_source_function}"
|
|
167
|
-
f".perform_training_time_embeddings_health_check.disabled",
|
|
168
|
-
event_info=(
|
|
169
|
-
f"The {LLM_API_HEALTH_CHECK_ENV_VAR} environment variable is set "
|
|
170
|
-
f"to false, which will disable model consistency check. "
|
|
171
|
-
f"It is recommended to set this variable to true in production "
|
|
172
|
-
f"environments."
|
|
173
|
-
),
|
|
174
|
-
)
|
|
175
|
-
return None
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
def perform_inference_time_llm_health_check(
|
|
179
|
-
custom_config: Optional[Dict[str, Any]],
|
|
180
|
-
default_config: Dict[str, Any],
|
|
181
|
-
train_model_name: Optional[str],
|
|
182
|
-
log_source_function: str,
|
|
183
|
-
log_source_component: str,
|
|
184
|
-
) -> None:
|
|
185
|
-
"""If the LLM_API_HEALTH_CHECK environment variable is true, perform a test call
|
|
186
|
-
to the LLM API. If config contains multiple models, perform a consistency
|
|
187
|
-
check for the model group.
|
|
188
|
-
Compare the model name from the API response with the model name used for training
|
|
189
|
-
(if available) and raise an exception if they are different.
|
|
190
|
-
|
|
191
|
-
This method supports both single model configurations and model group configurations
|
|
192
|
-
(configs that have the `models` key).
|
|
193
|
-
"""
|
|
194
|
-
if (
|
|
195
|
-
os.getenv(
|
|
196
|
-
LLM_API_HEALTH_CHECK_ENV_VAR, LLM_API_HEALTH_CHECK_DEFAULT_VALUE
|
|
197
|
-
).lower()
|
|
198
|
-
== "true"
|
|
199
|
-
):
|
|
200
|
-
structlogger.info(
|
|
201
|
-
f"{log_source_function}.perform_inference_time_llm_health_check",
|
|
202
|
-
event_info=(
|
|
203
|
-
f"Performing an inference-time health check on the LLM API for "
|
|
204
|
-
f"the component - {log_source_component}."
|
|
205
|
-
),
|
|
206
|
-
config=custom_config,
|
|
207
|
-
)
|
|
208
|
-
|
|
209
|
-
inference_model_name: Optional[str] = None
|
|
210
|
-
if (
|
|
211
|
-
custom_config
|
|
212
|
-
and MODELS_CONFIG_KEY in custom_config
|
|
213
|
-
and len(custom_config[MODELS_CONFIG_KEY]) > 1
|
|
214
|
-
):
|
|
215
|
-
inference_model_name = perform_llm_model_group_consistency_check(
|
|
216
|
-
custom_config,
|
|
217
|
-
default_config,
|
|
218
|
-
log_source_function,
|
|
219
|
-
log_source_component,
|
|
220
|
-
)
|
|
221
|
-
else:
|
|
222
|
-
llm_client = try_instantiate_llm_client(
|
|
223
|
-
custom_config,
|
|
224
|
-
default_config,
|
|
225
|
-
log_source_function,
|
|
226
|
-
log_source_component,
|
|
227
|
-
)
|
|
228
|
-
inference_model_name = send_test_llm_api_request(
|
|
229
|
-
llm_client,
|
|
230
|
-
log_source_function,
|
|
231
|
-
log_source_component,
|
|
232
|
-
)
|
|
233
|
-
|
|
234
|
-
if not inference_model_name:
|
|
235
|
-
structlogger.warning(
|
|
236
|
-
f"{log_source_function}"
|
|
237
|
-
f".perform_inference_time_llm_health_check.no_inference_model",
|
|
238
|
-
event_info=(
|
|
239
|
-
"Failed to perform model consistency check: "
|
|
240
|
-
"the API response does not contain a model name."
|
|
241
|
-
),
|
|
242
|
-
)
|
|
243
|
-
elif not train_model_name:
|
|
244
|
-
structlogger.warning(
|
|
245
|
-
f"{log_source_function}"
|
|
246
|
-
f".perform_inference_time_llm_health_check.no_train_model",
|
|
247
|
-
event_info=(
|
|
248
|
-
f"The model was trained with {LLM_API_HEALTH_CHECK_ENV_VAR} "
|
|
249
|
-
f"environment variable set to false, so the model "
|
|
250
|
-
f"consistency check is not available."
|
|
251
|
-
),
|
|
252
|
-
)
|
|
253
|
-
elif inference_model_name != train_model_name:
|
|
254
|
-
error_message = (
|
|
255
|
-
f"The LLM used to train the {log_source_component} "
|
|
256
|
-
f"({train_model_name}) is not the same as the LLM used for inference "
|
|
257
|
-
f"({inference_model_name}). Please verify your configuration."
|
|
258
|
-
)
|
|
259
|
-
structlogger.error(
|
|
260
|
-
f"{log_source_function}.train_inference_llm_model_mismatch",
|
|
261
|
-
event_info=error_message,
|
|
262
|
-
)
|
|
263
|
-
print_error_and_exit(error_message)
|
|
264
|
-
else:
|
|
265
|
-
structlogger.warning(
|
|
266
|
-
f"{log_source_function}.perform_inference_time_llm_health_check.disabled",
|
|
267
|
-
event_info=(
|
|
268
|
-
f"The {LLM_API_HEALTH_CHECK_ENV_VAR} environment variable is set "
|
|
269
|
-
f"to false, which will disable model consistency check. "
|
|
270
|
-
f"It is recommended to set this variable to true in production "
|
|
271
|
-
f"environments."
|
|
272
|
-
),
|
|
273
|
-
)
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
def perform_inference_time_embeddings_health_check(
|
|
277
|
-
custom_config: Optional[Dict[str, Any]],
|
|
278
|
-
default_config: Dict[str, Any],
|
|
279
|
-
train_model_name: Optional[str],
|
|
280
|
-
log_source_function: str,
|
|
281
|
-
log_source_component: str,
|
|
282
|
-
) -> None:
|
|
283
|
-
"""If the LLM_API_HEALTH_CHECK environment variable is true, perform a test call
|
|
284
|
-
to the Embeddings API. If config contains multiple models, perform a consistency
|
|
285
|
-
check for the model group.
|
|
286
|
-
Compare the model name from the API response with the model name used for training
|
|
287
|
-
(if available) and raise an exception if they are different.
|
|
288
|
-
|
|
289
|
-
This method supports both single model configurations and model group configurations
|
|
290
|
-
(configs that have the `models` key).
|
|
291
|
-
"""
|
|
292
|
-
if (
|
|
293
|
-
os.getenv(
|
|
294
|
-
LLM_API_HEALTH_CHECK_ENV_VAR, LLM_API_HEALTH_CHECK_DEFAULT_VALUE
|
|
295
|
-
).lower()
|
|
296
|
-
== "true"
|
|
297
|
-
):
|
|
298
|
-
structlogger.info(
|
|
299
|
-
f"{log_source_function}.perform_inference_time_embeddings_health_check",
|
|
300
|
-
event_info=(
|
|
301
|
-
f"Performing an inference-time health check on the Embeddings API for "
|
|
302
|
-
f"the component - {log_source_component}."
|
|
303
|
-
),
|
|
304
|
-
config=custom_config,
|
|
305
|
-
)
|
|
306
|
-
|
|
307
|
-
inference_model_name: Optional[str] = None
|
|
308
|
-
if (
|
|
309
|
-
custom_config
|
|
310
|
-
and MODELS_CONFIG_KEY in custom_config
|
|
311
|
-
and len(custom_config[MODELS_CONFIG_KEY]) > 1
|
|
312
|
-
):
|
|
313
|
-
inference_model_name = perform_embeddings_model_group_consistency_check(
|
|
314
|
-
custom_config,
|
|
315
|
-
default_config,
|
|
316
|
-
log_source_function,
|
|
317
|
-
log_source_component,
|
|
318
|
-
)
|
|
319
|
-
else:
|
|
320
|
-
embedder = try_instantiate_embedder(
|
|
321
|
-
custom_config, default_config, log_source_function, log_source_component
|
|
322
|
-
)
|
|
323
|
-
inference_model_name = send_test_embeddings_api_request(
|
|
324
|
-
embedder, log_source_function, log_source_component
|
|
325
|
-
)
|
|
326
|
-
|
|
327
|
-
if not inference_model_name:
|
|
328
|
-
structlogger.warning(
|
|
329
|
-
f"{log_source_function}"
|
|
330
|
-
f".perform_inference_time_embeddings_health_check.no_inference_model",
|
|
331
|
-
event_info=(
|
|
332
|
-
"Failed to perform embeddings model consistency check: "
|
|
333
|
-
"the API response does not contain a model name."
|
|
334
|
-
),
|
|
335
|
-
)
|
|
336
|
-
elif not train_model_name:
|
|
337
|
-
structlogger.warning(
|
|
338
|
-
f"{log_source_function}"
|
|
339
|
-
f".perform_inference_time_embeddings_health_check.no_train_model",
|
|
340
|
-
event_info=(
|
|
341
|
-
f"The model was trained with {LLM_API_HEALTH_CHECK_ENV_VAR} "
|
|
342
|
-
f"environment variable set to false, so the model "
|
|
343
|
-
f"consistency check is not available."
|
|
344
|
-
),
|
|
345
|
-
)
|
|
346
|
-
elif inference_model_name != train_model_name:
|
|
347
|
-
error_message = (
|
|
348
|
-
f"The Embeddings model used to train the {log_source_component} "
|
|
349
|
-
f"({train_model_name}) is not the same as the model used for inference "
|
|
350
|
-
f"({inference_model_name}). Please verify your configuration."
|
|
351
|
-
)
|
|
352
|
-
structlogger.error(
|
|
353
|
-
f"{log_source_function}.train_inference_embeddings_model_mismatch",
|
|
354
|
-
event_info=error_message,
|
|
355
|
-
)
|
|
356
|
-
print_error_and_exit(error_message)
|
|
357
|
-
else:
|
|
358
|
-
structlogger.warning(
|
|
359
|
-
f"{log_source_function}"
|
|
360
|
-
f".perform_inference_time_embeddings_health_check.disabled",
|
|
361
|
-
event_info=(
|
|
362
|
-
f"The {LLM_API_HEALTH_CHECK_ENV_VAR} environment variable is set "
|
|
363
|
-
f"to false, which will disable model consistency check. "
|
|
364
|
-
f"It is recommended to set this variable to true in production "
|
|
365
|
-
f"environments."
|
|
366
|
-
),
|
|
367
|
-
)
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
def perform_llm_model_group_consistency_check(
|
|
371
|
-
custom_config: Dict[str, Any],
|
|
372
|
-
default_config: Dict[str, Any],
|
|
373
|
-
log_source_function: str,
|
|
374
|
-
log_source_component: str,
|
|
375
|
-
) -> Optional[str]:
|
|
376
|
-
"""Perform a consistency check for multiple models inside a model group.
|
|
377
|
-
|
|
378
|
-
This function checks if all models within a model group are consistent by verifying
|
|
379
|
-
that they all return the same model name from the LLM API health check.
|
|
380
|
-
|
|
381
|
-
This method supports only model group configuration (config that have the `models`
|
|
382
|
-
key) and will ignore single model configuration.
|
|
383
|
-
|
|
384
|
-
Returns:
|
|
385
|
-
The model name if all models are consistent, otherwise raises
|
|
386
|
-
an InvalidConfigException.
|
|
387
|
-
|
|
388
|
-
Raises:
|
|
389
|
-
InvalidConfigException: If the model group contains different models.
|
|
390
|
-
"""
|
|
391
|
-
if not custom_config or MODELS_CONFIG_KEY not in custom_config:
|
|
392
|
-
return None
|
|
393
|
-
|
|
394
|
-
model_names = set()
|
|
395
|
-
for model_config in custom_config[MODELS_CONFIG_KEY]:
|
|
396
|
-
llm_client = try_instantiate_llm_client(
|
|
397
|
-
model_config, default_config, log_source_function, log_source_component
|
|
398
|
-
)
|
|
399
|
-
model_name = send_test_llm_api_request(
|
|
400
|
-
llm_client, log_source_function, log_source_component
|
|
401
|
-
)
|
|
402
|
-
model_names.add(model_name)
|
|
403
|
-
|
|
404
|
-
if len(model_names) > 1:
|
|
405
|
-
error_message = (
|
|
406
|
-
f"The model group {custom_config.get(MODEL_GROUP_ID_CONFIG_KEY)} used by "
|
|
407
|
-
f"{log_source_component} component is inconsistent. "
|
|
408
|
-
f"It contains different models: {model_names}. "
|
|
409
|
-
f"Please verify your configuration."
|
|
410
|
-
)
|
|
411
|
-
structlogger.error(
|
|
412
|
-
f"{log_source_function}.inconsistent_model_group", event_info=error_message
|
|
413
|
-
)
|
|
414
|
-
print_error_and_exit(error_message)
|
|
415
|
-
|
|
416
|
-
return model_names.pop() if len(model_names) > 0 else None
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
def send_test_llm_api_request(
|
|
420
|
-
llm_client: LLMClient, log_source_function: str, log_source_component: str
|
|
421
|
-
) -> Optional[str]:
|
|
422
|
-
"""Sends a test request to the LLM API to perform a health check.
|
|
423
|
-
|
|
424
|
-
Returns:
|
|
425
|
-
The model name from the API response.
|
|
426
|
-
|
|
427
|
-
Raises:
|
|
428
|
-
Exception: If the API call fails.
|
|
429
|
-
"""
|
|
430
|
-
structlogger.info(
|
|
431
|
-
f"{log_source_function}.send_test_llm_api_request",
|
|
432
|
-
event_info=(
|
|
433
|
-
f"Sending a test LLM API request for the component - "
|
|
434
|
-
f"{log_source_component}."
|
|
435
|
-
),
|
|
436
|
-
config=llm_client.config,
|
|
437
|
-
)
|
|
438
|
-
try:
|
|
439
|
-
response = llm_client.completion("hello")
|
|
440
|
-
return response.model
|
|
441
|
-
except Exception as e:
|
|
442
|
-
structlogger.error(
|
|
443
|
-
f"{log_source_function}.send_test_llm_api_request_failed",
|
|
444
|
-
event_info="Test call to the LLM API failed.",
|
|
445
|
-
error=e,
|
|
446
|
-
)
|
|
447
|
-
print_error_and_exit(
|
|
448
|
-
f"Test call to the LLM API failed for component - {log_source_component}. "
|
|
449
|
-
f"Error: {e}"
|
|
450
|
-
)
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
def send_test_embeddings_api_request(
|
|
454
|
-
embedder: EmbeddingClient, log_source_function: str, log_source_component: str
|
|
455
|
-
) -> Optional[str]:
|
|
456
|
-
"""Sends a test request to the Embeddings API to perform a health check.
|
|
457
|
-
|
|
458
|
-
Returns:
|
|
459
|
-
The model name from the API response.
|
|
460
|
-
|
|
461
|
-
Raises:
|
|
462
|
-
Exception: If the API call fails.
|
|
463
|
-
"""
|
|
464
|
-
structlogger.info(
|
|
465
|
-
f"{log_source_function}.send_test_embeddings_api_request",
|
|
466
|
-
event_info=(
|
|
467
|
-
f"Sending a test Embeddings API request for the component - "
|
|
468
|
-
f"{log_source_component}."
|
|
469
|
-
),
|
|
470
|
-
config=embedder.config,
|
|
471
|
-
)
|
|
472
|
-
try:
|
|
473
|
-
response = embedder.embed(["hello"])
|
|
474
|
-
return response.model
|
|
475
|
-
except Exception as e:
|
|
476
|
-
structlogger.error(
|
|
477
|
-
f"{log_source_function}.send_test_llm_api_request_failed",
|
|
478
|
-
event_info="Test call to the Embeddings API failed.",
|
|
479
|
-
error=e,
|
|
480
|
-
)
|
|
481
|
-
print_error_and_exit(
|
|
482
|
-
f"Test call to the Embeddings API failed for component - "
|
|
483
|
-
f"{log_source_component}. Error: {e}"
|
|
484
|
-
)
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
def perform_embeddings_model_group_consistency_check(
|
|
488
|
-
custom_config: Dict[str, Any],
|
|
489
|
-
default_config: Dict[str, Any],
|
|
490
|
-
log_source_function: str,
|
|
491
|
-
log_source_component: str,
|
|
492
|
-
) -> Optional[str]:
|
|
493
|
-
"""Perform a consistency check for multiple embeddings models inside a model group.
|
|
494
|
-
|
|
495
|
-
This function checks if all models within a model group are consistent by verifying
|
|
496
|
-
that they all return the same model name from the Embeddings API health check.
|
|
497
|
-
|
|
498
|
-
This method supports only model group configuration (config that have the `models`
|
|
499
|
-
key) and will ignore single model configuration.
|
|
500
|
-
|
|
501
|
-
Returns:
|
|
502
|
-
The model name if all models are consistent, otherwise raises
|
|
503
|
-
an InvalidConfigException.
|
|
504
|
-
|
|
505
|
-
Raises:
|
|
506
|
-
InvalidConfigException: If the model group contains different models.
|
|
507
|
-
"""
|
|
508
|
-
if not custom_config or MODELS_CONFIG_KEY not in custom_config:
|
|
509
|
-
return None
|
|
510
|
-
|
|
511
|
-
model_names = set()
|
|
512
|
-
for model_config in custom_config[MODELS_CONFIG_KEY]:
|
|
513
|
-
embedder = try_instantiate_embedder(
|
|
514
|
-
custom_config, default_config, log_source_function, log_source_component
|
|
515
|
-
)
|
|
516
|
-
model_name = send_test_embeddings_api_request(
|
|
517
|
-
embedder, log_source_function, log_source_component
|
|
518
|
-
)
|
|
519
|
-
model_names.add(model_name)
|
|
520
|
-
|
|
521
|
-
if len(model_names) > 1:
|
|
522
|
-
error_message = (
|
|
523
|
-
f"The embeddings model group {custom_config.get(MODEL_GROUP_ID_CONFIG_KEY)}"
|
|
524
|
-
f" used by {log_source_component} component is inconsistent. "
|
|
525
|
-
f"It contains different models: {model_names}. "
|
|
526
|
-
f"Please verify your configuration."
|
|
527
|
-
)
|
|
528
|
-
structlogger.error(
|
|
529
|
-
f"{log_source_function}.inconsistent_embeddings", event_info=error_message
|
|
530
|
-
)
|
|
531
|
-
print_error_and_exit(error_message)
|
|
532
|
-
|
|
533
|
-
return model_names.pop() if len(model_names) > 0 else None
|
|
File without changes
|
|
File without changes
|
|
File without changes
|