model_registry
model_registry ¶
clear_registry ¶
Clear the model registry, optionally only for a specific namespace.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
namespace
|
Optional[str]
|
If provided, only clear this namespace. Otherwise, clear all. |
None
|
Source code in src/results_manager/model_registry.py
find_model_in_all_namespaces ¶
Find a model by name in all namespaces.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_name
|
str
|
The name of the model class |
required |
Returns:
Type | Description |
---|---|
List[Tuple[str, Type[BaseModel]]]
|
List of (namespace, model_class) tuples for all matches |
Source code in src/results_manager/model_registry.py
find_model_namespace ¶
Find the namespace for a model class.
If the model is registered in multiple namespaces, behavior depends on the 'strict' parameter: - If strict=False (default): Prioritizes non-default namespaces, returns the first one found - If strict=True: Raises ValueError if found in multiple non-default namespaces
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_class
|
Type[BaseModel]
|
The model class to find the namespace for |
required |
strict
|
bool
|
Whether to raise an error if the model is in multiple non-default namespaces |
False
|
Returns:
Type | Description |
---|---|
Optional[str]
|
The namespace name if found, None otherwise |
Raises:
Type | Description |
---|---|
ValueError
|
If strict=True and the model is registered in multiple non-default namespaces |
Source code in src/results_manager/model_registry.py
get_model_class ¶
Retrieve a model class from the registry by name and namespace.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_name
|
str
|
The name of the model class |
required |
namespace
|
str
|
The namespace to look in |
DEFAULT_NAMESPACE
|
Returns:
Type | Description |
---|---|
Optional[Type[BaseModel]]
|
The model class if found, None otherwise |
Source code in src/results_manager/model_registry.py
get_models_in_namespace ¶
get_namespaces ¶
register_model ¶
Register a pydantic model class in the registry.
Can be used as a decorator with or without arguments:
@register_model class MyModel(BaseModel): ...
@register_model(namespace="custom") class MyModel(BaseModel): ...
Or programmatically: register_model(MyModel, namespace="custom")
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_class_or_namespace
|
Any
|
The model class to register or a namespace string |
None
|
namespace
|
str
|
The namespace to register the model in (when used programmatically) |
DEFAULT_NAMESPACE
|
Returns:
Type | Description |
---|---|
The decorator function or the registered model class |