🔍 Code Extractor

function get_all_model_classes

Maturity: 41

Retrieves a copy of the internal model registry containing all registered model classes mapped by their names.

File:
/tf/active/vicechatdev/CDocs/models/__init__.py
Lines:
98 - 105
Complexity:
simple

Purpose

This function provides read-only access to the global model registry (_model_registry) that stores all BaseModel subclasses registered in the CDocs system. It returns a shallow copy to prevent external modification of the internal registry while allowing inspection of all available model classes. This is useful for dynamic model discovery, introspection, validation, and plugin systems that need to enumerate available models.

Source Code

def get_all_model_classes() -> Dict[str, Type[BaseModel]]:
    """
    Get all registered model classes.
    
    Returns:
        Dictionary of model name to model class
    """
    return _model_registry.copy()

Return Value

Type: Dict[str, Type[BaseModel]]

Returns a dictionary where keys are string model names and values are Type[BaseModel] class objects. The dictionary is a shallow copy of the internal registry, containing all model classes that have been registered in the system (e.g., 'DocUser', 'ControlledDocument', 'DocumentVersion', 'ReviewCycle', 'ReviewComment', 'ApprovalCycle'). Returns an empty dictionary if no models are registered.

Required Imports

from typing import Dict, Type
from CDocs.models.user_extensions import DocUser
from CDocs.models.document import ControlledDocument, DocumentVersion
from CDocs.models.review import ReviewCycle, ReviewComment
from CDocs.models.approval import ApprovalCycle

Usage Example

# Get all registered model classes
all_models = get_all_model_classes()

# Iterate through registered models
for model_name, model_class in all_models.items():
    print(f"Model: {model_name}, Class: {model_class.__name__}")

# Check if a specific model is registered
if 'ControlledDocument' in all_models:
    doc_class = all_models['ControlledDocument']
    # Instantiate the model
    doc = doc_class()

# Get count of registered models
model_count = len(all_models)
print(f"Total registered models: {model_count}")

Best Practices

  • This function returns a copy of the registry, so modifications to the returned dictionary will not affect the internal registry
  • Use this function for read-only operations like model discovery and validation
  • Do not cache the result if models may be registered dynamically at runtime; call the function each time you need current registry state
  • The returned dictionary contains class types, not instances; use the classes to instantiate models as needed
  • Ensure all required models are registered before calling this function if you expect specific models to be present

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function get_model_class 70.0% similar

    Retrieves a model class from a registry by its string name, returning the class type or None if not found.

    From: /tf/active/vicechatdev/CDocs/models/__init__.py
  • function register_model 67.8% similar

    Registers a model class in a global registry dictionary, enabling dynamic model lookup and management. Can be used as a decorator or called directly.

    From: /tf/active/vicechatdev/CDocs/models/__init__.py
  • class BaseModel 56.3% similar

    Base class providing common data model functionality for all models in the system, including property management, serialization, and deserialization.

    From: /tf/active/vicechatdev/CDocs/models/__init__.py
  • function api_get_models 45.9% similar

    Flask API endpoint that returns a list of available LLM models and the default model configuration.

    From: /tf/active/vicechatdev/docchat/app.py
  • function get_available_models 45.8% similar

    Flask API endpoint that returns a JSON response containing the list of available LLM models and the default model configured in the application.

    From: /tf/active/vicechatdev/docchat/blueprint.py
← Back to Browse