nvidia-nat 1.2.1rc1__py3-none-any.whl → 1.3.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.
- aiq/__init__.py +2 -2
- nat/agent/base.py +27 -18
- nat/agent/dual_node.py +9 -4
- nat/agent/prompt_optimizer/prompt.py +68 -0
- nat/agent/prompt_optimizer/register.py +149 -0
- nat/agent/react_agent/agent.py +81 -50
- nat/agent/react_agent/register.py +59 -40
- nat/agent/reasoning_agent/reasoning_agent.py +17 -15
- nat/agent/register.py +1 -1
- nat/agent/rewoo_agent/agent.py +327 -149
- nat/agent/rewoo_agent/prompt.py +19 -22
- nat/agent/rewoo_agent/register.py +64 -46
- nat/agent/tool_calling_agent/agent.py +152 -29
- nat/agent/tool_calling_agent/register.py +61 -38
- nat/authentication/api_key/api_key_auth_provider.py +2 -2
- nat/authentication/credential_validator/bearer_token_validator.py +557 -0
- nat/authentication/http_basic_auth/http_basic_auth_provider.py +1 -1
- nat/authentication/interfaces.py +5 -2
- nat/authentication/oauth2/oauth2_auth_code_flow_provider.py +69 -36
- nat/authentication/oauth2/oauth2_resource_server_config.py +124 -0
- nat/authentication/register.py +0 -1
- nat/builder/builder.py +56 -24
- nat/builder/component_utils.py +10 -6
- nat/builder/context.py +70 -18
- nat/builder/eval_builder.py +16 -11
- nat/builder/framework_enum.py +1 -0
- nat/builder/front_end.py +1 -1
- nat/builder/function.py +378 -8
- nat/builder/function_base.py +3 -3
- nat/builder/function_info.py +6 -8
- nat/builder/intermediate_step_manager.py +6 -2
- nat/builder/user_interaction_manager.py +2 -2
- nat/builder/workflow.py +13 -1
- nat/builder/workflow_builder.py +327 -79
- nat/cli/cli_utils/config_override.py +2 -2
- nat/cli/commands/evaluate.py +1 -1
- nat/cli/commands/info/info.py +16 -6
- nat/cli/commands/info/list_channels.py +1 -1
- nat/cli/commands/info/list_components.py +7 -8
- nat/cli/commands/mcp/__init__.py +14 -0
- nat/cli/commands/mcp/mcp.py +986 -0
- nat/cli/commands/object_store/__init__.py +14 -0
- nat/cli/commands/object_store/object_store.py +227 -0
- nat/cli/commands/optimize.py +90 -0
- nat/cli/commands/registry/publish.py +2 -2
- nat/cli/commands/registry/pull.py +2 -2
- nat/cli/commands/registry/remove.py +2 -2
- nat/cli/commands/registry/search.py +15 -17
- nat/cli/commands/start.py +16 -5
- nat/cli/commands/uninstall.py +1 -1
- nat/cli/commands/workflow/templates/config.yml.j2 +14 -13
- nat/cli/commands/workflow/templates/pyproject.toml.j2 +5 -2
- nat/cli/commands/workflow/templates/register.py.j2 +2 -3
- nat/cli/commands/workflow/templates/workflow.py.j2 +35 -21
- nat/cli/commands/workflow/workflow_commands.py +105 -19
- nat/cli/entrypoint.py +17 -11
- nat/cli/main.py +3 -0
- nat/cli/register_workflow.py +38 -4
- nat/cli/type_registry.py +79 -10
- nat/control_flow/__init__.py +0 -0
- nat/control_flow/register.py +20 -0
- nat/control_flow/router_agent/__init__.py +0 -0
- nat/control_flow/router_agent/agent.py +329 -0
- nat/control_flow/router_agent/prompt.py +48 -0
- nat/control_flow/router_agent/register.py +91 -0
- nat/control_flow/sequential_executor.py +166 -0
- nat/data_models/agent.py +34 -0
- nat/data_models/api_server.py +196 -67
- nat/data_models/authentication.py +23 -9
- nat/data_models/common.py +1 -1
- nat/data_models/component.py +2 -0
- nat/data_models/component_ref.py +11 -0
- nat/data_models/config.py +42 -18
- nat/data_models/dataset_handler.py +1 -1
- nat/data_models/discovery_metadata.py +4 -4
- nat/data_models/evaluate.py +4 -1
- nat/data_models/function.py +34 -0
- nat/data_models/function_dependencies.py +14 -6
- nat/data_models/gated_field_mixin.py +242 -0
- nat/data_models/intermediate_step.py +3 -3
- nat/data_models/optimizable.py +119 -0
- nat/data_models/optimizer.py +149 -0
- nat/data_models/span.py +41 -3
- nat/data_models/swe_bench_model.py +1 -1
- nat/data_models/temperature_mixin.py +44 -0
- nat/data_models/thinking_mixin.py +86 -0
- nat/data_models/top_p_mixin.py +44 -0
- nat/embedder/azure_openai_embedder.py +46 -0
- nat/embedder/nim_embedder.py +1 -1
- nat/embedder/openai_embedder.py +2 -3
- nat/embedder/register.py +1 -1
- nat/eval/config.py +3 -1
- nat/eval/dataset_handler/dataset_handler.py +71 -7
- nat/eval/evaluate.py +86 -31
- nat/eval/evaluator/base_evaluator.py +1 -1
- nat/eval/evaluator/evaluator_model.py +13 -0
- nat/eval/intermediate_step_adapter.py +1 -1
- nat/eval/rag_evaluator/evaluate.py +9 -6
- nat/eval/rag_evaluator/register.py +3 -3
- nat/eval/register.py +4 -1
- nat/eval/remote_workflow.py +3 -3
- nat/eval/runtime_evaluator/__init__.py +14 -0
- nat/eval/runtime_evaluator/evaluate.py +123 -0
- nat/eval/runtime_evaluator/register.py +100 -0
- nat/eval/swe_bench_evaluator/evaluate.py +6 -6
- nat/eval/trajectory_evaluator/evaluate.py +1 -1
- nat/eval/trajectory_evaluator/register.py +1 -1
- nat/eval/tunable_rag_evaluator/evaluate.py +4 -7
- nat/eval/utils/eval_trace_ctx.py +89 -0
- nat/eval/utils/weave_eval.py +18 -9
- nat/experimental/decorators/experimental_warning_decorator.py +27 -7
- nat/experimental/test_time_compute/functions/execute_score_select_function.py +1 -1
- nat/experimental/test_time_compute/functions/plan_select_execute_function.py +7 -3
- nat/experimental/test_time_compute/functions/ttc_tool_orchestration_function.py +3 -3
- nat/experimental/test_time_compute/functions/ttc_tool_wrapper_function.py +3 -3
- nat/experimental/test_time_compute/models/strategy_base.py +5 -4
- nat/experimental/test_time_compute/register.py +0 -1
- nat/experimental/test_time_compute/selection/llm_based_output_merging_selector.py +1 -3
- nat/front_ends/console/authentication_flow_handler.py +82 -30
- nat/front_ends/console/console_front_end_plugin.py +19 -7
- nat/front_ends/fastapi/auth_flow_handlers/http_flow_handler.py +1 -1
- nat/front_ends/fastapi/auth_flow_handlers/websocket_flow_handler.py +52 -17
- nat/front_ends/fastapi/dask_client_mixin.py +65 -0
- nat/front_ends/fastapi/fastapi_front_end_config.py +36 -5
- nat/front_ends/fastapi/fastapi_front_end_controller.py +4 -4
- nat/front_ends/fastapi/fastapi_front_end_plugin.py +135 -4
- nat/front_ends/fastapi/fastapi_front_end_plugin_worker.py +455 -282
- nat/front_ends/fastapi/job_store.py +518 -99
- nat/front_ends/fastapi/main.py +11 -19
- nat/front_ends/fastapi/message_handler.py +74 -50
- nat/front_ends/fastapi/message_validator.py +20 -21
- nat/front_ends/fastapi/response_helpers.py +4 -4
- nat/front_ends/fastapi/step_adaptor.py +2 -2
- nat/front_ends/fastapi/utils.py +57 -0
- nat/front_ends/mcp/introspection_token_verifier.py +73 -0
- nat/front_ends/mcp/mcp_front_end_config.py +47 -3
- nat/front_ends/mcp/mcp_front_end_plugin.py +48 -13
- nat/front_ends/mcp/mcp_front_end_plugin_worker.py +120 -8
- nat/front_ends/mcp/tool_converter.py +44 -14
- nat/front_ends/register.py +0 -1
- nat/front_ends/simple_base/simple_front_end_plugin_base.py +3 -1
- nat/llm/aws_bedrock_llm.py +24 -12
- nat/llm/azure_openai_llm.py +57 -0
- nat/llm/litellm_llm.py +69 -0
- nat/llm/nim_llm.py +20 -8
- nat/llm/openai_llm.py +14 -6
- nat/llm/register.py +5 -1
- nat/llm/utils/env_config_value.py +2 -3
- nat/llm/utils/thinking.py +215 -0
- nat/meta/pypi.md +9 -9
- nat/object_store/register.py +0 -1
- nat/observability/exporter/base_exporter.py +3 -3
- nat/observability/exporter/file_exporter.py +1 -1
- nat/observability/exporter/processing_exporter.py +309 -81
- nat/observability/exporter/span_exporter.py +35 -15
- nat/observability/exporter_manager.py +7 -7
- nat/observability/mixin/file_mixin.py +7 -7
- nat/observability/mixin/redaction_config_mixin.py +42 -0
- nat/observability/mixin/tagging_config_mixin.py +62 -0
- nat/observability/mixin/type_introspection_mixin.py +420 -107
- nat/observability/processor/batching_processor.py +5 -7
- nat/observability/processor/falsy_batch_filter_processor.py +55 -0
- nat/observability/processor/processor.py +3 -0
- nat/observability/processor/processor_factory.py +70 -0
- nat/observability/processor/redaction/__init__.py +24 -0
- nat/observability/processor/redaction/contextual_redaction_processor.py +125 -0
- nat/observability/processor/redaction/contextual_span_redaction_processor.py +66 -0
- nat/observability/processor/redaction/redaction_processor.py +177 -0
- nat/observability/processor/redaction/span_header_redaction_processor.py +92 -0
- nat/observability/processor/span_tagging_processor.py +68 -0
- nat/observability/register.py +22 -4
- nat/profiler/calc/calc_runner.py +3 -4
- nat/profiler/callbacks/agno_callback_handler.py +1 -1
- nat/profiler/callbacks/langchain_callback_handler.py +14 -7
- nat/profiler/callbacks/llama_index_callback_handler.py +3 -3
- nat/profiler/callbacks/semantic_kernel_callback_handler.py +3 -3
- nat/profiler/data_frame_row.py +1 -1
- nat/profiler/decorators/framework_wrapper.py +62 -13
- nat/profiler/decorators/function_tracking.py +160 -3
- nat/profiler/forecasting/models/forecasting_base_model.py +3 -1
- nat/profiler/forecasting/models/linear_model.py +1 -1
- nat/profiler/forecasting/models/random_forest_regressor.py +1 -1
- nat/profiler/inference_optimization/bottleneck_analysis/nested_stack_analysis.py +1 -1
- nat/profiler/inference_optimization/bottleneck_analysis/simple_stack_analysis.py +1 -1
- nat/profiler/inference_optimization/data_models.py +3 -3
- nat/profiler/inference_optimization/experimental/prefix_span_analysis.py +8 -9
- nat/profiler/inference_optimization/token_uniqueness.py +1 -1
- nat/profiler/parameter_optimization/__init__.py +0 -0
- nat/profiler/parameter_optimization/optimizable_utils.py +93 -0
- nat/profiler/parameter_optimization/optimizer_runtime.py +67 -0
- nat/profiler/parameter_optimization/parameter_optimizer.py +164 -0
- nat/profiler/parameter_optimization/parameter_selection.py +107 -0
- nat/profiler/parameter_optimization/pareto_visualizer.py +395 -0
- nat/profiler/parameter_optimization/prompt_optimizer.py +384 -0
- nat/profiler/parameter_optimization/update_helpers.py +66 -0
- nat/profiler/profile_runner.py +14 -9
- nat/profiler/utils.py +4 -2
- nat/registry_handlers/local/local_handler.py +2 -2
- nat/registry_handlers/package_utils.py +1 -2
- nat/registry_handlers/pypi/pypi_handler.py +23 -26
- nat/registry_handlers/register.py +3 -4
- nat/registry_handlers/rest/rest_handler.py +12 -13
- nat/retriever/milvus/retriever.py +2 -2
- nat/retriever/nemo_retriever/retriever.py +1 -1
- nat/retriever/register.py +0 -1
- nat/runtime/loader.py +2 -2
- nat/runtime/runner.py +105 -8
- nat/runtime/session.py +69 -8
- nat/settings/global_settings.py +16 -5
- nat/tool/chat_completion.py +5 -2
- nat/tool/code_execution/local_sandbox/local_sandbox_server.py +3 -3
- nat/tool/datetime_tools.py +49 -9
- nat/tool/document_search.py +2 -2
- nat/tool/github_tools.py +450 -0
- nat/tool/memory_tools/add_memory_tool.py +3 -3
- nat/tool/memory_tools/delete_memory_tool.py +3 -4
- nat/tool/memory_tools/get_memory_tool.py +4 -4
- nat/tool/nvidia_rag.py +1 -1
- nat/tool/register.py +2 -9
- nat/tool/retriever.py +3 -2
- nat/utils/callable_utils.py +70 -0
- nat/utils/data_models/schema_validator.py +3 -3
- nat/utils/decorators.py +210 -0
- nat/utils/exception_handlers/automatic_retries.py +104 -51
- nat/utils/exception_handlers/schemas.py +1 -1
- nat/utils/io/yaml_tools.py +2 -2
- nat/utils/log_levels.py +25 -0
- nat/utils/reactive/base/observable_base.py +2 -2
- nat/utils/reactive/base/observer_base.py +1 -1
- nat/utils/reactive/observable.py +2 -2
- nat/utils/reactive/observer.py +4 -4
- nat/utils/reactive/subscription.py +1 -1
- nat/utils/settings/global_settings.py +6 -8
- nat/utils/type_converter.py +12 -3
- nat/utils/type_utils.py +9 -5
- nvidia_nat-1.3.0.dist-info/METADATA +195 -0
- {nvidia_nat-1.2.1rc1.dist-info → nvidia_nat-1.3.0.dist-info}/RECORD +244 -200
- {nvidia_nat-1.2.1rc1.dist-info → nvidia_nat-1.3.0.dist-info}/entry_points.txt +1 -0
- nat/cli/commands/info/list_mcp.py +0 -304
- nat/tool/github_tools/create_github_commit.py +0 -133
- nat/tool/github_tools/create_github_issue.py +0 -87
- nat/tool/github_tools/create_github_pr.py +0 -106
- nat/tool/github_tools/get_github_file.py +0 -106
- nat/tool/github_tools/get_github_issue.py +0 -166
- nat/tool/github_tools/get_github_pr.py +0 -256
- nat/tool/github_tools/update_github_issue.py +0 -100
- nat/tool/mcp/exceptions.py +0 -142
- nat/tool/mcp/mcp_client.py +0 -255
- nat/tool/mcp/mcp_tool.py +0 -96
- nat/utils/exception_handlers/mcp.py +0 -211
- nvidia_nat-1.2.1rc1.dist-info/METADATA +0 -365
- /nat/{tool/github_tools → agent/prompt_optimizer}/__init__.py +0 -0
- /nat/{tool/mcp → authentication/credential_validator}/__init__.py +0 -0
- {nvidia_nat-1.2.1rc1.dist-info → nvidia_nat-1.3.0.dist-info}/WHEEL +0 -0
- {nvidia_nat-1.2.1rc1.dist-info → nvidia_nat-1.3.0.dist-info}/licenses/LICENSE-3rd-party.txt +0 -0
- {nvidia_nat-1.2.1rc1.dist-info → nvidia_nat-1.3.0.dist-info}/licenses/LICENSE.md +0 -0
- {nvidia_nat-1.2.1rc1.dist-info → nvidia_nat-1.3.0.dist-info}/top_level.txt +0 -0
nat/data_models/config.py
CHANGED
|
@@ -20,6 +20,7 @@ import typing
|
|
|
20
20
|
from pydantic import BaseModel
|
|
21
21
|
from pydantic import ConfigDict
|
|
22
22
|
from pydantic import Discriminator
|
|
23
|
+
from pydantic import Field
|
|
23
24
|
from pydantic import ValidationError
|
|
24
25
|
from pydantic import ValidationInfo
|
|
25
26
|
from pydantic import ValidatorFunctionWrapHandler
|
|
@@ -29,7 +30,9 @@ from nat.data_models.evaluate import EvalConfig
|
|
|
29
30
|
from nat.data_models.front_end import FrontEndBaseConfig
|
|
30
31
|
from nat.data_models.function import EmptyFunctionConfig
|
|
31
32
|
from nat.data_models.function import FunctionBaseConfig
|
|
33
|
+
from nat.data_models.function import FunctionGroupBaseConfig
|
|
32
34
|
from nat.data_models.logging import LoggingBaseConfig
|
|
35
|
+
from nat.data_models.optimizer import OptimizerConfig
|
|
33
36
|
from nat.data_models.telemetry_exporter import TelemetryExporterBaseConfig
|
|
34
37
|
from nat.data_models.ttc_strategy import TTCStrategyBaseConfig
|
|
35
38
|
from nat.front_ends.fastapi.fastapi_front_end_config import FastApiFrontEndConfig
|
|
@@ -47,7 +50,7 @@ logger = logging.getLogger(__name__)
|
|
|
47
50
|
|
|
48
51
|
|
|
49
52
|
def _process_validation_error(err: ValidationError, handler: ValidatorFunctionWrapHandler, info: ValidationInfo):
|
|
50
|
-
from nat.cli.type_registry import GlobalTypeRegistry
|
|
53
|
+
from nat.cli.type_registry import GlobalTypeRegistry
|
|
51
54
|
|
|
52
55
|
new_errors = []
|
|
53
56
|
logged_once = False
|
|
@@ -57,9 +60,10 @@ def _process_validation_error(err: ValidationError, handler: ValidatorFunctionWr
|
|
|
57
60
|
error_type = e['type']
|
|
58
61
|
if error_type == 'union_tag_invalid' and "ctx" in e and not logged_once:
|
|
59
62
|
requested_type = e["ctx"]["tag"]
|
|
60
|
-
|
|
61
63
|
if (info.field_name in ('workflow', 'functions')):
|
|
62
64
|
registered_keys = GlobalTypeRegistry.get().get_registered_functions()
|
|
65
|
+
elif (info.field_name == "function_groups"):
|
|
66
|
+
registered_keys = GlobalTypeRegistry.get().get_registered_function_groups()
|
|
63
67
|
elif (info.field_name == "authentication"):
|
|
64
68
|
registered_keys = GlobalTypeRegistry.get().get_registered_auth_providers()
|
|
65
69
|
elif (info.field_name == "llms"):
|
|
@@ -135,8 +139,8 @@ def _process_validation_error(err: ValidationError, handler: ValidatorFunctionWr
|
|
|
135
139
|
|
|
136
140
|
class TelemetryConfig(BaseModel):
|
|
137
141
|
|
|
138
|
-
logging: dict[str, LoggingBaseConfig] =
|
|
139
|
-
tracing: dict[str, TelemetryExporterBaseConfig] =
|
|
142
|
+
logging: dict[str, LoggingBaseConfig] = Field(default_factory=dict)
|
|
143
|
+
tracing: dict[str, TelemetryExporterBaseConfig] = Field(default_factory=dict)
|
|
140
144
|
|
|
141
145
|
@field_validator("logging", "tracing", mode="wrap")
|
|
142
146
|
@classmethod
|
|
@@ -183,12 +187,16 @@ class TelemetryConfig(BaseModel):
|
|
|
183
187
|
|
|
184
188
|
class GeneralConfig(BaseModel):
|
|
185
189
|
|
|
186
|
-
model_config = ConfigDict(protected_namespaces=())
|
|
190
|
+
model_config = ConfigDict(protected_namespaces=(), extra="forbid")
|
|
187
191
|
|
|
188
|
-
use_uvloop: bool =
|
|
192
|
+
use_uvloop: bool | None = Field(
|
|
193
|
+
default=None,
|
|
194
|
+
deprecated=
|
|
195
|
+
"`use_uvloop` field is deprecated and will be removed in a future release. The use of `uv_loop` is now" +
|
|
196
|
+
"automatically determined based on platform")
|
|
189
197
|
"""
|
|
190
|
-
|
|
191
|
-
|
|
198
|
+
This field is deprecated and ignored. It previously controlled whether to use uvloop as the event loop. uvloop
|
|
199
|
+
usage is now determined automatically based on the platform.
|
|
192
200
|
"""
|
|
193
201
|
|
|
194
202
|
telemetry: TelemetryConfig = TelemetryConfig()
|
|
@@ -240,31 +248,37 @@ class Config(HashableBaseModel):
|
|
|
240
248
|
general: GeneralConfig = GeneralConfig()
|
|
241
249
|
|
|
242
250
|
# Functions Configuration
|
|
243
|
-
functions: dict[str, FunctionBaseConfig] =
|
|
251
|
+
functions: dict[str, FunctionBaseConfig] = Field(default_factory=dict)
|
|
252
|
+
|
|
253
|
+
# Function Groups Configuration
|
|
254
|
+
function_groups: dict[str, FunctionGroupBaseConfig] = Field(default_factory=dict)
|
|
244
255
|
|
|
245
256
|
# LLMs Configuration
|
|
246
|
-
llms: dict[str, LLMBaseConfig] =
|
|
257
|
+
llms: dict[str, LLMBaseConfig] = Field(default_factory=dict)
|
|
247
258
|
|
|
248
259
|
# Embedders Configuration
|
|
249
|
-
embedders: dict[str, EmbedderBaseConfig] =
|
|
260
|
+
embedders: dict[str, EmbedderBaseConfig] = Field(default_factory=dict)
|
|
250
261
|
|
|
251
262
|
# Memory Configuration
|
|
252
|
-
memory: dict[str, MemoryBaseConfig] =
|
|
263
|
+
memory: dict[str, MemoryBaseConfig] = Field(default_factory=dict)
|
|
253
264
|
|
|
254
265
|
# Object Stores Configuration
|
|
255
|
-
object_stores: dict[str, ObjectStoreBaseConfig] =
|
|
266
|
+
object_stores: dict[str, ObjectStoreBaseConfig] = Field(default_factory=dict)
|
|
267
|
+
|
|
268
|
+
# Optimizer Configuration
|
|
269
|
+
optimizer: OptimizerConfig = OptimizerConfig()
|
|
256
270
|
|
|
257
271
|
# Retriever Configuration
|
|
258
|
-
retrievers: dict[str, RetrieverBaseConfig] =
|
|
272
|
+
retrievers: dict[str, RetrieverBaseConfig] = Field(default_factory=dict)
|
|
259
273
|
|
|
260
274
|
# TTC Strategies
|
|
261
|
-
ttc_strategies: dict[str, TTCStrategyBaseConfig] =
|
|
275
|
+
ttc_strategies: dict[str, TTCStrategyBaseConfig] = Field(default_factory=dict)
|
|
262
276
|
|
|
263
277
|
# Workflow Configuration
|
|
264
278
|
workflow: FunctionBaseConfig = EmptyFunctionConfig()
|
|
265
279
|
|
|
266
280
|
# Authentication Configuration
|
|
267
|
-
authentication: dict[str, AuthProviderBaseConfig] =
|
|
281
|
+
authentication: dict[str, AuthProviderBaseConfig] = Field(default_factory=dict)
|
|
268
282
|
|
|
269
283
|
# Evaluation Options
|
|
270
284
|
eval: EvalConfig = EvalConfig()
|
|
@@ -278,6 +292,7 @@ class Config(HashableBaseModel):
|
|
|
278
292
|
stream.write(f"Workflow Type: {self.workflow.type}\n")
|
|
279
293
|
|
|
280
294
|
stream.write(f"Number of Functions: {len(self.functions)}\n")
|
|
295
|
+
stream.write(f"Number of Function Groups: {len(self.function_groups)}\n")
|
|
281
296
|
stream.write(f"Number of LLMs: {len(self.llms)}\n")
|
|
282
297
|
stream.write(f"Number of Embedders: {len(self.embedders)}\n")
|
|
283
298
|
stream.write(f"Number of Memory: {len(self.memory)}\n")
|
|
@@ -287,6 +302,7 @@ class Config(HashableBaseModel):
|
|
|
287
302
|
stream.write(f"Number of Authentication Providers: {len(self.authentication)}\n")
|
|
288
303
|
|
|
289
304
|
@field_validator("functions",
|
|
305
|
+
"function_groups",
|
|
290
306
|
"llms",
|
|
291
307
|
"embedders",
|
|
292
308
|
"memory",
|
|
@@ -328,6 +344,10 @@ class Config(HashableBaseModel):
|
|
|
328
344
|
typing.Annotated[type_registry.compute_annotation(FunctionBaseConfig),
|
|
329
345
|
Discriminator(TypedBaseModel.discriminator)]]
|
|
330
346
|
|
|
347
|
+
FunctionGroupsAnnotation = dict[str,
|
|
348
|
+
typing.Annotated[type_registry.compute_annotation(FunctionGroupBaseConfig),
|
|
349
|
+
Discriminator(TypedBaseModel.discriminator)]]
|
|
350
|
+
|
|
331
351
|
MemoryAnnotation = dict[str,
|
|
332
352
|
typing.Annotated[type_registry.compute_annotation(MemoryBaseConfig),
|
|
333
353
|
Discriminator(TypedBaseModel.discriminator)]]
|
|
@@ -335,7 +355,6 @@ class Config(HashableBaseModel):
|
|
|
335
355
|
ObjectStoreAnnotation = dict[str,
|
|
336
356
|
typing.Annotated[type_registry.compute_annotation(ObjectStoreBaseConfig),
|
|
337
357
|
Discriminator(TypedBaseModel.discriminator)]]
|
|
338
|
-
|
|
339
358
|
RetrieverAnnotation = dict[str,
|
|
340
359
|
typing.Annotated[type_registry.compute_annotation(RetrieverBaseConfig),
|
|
341
360
|
Discriminator(TypedBaseModel.discriminator)]]
|
|
@@ -344,7 +363,7 @@ class Config(HashableBaseModel):
|
|
|
344
363
|
typing.Annotated[type_registry.compute_annotation(TTCStrategyBaseConfig),
|
|
345
364
|
Discriminator(TypedBaseModel.discriminator)]]
|
|
346
365
|
|
|
347
|
-
WorkflowAnnotation = typing.Annotated[type_registry.compute_annotation(FunctionBaseConfig),
|
|
366
|
+
WorkflowAnnotation = typing.Annotated[(type_registry.compute_annotation(FunctionBaseConfig)),
|
|
348
367
|
Discriminator(TypedBaseModel.discriminator)]
|
|
349
368
|
|
|
350
369
|
should_rebuild = False
|
|
@@ -369,6 +388,11 @@ class Config(HashableBaseModel):
|
|
|
369
388
|
functions_field.annotation = FunctionsAnnotation
|
|
370
389
|
should_rebuild = True
|
|
371
390
|
|
|
391
|
+
function_groups_field = cls.model_fields.get("function_groups")
|
|
392
|
+
if function_groups_field is not None and function_groups_field.annotation != FunctionGroupsAnnotation:
|
|
393
|
+
function_groups_field.annotation = FunctionGroupsAnnotation
|
|
394
|
+
should_rebuild = True
|
|
395
|
+
|
|
372
396
|
memory_field = cls.model_fields.get("memory")
|
|
373
397
|
if memory_field is not None and memory_field.annotation != MemoryAnnotation:
|
|
374
398
|
memory_field.annotation = MemoryAnnotation
|
|
@@ -80,7 +80,7 @@ class EvalDatasetJsonConfig(EvalDatasetBaseConfig, name="json"):
|
|
|
80
80
|
|
|
81
81
|
|
|
82
82
|
def read_jsonl(file_path: FilePath):
|
|
83
|
-
with open(file_path,
|
|
83
|
+
with open(file_path, encoding='utf-8') as f:
|
|
84
84
|
data = [json.loads(line) for line in f]
|
|
85
85
|
return pd.DataFrame(data)
|
|
86
86
|
|
|
@@ -177,7 +177,7 @@ class DiscoveryMetadata(BaseModel):
|
|
|
177
177
|
logger.warning("Package metadata not found for %s", distro_name)
|
|
178
178
|
version = ""
|
|
179
179
|
except Exception as e:
|
|
180
|
-
logger.exception("Encountered issue extracting module metadata for %s: %s", config_type, e
|
|
180
|
+
logger.exception("Encountered issue extracting module metadata for %s: %s", config_type, e)
|
|
181
181
|
return DiscoveryMetadata(status=DiscoveryStatusEnum.FAILURE)
|
|
182
182
|
|
|
183
183
|
description = generate_config_type_docs(config_type=config_type)
|
|
@@ -217,7 +217,7 @@ class DiscoveryMetadata(BaseModel):
|
|
|
217
217
|
logger.warning("Package metadata not found for %s", distro_name)
|
|
218
218
|
version = ""
|
|
219
219
|
except Exception as e:
|
|
220
|
-
logger.exception("Encountered issue extracting module metadata for %s: %s", fn, e
|
|
220
|
+
logger.exception("Encountered issue extracting module metadata for %s: %s", fn, e)
|
|
221
221
|
return DiscoveryMetadata(status=DiscoveryStatusEnum.FAILURE)
|
|
222
222
|
|
|
223
223
|
if isinstance(wrapper_type, LLMFrameworkEnum):
|
|
@@ -252,7 +252,7 @@ class DiscoveryMetadata(BaseModel):
|
|
|
252
252
|
description = ""
|
|
253
253
|
package_version = package_version or ""
|
|
254
254
|
except Exception as e:
|
|
255
|
-
logger.exception("Encountered issue extracting module metadata for %s: %s", package_name, e
|
|
255
|
+
logger.exception("Encountered issue extracting module metadata for %s: %s", package_name, e)
|
|
256
256
|
return DiscoveryMetadata(status=DiscoveryStatusEnum.FAILURE)
|
|
257
257
|
|
|
258
258
|
return DiscoveryMetadata(package=package_name,
|
|
@@ -290,7 +290,7 @@ class DiscoveryMetadata(BaseModel):
|
|
|
290
290
|
logger.warning("Package metadata not found for %s", distro_name)
|
|
291
291
|
version = ""
|
|
292
292
|
except Exception as e:
|
|
293
|
-
logger.exception("Encountered issue extracting module metadata for %s: %s", config_type, e
|
|
293
|
+
logger.exception("Encountered issue extracting module metadata for %s: %s", config_type, e)
|
|
294
294
|
return DiscoveryMetadata(status=DiscoveryStatusEnum.FAILURE)
|
|
295
295
|
|
|
296
296
|
wrapper_type = wrapper_type.value if isinstance(wrapper_type, LLMFrameworkEnum) else wrapper_type
|
nat/data_models/evaluate.py
CHANGED
|
@@ -57,6 +57,9 @@ class EvalOutputConfig(BaseModel):
|
|
|
57
57
|
dir: Path = Path("./.tmp/nat/examples/default/")
|
|
58
58
|
# S3 prefix for the workflow and evaluation results
|
|
59
59
|
remote_dir: str | None = None
|
|
60
|
+
# Custom function to pre-evaluation process the eval input
|
|
61
|
+
# Format: "module.path.function_name"
|
|
62
|
+
custom_pre_eval_process_function: str | None = None
|
|
60
63
|
# Custom scripts to run after the workflow and evaluation results are saved
|
|
61
64
|
custom_scripts: dict[str, EvalCustomScriptConfig] = {}
|
|
62
65
|
# S3 config for uploading the contents of the output directory
|
|
@@ -108,7 +111,7 @@ class EvalConfig(BaseModel):
|
|
|
108
111
|
@classmethod
|
|
109
112
|
def rebuild_annotations(cls):
|
|
110
113
|
|
|
111
|
-
from nat.cli.type_registry import GlobalTypeRegistry
|
|
114
|
+
from nat.cli.type_registry import GlobalTypeRegistry
|
|
112
115
|
|
|
113
116
|
type_registry = GlobalTypeRegistry.get()
|
|
114
117
|
|
nat/data_models/function.py
CHANGED
|
@@ -15,6 +15,10 @@
|
|
|
15
15
|
|
|
16
16
|
import typing
|
|
17
17
|
|
|
18
|
+
from pydantic import Field
|
|
19
|
+
from pydantic import field_validator
|
|
20
|
+
from pydantic import model_validator
|
|
21
|
+
|
|
18
22
|
from .common import BaseModelRegistryTag
|
|
19
23
|
from .common import TypedBaseModel
|
|
20
24
|
|
|
@@ -23,8 +27,38 @@ class FunctionBaseConfig(TypedBaseModel, BaseModelRegistryTag):
|
|
|
23
27
|
pass
|
|
24
28
|
|
|
25
29
|
|
|
30
|
+
class FunctionGroupBaseConfig(TypedBaseModel, BaseModelRegistryTag):
|
|
31
|
+
"""Base configuration for function groups.
|
|
32
|
+
|
|
33
|
+
Function groups enable sharing of configurations and resources across multiple functions.
|
|
34
|
+
"""
|
|
35
|
+
include: list[str] = Field(
|
|
36
|
+
default_factory=list,
|
|
37
|
+
description="The list of function names which should be added to the global Function registry",
|
|
38
|
+
)
|
|
39
|
+
exclude: list[str] = Field(
|
|
40
|
+
default_factory=list,
|
|
41
|
+
description="The list of function names which should be excluded from default access to the group",
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
@field_validator("include", "exclude")
|
|
45
|
+
@classmethod
|
|
46
|
+
def _validate_fields_include_exclude(cls, value: list[str]) -> list[str]:
|
|
47
|
+
if len(set(value)) != len(value):
|
|
48
|
+
raise ValueError("Function names must be unique")
|
|
49
|
+
return sorted(value)
|
|
50
|
+
|
|
51
|
+
@model_validator(mode="after")
|
|
52
|
+
def _validate_include_exclude(self):
|
|
53
|
+
if self.include and self.exclude:
|
|
54
|
+
raise ValueError("include and exclude cannot be used together")
|
|
55
|
+
return self
|
|
56
|
+
|
|
57
|
+
|
|
26
58
|
class EmptyFunctionConfig(FunctionBaseConfig, name="EmptyFunctionConfig"):
|
|
27
59
|
pass
|
|
28
60
|
|
|
29
61
|
|
|
30
62
|
FunctionConfigT = typing.TypeVar("FunctionConfigT", bound=FunctionBaseConfig)
|
|
63
|
+
|
|
64
|
+
FunctionGroupConfigT = typing.TypeVar("FunctionGroupConfigT", bound=FunctionGroupBaseConfig)
|
|
@@ -23,6 +23,7 @@ class FunctionDependencies(BaseModel):
|
|
|
23
23
|
A class to represent the dependencies of a function.
|
|
24
24
|
"""
|
|
25
25
|
functions: set[str] = Field(default_factory=set)
|
|
26
|
+
function_groups: set[str] = Field(default_factory=set)
|
|
26
27
|
llms: set[str] = Field(default_factory=set)
|
|
27
28
|
embedders: set[str] = Field(default_factory=set)
|
|
28
29
|
memory_clients: set[str] = Field(default_factory=set)
|
|
@@ -33,6 +34,10 @@ class FunctionDependencies(BaseModel):
|
|
|
33
34
|
def serialize_functions(self, v: set[str]) -> list[str]:
|
|
34
35
|
return list(v)
|
|
35
36
|
|
|
37
|
+
@field_serializer("function_groups", when_used="json")
|
|
38
|
+
def serialize_function_groups(self, v: set[str]) -> list[str]:
|
|
39
|
+
return list(v)
|
|
40
|
+
|
|
36
41
|
@field_serializer("llms", when_used="json")
|
|
37
42
|
def serialize_llms(self, v: set[str]) -> list[str]:
|
|
38
43
|
return list(v)
|
|
@@ -54,19 +59,22 @@ class FunctionDependencies(BaseModel):
|
|
|
54
59
|
return list(v)
|
|
55
60
|
|
|
56
61
|
def add_function(self, function: str):
|
|
57
|
-
self.functions.add(function)
|
|
62
|
+
self.functions.add(function)
|
|
63
|
+
|
|
64
|
+
def add_function_group(self, function_group: str):
|
|
65
|
+
self.function_groups.add(function_group) # pylint: disable=no-member
|
|
58
66
|
|
|
59
67
|
def add_llm(self, llm: str):
|
|
60
|
-
self.llms.add(llm)
|
|
68
|
+
self.llms.add(llm)
|
|
61
69
|
|
|
62
70
|
def add_embedder(self, embedder: str):
|
|
63
|
-
self.embedders.add(embedder)
|
|
71
|
+
self.embedders.add(embedder)
|
|
64
72
|
|
|
65
73
|
def add_memory_client(self, memory_client: str):
|
|
66
|
-
self.memory_clients.add(memory_client)
|
|
74
|
+
self.memory_clients.add(memory_client)
|
|
67
75
|
|
|
68
76
|
def add_object_store(self, object_store: str):
|
|
69
|
-
self.object_stores.add(object_store)
|
|
77
|
+
self.object_stores.add(object_store)
|
|
70
78
|
|
|
71
79
|
def add_retriever(self, retriever: str):
|
|
72
|
-
self.retrievers.add(retriever)
|
|
80
|
+
self.retrievers.add(retriever)
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
|
|
16
|
+
from collections.abc import Sequence
|
|
17
|
+
from dataclasses import dataclass
|
|
18
|
+
from re import Pattern
|
|
19
|
+
|
|
20
|
+
from pydantic import model_validator
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@dataclass
|
|
24
|
+
class GatedFieldMixinConfig:
|
|
25
|
+
"""Configuration for a gated field mixin."""
|
|
26
|
+
|
|
27
|
+
field_name: str
|
|
28
|
+
default_if_supported: object | None
|
|
29
|
+
unsupported: Sequence[Pattern[str]] | None
|
|
30
|
+
supported: Sequence[Pattern[str]] | None
|
|
31
|
+
keys: Sequence[str]
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class GatedFieldMixin:
|
|
35
|
+
"""
|
|
36
|
+
A mixin that gates a field based on specified keys.
|
|
37
|
+
|
|
38
|
+
This should be used to automatically validate a field based on a given key.
|
|
39
|
+
|
|
40
|
+
Parameters
|
|
41
|
+
----------
|
|
42
|
+
field_name: `str`
|
|
43
|
+
The name of the field.
|
|
44
|
+
default_if_supported: `object | None`
|
|
45
|
+
The default value of the field if it is supported for the key.
|
|
46
|
+
keys: `Sequence[str]`
|
|
47
|
+
A sequence of keys that are used to validate the field.
|
|
48
|
+
unsupported: `Sequence[Pattern[str]] | None`
|
|
49
|
+
A sequence of regex patterns that match the key names NOT supported for the field.
|
|
50
|
+
Defaults to None.
|
|
51
|
+
supported: `Sequence[Pattern[str]] | None`
|
|
52
|
+
A sequence of regex patterns that match the key names supported for the field.
|
|
53
|
+
Defaults to None.
|
|
54
|
+
"""
|
|
55
|
+
|
|
56
|
+
def __init_subclass__(
|
|
57
|
+
cls,
|
|
58
|
+
field_name: str | None = None,
|
|
59
|
+
default_if_supported: object | None = None,
|
|
60
|
+
keys: Sequence[str] | None = None,
|
|
61
|
+
unsupported: Sequence[Pattern[str]] | None = None,
|
|
62
|
+
supported: Sequence[Pattern[str]] | None = None,
|
|
63
|
+
) -> None:
|
|
64
|
+
"""Store the class variables for the field and define the gated field validator."""
|
|
65
|
+
super().__init_subclass__()
|
|
66
|
+
|
|
67
|
+
# Check if this class directly inherits from GatedFieldMixin
|
|
68
|
+
has_gated_field_mixin = GatedFieldMixin in cls.__bases__
|
|
69
|
+
|
|
70
|
+
if has_gated_field_mixin:
|
|
71
|
+
if keys is None:
|
|
72
|
+
raise ValueError("keys must be provided when subclassing GatedFieldMixin")
|
|
73
|
+
if field_name is None:
|
|
74
|
+
raise ValueError("field_name must be provided when subclassing GatedFieldMixin")
|
|
75
|
+
|
|
76
|
+
cls._setup_direct_mixin(field_name, default_if_supported, unsupported, supported, keys)
|
|
77
|
+
|
|
78
|
+
# Always try to collect mixins and create validators for multiple inheritance
|
|
79
|
+
# This handles both direct inheritance and deep inheritance chains
|
|
80
|
+
all_mixins = cls._collect_all_mixin_configs()
|
|
81
|
+
if all_mixins:
|
|
82
|
+
cls._create_combined_validator(all_mixins)
|
|
83
|
+
|
|
84
|
+
@classmethod
|
|
85
|
+
def _setup_direct_mixin(
|
|
86
|
+
cls,
|
|
87
|
+
field_name: str,
|
|
88
|
+
default_if_supported: object | None,
|
|
89
|
+
unsupported: Sequence[Pattern[str]] | None,
|
|
90
|
+
supported: Sequence[Pattern[str]] | None,
|
|
91
|
+
keys: Sequence[str],
|
|
92
|
+
) -> None:
|
|
93
|
+
"""Set up a class that directly inherits from GatedFieldMixin."""
|
|
94
|
+
cls._validate_mixin_parameters(unsupported, supported, keys)
|
|
95
|
+
|
|
96
|
+
# Create and store validator
|
|
97
|
+
validator = cls._create_gated_field_validator(field_name, default_if_supported, unsupported, supported, keys)
|
|
98
|
+
validator_name = f"_gated_field_validator_{field_name}"
|
|
99
|
+
setattr(cls, validator_name, validator)
|
|
100
|
+
|
|
101
|
+
# Store mixin info for multiple inheritance
|
|
102
|
+
if not hasattr(cls, "_gated_field_mixins"):
|
|
103
|
+
cls._gated_field_mixins = []
|
|
104
|
+
|
|
105
|
+
cls._gated_field_mixins.append(
|
|
106
|
+
GatedFieldMixinConfig(
|
|
107
|
+
field_name,
|
|
108
|
+
default_if_supported,
|
|
109
|
+
unsupported,
|
|
110
|
+
supported,
|
|
111
|
+
keys,
|
|
112
|
+
))
|
|
113
|
+
|
|
114
|
+
@classmethod
|
|
115
|
+
def _validate_mixin_parameters(
|
|
116
|
+
cls,
|
|
117
|
+
unsupported: Sequence[Pattern[str]] | None,
|
|
118
|
+
supported: Sequence[Pattern[str]] | None,
|
|
119
|
+
keys: Sequence[str],
|
|
120
|
+
) -> None:
|
|
121
|
+
"""Validate that all required parameters are provided."""
|
|
122
|
+
if unsupported is None and supported is None:
|
|
123
|
+
raise ValueError("Either unsupported or supported must be provided")
|
|
124
|
+
if unsupported is not None and supported is not None:
|
|
125
|
+
raise ValueError("Only one of unsupported or supported must be provided")
|
|
126
|
+
if len(keys) == 0:
|
|
127
|
+
raise ValueError("keys must be provided and non-empty when subclassing GatedFieldMixin")
|
|
128
|
+
|
|
129
|
+
@classmethod
|
|
130
|
+
def _create_gated_field_validator(
|
|
131
|
+
cls,
|
|
132
|
+
field_name: str,
|
|
133
|
+
default_if_supported: object | None,
|
|
134
|
+
unsupported: Sequence[Pattern[str]] | None,
|
|
135
|
+
supported: Sequence[Pattern[str]] | None,
|
|
136
|
+
keys: Sequence[str],
|
|
137
|
+
):
|
|
138
|
+
"""Create the model validator function."""
|
|
139
|
+
|
|
140
|
+
@model_validator(mode="after")
|
|
141
|
+
def gated_field_validator(self):
|
|
142
|
+
"""Validate the gated field."""
|
|
143
|
+
current_value = getattr(self, field_name, None)
|
|
144
|
+
is_supported = cls._check_field_support(self, unsupported, supported, keys)
|
|
145
|
+
if not is_supported:
|
|
146
|
+
if current_value is not None:
|
|
147
|
+
blocking_key = cls._find_blocking_key(self, unsupported, supported, keys)
|
|
148
|
+
value = getattr(self, blocking_key, "<unknown>")
|
|
149
|
+
raise ValueError(f"{field_name} is not supported for {blocking_key}: {value}")
|
|
150
|
+
elif current_value is None:
|
|
151
|
+
setattr(self, field_name, default_if_supported)
|
|
152
|
+
return self
|
|
153
|
+
|
|
154
|
+
return gated_field_validator
|
|
155
|
+
|
|
156
|
+
@classmethod
|
|
157
|
+
def _check_field_support(
|
|
158
|
+
cls,
|
|
159
|
+
instance: object,
|
|
160
|
+
unsupported: Sequence[Pattern[str]] | None,
|
|
161
|
+
supported: Sequence[Pattern[str]] | None,
|
|
162
|
+
keys: Sequence[str],
|
|
163
|
+
) -> bool:
|
|
164
|
+
"""Check if a specific field is supported based on its configuration and keys."""
|
|
165
|
+
seen = False
|
|
166
|
+
for key in keys:
|
|
167
|
+
if not hasattr(instance, key):
|
|
168
|
+
continue
|
|
169
|
+
seen = True
|
|
170
|
+
value = str(getattr(instance, key))
|
|
171
|
+
if supported is not None:
|
|
172
|
+
if any(p.search(value) for p in supported):
|
|
173
|
+
return True
|
|
174
|
+
elif unsupported is not None:
|
|
175
|
+
if any(p.search(value) for p in unsupported):
|
|
176
|
+
return False
|
|
177
|
+
return True if not seen else (unsupported is not None)
|
|
178
|
+
|
|
179
|
+
@classmethod
|
|
180
|
+
def _find_blocking_key(
|
|
181
|
+
cls,
|
|
182
|
+
instance: object,
|
|
183
|
+
unsupported: Sequence[Pattern[str]] | None,
|
|
184
|
+
supported: Sequence[Pattern[str]] | None,
|
|
185
|
+
keys: Sequence[str],
|
|
186
|
+
) -> str:
|
|
187
|
+
"""Find which key is blocking the field."""
|
|
188
|
+
for key in keys:
|
|
189
|
+
if not hasattr(instance, key):
|
|
190
|
+
continue
|
|
191
|
+
value = str(getattr(instance, key))
|
|
192
|
+
if supported is not None:
|
|
193
|
+
if not any(p.search(value) for p in supported):
|
|
194
|
+
return key
|
|
195
|
+
elif unsupported is not None:
|
|
196
|
+
if any(p.search(value) for p in unsupported):
|
|
197
|
+
return key
|
|
198
|
+
|
|
199
|
+
return "<unknown>"
|
|
200
|
+
|
|
201
|
+
@classmethod
|
|
202
|
+
def _collect_all_mixin_configs(cls) -> list[GatedFieldMixinConfig]:
|
|
203
|
+
"""Collect all mixin configurations from base classes."""
|
|
204
|
+
all_mixins = []
|
|
205
|
+
for base in cls.__bases__:
|
|
206
|
+
if hasattr(base, "_gated_field_mixins"):
|
|
207
|
+
all_mixins.extend(base._gated_field_mixins)
|
|
208
|
+
return all_mixins
|
|
209
|
+
|
|
210
|
+
@classmethod
|
|
211
|
+
def _create_combined_validator(cls, all_mixins: list[GatedFieldMixinConfig]) -> None:
|
|
212
|
+
"""Create a combined validator that handles all fields."""
|
|
213
|
+
|
|
214
|
+
@model_validator(mode="after")
|
|
215
|
+
def combined_gated_field_validator(self):
|
|
216
|
+
"""Validate all gated fields."""
|
|
217
|
+
for mixin_config in all_mixins:
|
|
218
|
+
field_name_local = mixin_config.field_name
|
|
219
|
+
current_value = getattr(self, field_name_local, None)
|
|
220
|
+
if not self._check_field_support_instance(mixin_config):
|
|
221
|
+
if current_value is not None:
|
|
222
|
+
blocking_key = self._find_blocking_key_instance(mixin_config)
|
|
223
|
+
value = getattr(self, blocking_key, "<unknown>")
|
|
224
|
+
raise ValueError(f"{field_name_local} is not supported for {blocking_key}: {value}")
|
|
225
|
+
elif current_value is None:
|
|
226
|
+
setattr(self, field_name_local, mixin_config.default_if_supported)
|
|
227
|
+
|
|
228
|
+
return self
|
|
229
|
+
|
|
230
|
+
cls._combined_gated_field_validator = combined_gated_field_validator
|
|
231
|
+
|
|
232
|
+
# Add helper methods
|
|
233
|
+
def _check_field_support_instance(self, mixin_config: GatedFieldMixinConfig) -> bool:
|
|
234
|
+
"""Check if a specific field is supported based on its configuration and keys."""
|
|
235
|
+
return cls._check_field_support(self, mixin_config.unsupported, mixin_config.supported, mixin_config.keys)
|
|
236
|
+
|
|
237
|
+
def _find_blocking_key_instance(self, mixin_config: GatedFieldMixinConfig) -> str:
|
|
238
|
+
"""Find which key is blocking the field."""
|
|
239
|
+
return cls._find_blocking_key(self, mixin_config.unsupported, mixin_config.supported, mixin_config.keys)
|
|
240
|
+
|
|
241
|
+
cls._check_field_support_instance = _check_field_support_instance
|
|
242
|
+
cls._find_blocking_key_instance = _find_blocking_key_instance
|
|
@@ -142,7 +142,7 @@ class IntermediateStepPayload(BaseModel):
|
|
|
142
142
|
UUID: str = Field(default_factory=lambda: str(uuid.uuid4()))
|
|
143
143
|
|
|
144
144
|
@property
|
|
145
|
-
def event_category(self) -> IntermediateStepCategory:
|
|
145
|
+
def event_category(self) -> IntermediateStepCategory:
|
|
146
146
|
match self.event_type:
|
|
147
147
|
case IntermediateStepType.LLM_START:
|
|
148
148
|
return IntermediateStepCategory.LLM
|
|
@@ -180,7 +180,7 @@ class IntermediateStepPayload(BaseModel):
|
|
|
180
180
|
raise ValueError(f"Unknown event type: {self.event_type}")
|
|
181
181
|
|
|
182
182
|
@property
|
|
183
|
-
def event_state(self) -> IntermediateStepState:
|
|
183
|
+
def event_state(self) -> IntermediateStepState:
|
|
184
184
|
match self.event_type:
|
|
185
185
|
case IntermediateStepType.LLM_START:
|
|
186
186
|
return IntermediateStepState.START
|
|
@@ -290,7 +290,7 @@ class IntermediateStep(BaseModel):
|
|
|
290
290
|
return self.payload.usage_info
|
|
291
291
|
|
|
292
292
|
@property
|
|
293
|
-
def UUID(self) -> str:
|
|
293
|
+
def UUID(self) -> str:
|
|
294
294
|
return self.payload.UUID
|
|
295
295
|
|
|
296
296
|
@property
|