diff --git a/litellm/__init__.py b/litellm/__init__.py index 8e5dd68a186..8a73f3447b8 100644 --- a/litellm/__init__.py +++ b/litellm/__init__.py @@ -81,7 +81,6 @@ from litellm.constants import ( import httpx from openai import DefaultAsyncHttpxClient, DefaultHttpxClient -# register_async_client_cleanup is lazy-loaded and called on first access litellm_mode = os.getenv("LITELLM_MODE", "DEV") # "PRODUCTION", "DEV" @@ -98,7 +97,6 @@ failure_callback: List[CALLBACK_TYPES] = [] service_callback: List[CALLBACK_TYPES] = [] audit_log_callbacks: List[CALLBACK_TYPES] = [] batch_line_item_callbacks: Sequence[CALLBACK_TYPES] = () -# logging_callback_manager is lazy-loaded via __getattr__ _custom_logger_compatible_callbacks_literal = Literal[ "lago", "openmeter", @@ -507,8 +505,6 @@ skill_search_embedding_model: Optional[str] = None public_model_groups_links: dict[str, str | dict[str, object]] = {} #### REQUEST PRIORITIZATION ####### priority_reservation: Optional[Dict[str, Union[float, "PriorityReservationDict"]]] = None -# priority_reservation_settings is lazy-loaded via __getattr__ -# Only declare for type checking - at runtime __getattr__ handles it if TYPE_CHECKING: priority_reservation_settings: Optional["PriorityReservationSettings"] = None @@ -543,8 +539,6 @@ _google_kms_resource_name: Optional[str] = None _key_management_system: Optional["KeyManagementSystem"] = None # Note: KeyManagementSettings must be eagerly imported because _key_management_settings # is accessed during import time in secret_managers/main.py -# We'll import it after the lazy import system is set up -# We can't define it here because KeyManagementSettings is lazy-loaded #### PII MASKING #### output_parse_pii: bool = False ############################################# @@ -1196,8 +1190,6 @@ model_list = list( model_list_set = set(model_list) -# provider_list is lazy-loaded via __getattr__ to avoid importing LlmProviders at import time - def _build_models_by_provider() -> dict: return { @@ -1378,10 +1370,6 @@ all_embedding_models = ( ####### VIDEO GENERATION MODELS ################### openai_video_generation_models = ["sora-2"] -# timeout is lazy-loaded via __getattr__ -# get_llm_provider is lazy-loaded via __getattr__ -# remove_index_from_tool_calls is lazy-loaded via __getattr__ - # Import KeyManagementSettings here (before utils import) because _key_management_settings # is accessed during import time in secret_managers/main.py (via dd_tracing -> datadog -> _service_logger -> utils) from litellm.types.secret_managers.main import KeyManagementSettings @@ -1391,8 +1379,6 @@ _key_management_settings: KeyManagementSettings = KeyManagementSettings() # client must be imported immediately as it's used as a decorator at function definition time from .utils import client -# Note: Most other utils imports are lazy-loaded via __getattr__ to avoid loading utils.py -# (which imports tiktoken) at import time from .llms.custom_llm import CustomLLM from .llms.anthropic.common_utils import AnthropicModelInfo @@ -1416,12 +1402,9 @@ from .llms.bedrock.embed.amazon_titan_v2_transformation import ( ) from .llms.topaz.common_utils import TopazModelInfo -# OpenAIOSeriesConfig is lazy loaded - openaiOSeriesConfig will be created on first access -# OpenAIGPTConfig, OpenAIGPT5Config, etc. are lazy loaded - instances will be created on first access from .llms.xai.common_utils import XAIModelInfo # PublicAI now uses JSON-based configuration (see litellm/llms/openai_like/providers.json) -# All remaining configs are now lazy loaded - see _lazy_imports_registry.py # Import LlmProviders here (before main import) because it's imported during import time # in multiple places including openai.py (via main import) @@ -1650,8 +1633,6 @@ def set_global_gitlab_config(config: Mapping[str, object]) -> None: global_gitlab_config = config -# Lazy loading system for heavy modules to reduce initial import time and memory usage - if TYPE_CHECKING: from . import guardrails as guardrails from litellm.types.utils import ModelInfo as _ModelInfoType @@ -1659,7 +1640,6 @@ if TYPE_CHECKING: from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler, HTTPHandler from litellm.caching.caching import Cache - # Type stubs for lazy-loaded configs to help mypy from .llms.bedrock.chat.converse_transformation import ( AmazonConverseConfig as AmazonConverseConfig, ) @@ -2088,7 +2068,6 @@ if TYPE_CHECKING: ) from .llms.gdc.chat.transformation import GDCGeminiConfig as GDCGeminiConfig - # Type stubs for lazy-loaded config instances openaiOSeriesConfig: OpenAIOSeriesConfig openAIGPTConfig: OpenAIGPTConfig openAIGPTAudioConfig: OpenAIGPTAudioConfig @@ -2146,7 +2125,6 @@ if TYPE_CHECKING: VertexGeminiConfig as _VertexGeminiConfig, ) - # Type stubs for lazy-loaded config classes (to help mypy understand types) VLLMConfig: Type[_VLLMConfig] DeepSeekChatConfig: Type[_DeepSeekChatConfig] TencentChatConfig: Type[_TencentChatConfig] @@ -2423,63 +2401,34 @@ if TYPE_CHECKING: module_level_aclient: AsyncHTTPHandler module_level_client: HTTPHandler - # Bedrock tool name mappings instance (lazy-loaded) from litellm.caching.caching import InMemoryCache bedrock_tool_name_mappings: InMemoryCache - # Azure exception class (lazy-loaded) from litellm.llms.azure.common_utils import AzureOpenAIError - # Secret manager types (lazy-loaded) from litellm.types.secret_managers.main import ( KeyManagementSystem, KeyManagementSettings, # Not lazy-loaded - needed for _key_management_settings initialization ) - # Custom logger class (lazy-loaded) from litellm.integrations.custom_logger import CustomLogger - # Datadog LLM observability params (lazy-loaded) from litellm.types.integrations.datadog_llm_obs import DatadogLLMObsInitParams - # Logging callback manager class and instance (lazy-loaded) from litellm.litellm_core_utils.logging_callback_manager import ( LoggingCallbackManager, ) logging_callback_manager: LoggingCallbackManager - # provider_list is lazy-loaded from litellm.types.utils import LlmProviders provider_list: List[Union[LlmProviders, str]] - # Note: AmazonConverseConfig and OpenAILikeChatConfig are imported above in TYPE_CHECKING block - -# Track if async client cleanup has been registered (for lazy loading) _async_client_cleanup_registered = False -_AGENT_EXPORTS: Final = frozenset( - { - "agent", - "aagent", - "agent_session", - "aagent_session", - "agent_resume", - "aagent_resume", - "agent_capabilities", - "Harness", - "ClaudeCodeOptions", - "CodexOptions", - "OpenCodeOptions", - "PiOptions", - "DeepAgentsOptions", - "ToolLoopOptions", - } -) - # Eager loading for backwards compatibility with VCR and other HTTP recording tools # When LITELLM_DISABLE_LAZY_LOADING is set, lazy-loaded attributes are loaded at import time # For now, this only affects encoding (tiktoken) as it was the only reported issue @@ -2492,9 +2441,7 @@ if os.getenv("LITELLM_DISABLE_LAZY_LOADING", "").lower() in ("1", "true", "yes", def __getattr__(name: str) -> Any: - """Lazy import handler with cached registry for improved performance.""" global _async_client_cleanup_registered - # Register async client cleanup on first access (only once) if not _async_client_cleanup_registered: from litellm.llms.custom_httpx.async_client_cleanup import ( register_async_client_cleanup, @@ -2503,205 +2450,9 @@ def __getattr__(name: str) -> Any: register_async_client_cleanup() _async_client_cleanup_registered = True - # Use cached registry from _lazy_imports instead of importing tuples every time - from ._lazy_imports import get_lazy_import_registry + from ._lazy_imports import resolve_lazy_attribute - registry: Final = get_lazy_import_registry() + return resolve_lazy_attribute(__name__, name) - # Check if name is in registry and call the cached handler function - if name in registry: - handler_func: Final = registry[name] - return handler_func(name) - - if name in ("proxy", "guardrails"): - import importlib - - return importlib.import_module(f"litellm.{name}") - - if name == "harness" or name in _AGENT_EXPORTS: - import importlib - - harness_module = importlib.import_module("litellm.harness") - return harness_module if name == "harness" else getattr(harness_module, name) - - # Lazy load encoding from main.py to avoid heavy tiktoken import - if name == "encoding": - from ._lazy_imports import get_litellm_globals - - _globals = get_litellm_globals() - # Check if already cached - if "encoding" not in _globals: - from .main import encoding as _encoding - - _globals["encoding"] = _encoding - return _globals["encoding"] - - # Lazy load bedrock_tool_name_mappings instance - if name == "bedrock_tool_name_mappings": - from ._lazy_imports import get_litellm_globals - - _globals = get_litellm_globals() - # Check if already cached - if "bedrock_tool_name_mappings" not in _globals: - from .llms.bedrock.chat.invoke_handler import ( - bedrock_tool_name_mappings as _bedrock_tool_name_mappings, - ) - - _globals["bedrock_tool_name_mappings"] = _bedrock_tool_name_mappings - return _globals["bedrock_tool_name_mappings"] - - # Lazy load AzureOpenAIError exception class - if name == "AzureOpenAIError": - from ._lazy_imports import get_litellm_globals - - _globals = get_litellm_globals() - # Check if already cached - if "AzureOpenAIError" not in _globals: - from .llms.azure.common_utils import AzureOpenAIError as _AzureOpenAIError - - _globals["AzureOpenAIError"] = _AzureOpenAIError - return _globals["AzureOpenAIError"] - - # Lazy load openaiOSeriesConfig instance - if name == "openaiOSeriesConfig": - from ._lazy_imports import get_litellm_globals - - _globals = get_litellm_globals() - if "openaiOSeriesConfig" not in _globals: - # Import the config class and instantiate it - config_class = __getattr__("OpenAIOSeriesConfig") - _globals["openaiOSeriesConfig"] = config_class() - return _globals["openaiOSeriesConfig"] - - # Lazy load other config instances - _config_instances: Final = { - "openAIGPTConfig": "OpenAIGPTConfig", - "openAIGPTAudioConfig": "OpenAIGPTAudioConfig", - "openAIGPT5Config": "OpenAIGPT5Config", - "nvidiaNimConfig": "NvidiaNimConfig", - "nvidiaNimEmbeddingConfig": "NvidiaNimEmbeddingConfig", - } - if name in _config_instances: - from ._lazy_imports import get_litellm_globals - - _globals = get_litellm_globals() - if name not in _globals: - # Import the config class and instantiate it - config_class = __getattr__(_config_instances[name]) - _globals[name] = config_class() - return _globals[name] - - # Handle OpenAIO1Config alias - if name == "OpenAIO1Config": - return __getattr__("OpenAIOSeriesConfig") - - # Lazy load provider_list - if name == "provider_list": - from ._lazy_imports import get_litellm_globals - - _globals = get_litellm_globals() - # Check if already cached - if "provider_list" not in _globals: - # LlmProviders is eagerly imported above, so we can import it directly - from litellm.types.utils import LlmProviders - - _globals["provider_list"] = list(LlmProviders) - return _globals["provider_list"] - - # Lazy load priority_reservation_settings instance - if name == "priority_reservation_settings": - from ._lazy_imports import get_litellm_globals - - _globals = get_litellm_globals() - # Check if already cached - if "priority_reservation_settings" not in _globals: - # Import the class and instantiate it - PriorityReservationSettings: Final = __getattr__("PriorityReservationSettings") - _globals["priority_reservation_settings"] = PriorityReservationSettings() - return _globals["priority_reservation_settings"] - - # Lazy load logging_callback_manager instance - if name == "logging_callback_manager": - from ._lazy_imports import get_litellm_globals - - _globals = get_litellm_globals() - # Check if already cached - if "logging_callback_manager" not in _globals: - # Import the class and instantiate it - LoggingCallbackManager: Final = __getattr__("LoggingCallbackManager") - _globals["logging_callback_manager"] = LoggingCallbackManager() - return _globals["logging_callback_manager"] - - # Lazy load _service_logger module - if name == "_service_logger": - from ._lazy_imports import get_litellm_globals - - _globals = get_litellm_globals() - # Check if already cached - if "_service_logger" not in _globals: - # Import the module lazily - import litellm._service_logger - - _globals["_service_logger"] = litellm._service_logger - return _globals["_service_logger"] - - # Lazy load evals module functions - if name in [ - "acreate_eval", - "alist_evals", - "aget_eval", - "aupdate_eval", - "adelete_eval", - "acancel_eval", - "create_eval", - "list_evals", - "get_eval", - "update_eval", - "delete_eval", - "cancel_eval", - "acreate_run", - "alist_runs", - "aget_run", - "acancel_run", - "adelete_run", - "create_run", - "list_runs", - "get_run", - "cancel_run", - "delete_run", - ]: - from litellm.evals.main import ( - acreate_eval, - alist_evals, - aget_eval, - aupdate_eval, - adelete_eval, - acancel_eval, - create_eval, - list_evals, - get_eval, - update_eval, - delete_eval, - cancel_eval, - acreate_run, - alist_runs, - aget_run, - acancel_run, - adelete_run, - create_run, - list_runs, - get_run, - cancel_run, - delete_run, - ) - from types import MappingProxyType - - evals_exports: Final[Mapping[str, object]] = MappingProxyType(locals()) - return evals_exports[name] - - raise AttributeError(f"module {__name__!r} has no attribute {name!r}") - - -# ALL_LITELLM_RESPONSE_TYPES is lazy-loaded via __getattr__ to avoid loading utils at import time mark_litellm_import_complete() diff --git a/litellm/_lazy_imports.py b/litellm/_lazy_imports.py index 1a7dc343745..1ea4bb52668 100644 --- a/litellm/_lazy_imports.py +++ b/litellm/_lazy_imports.py @@ -1,60 +1,14 @@ -""" -Lazy Import System - -This module implements lazy loading for LiteLLM attributes. Instead of importing -everything when the module loads, we only import things when they're actually used. - -How it works: -1. When someone accesses `litellm.some_attribute`, Python calls __getattr__ in __init__.py -2. __getattr__ looks up the attribute name in a registry -3. The registry points to a handler function (like _lazy_import_utils) -4. The handler function imports the module and returns the attribute -5. The result is cached so we don't import it again - -This makes importing litellm much faster because we don't load heavy dependencies -until they're actually needed. -""" +"""Resolve the attributes of `litellm` and `litellm.utils` that are imported on first access.""" import importlib import sys from collections.abc import Callable, Mapping -from types import ModuleType -from typing import TYPE_CHECKING, Any, Final +from types import MappingProxyType, ModuleType +from typing import TYPE_CHECKING, Final from typing_extensions import ReadOnly, TypedDict -# Import all the data structures that define what can be lazy-loaded -# These are just lists of names and maps of where to find them -from ._lazy_imports_registry import ( - # Import maps - _BEDROCK_TYPES_IMPORT_MAP, - _CACHING_IMPORT_MAP, - _COST_CALCULATOR_IMPORT_MAP, - _DOTPROMPT_IMPORT_MAP, - _LITELLM_LOGGING_IMPORT_MAP, - _LLM_CONFIGS_IMPORT_MAP, - _LLM_PROVIDER_LOGIC_IMPORT_MAP, - _TOKEN_COUNTER_IMPORT_MAP, - _TYPES_IMPORT_MAP, - _TYPES_UTILS_IMPORT_MAP, - _UTILS_IMPORT_MAP, - _UTILS_MODULE_IMPORT_MAP, - # Name tuples - BEDROCK_TYPES_NAMES, - CACHING_NAMES, - COST_CALCULATOR_NAMES, - DOTPROMPT_NAMES, - HTTP_HANDLER_NAMES, - LITELLM_LOGGING_NAMES, - LLM_CLIENT_CACHE_NAMES, - LLM_CONFIG_NAMES, - LLM_PROVIDER_LOGIC_NAMES, - TOKEN_COUNTER_NAMES, - TYPES_NAMES, - TYPES_UTILS_NAMES, - UTILS_MODULE_NAMES, - UTILS_NAMES, -) +from ._lazy_imports_registry import LITELLM_ATTRIBUTES, UTILS_ATTRIBUTES if TYPE_CHECKING: import httpx @@ -62,35 +16,6 @@ if TYPE_CHECKING: from litellm.litellm_core_utils.tokenizer import Encoding as Tokenizer -def get_litellm_globals() -> dict[str, object]: - """ - Get the globals dictionary of the litellm module. - - This is where we cache imported attributes so we don't import them twice. - When you do `litellm.some_function`, it gets stored in this dictionary. - """ - return sys.modules["litellm"].__dict__ - - -def _get_utils_globals() -> dict[str, object]: - """ - Get the globals dictionary of the utils module. - - This is where we cache imported attributes so we don't import them twice. - When you do `litellm.utils.some_function`, it gets stored in this dictionary. - """ - return sys.modules["litellm.utils"].__dict__ - - -def _get_module_level_client_timeout(litellm_globals: Mapping[str, Any]) -> "float | httpx.Timeout | None": - """Read the configured `litellm.request_timeout` used for the module level http clients.""" - return litellm_globals.get("request_timeout") - - -# These are special lazy loaders for things that are used internally -# They're separate from the main lazy import system because they have specific use cases - - def get_default_encoding() -> "Tokenizer": from litellm.rust_bridge.tokenizer import get_encoding @@ -100,138 +25,43 @@ def get_default_encoding() -> "Tokenizer": _get_default_encoding = get_default_encoding -# Lazy loader for get_modified_max_tokens to avoid importing token_counter at module import time -_get_modified_max_tokens_func: "Callable[..., int | None] | None" = None - - def _get_modified_max_tokens() -> "Callable[..., int | None]": - """ - Lazily load and cache the get_modified_max_tokens function. + from litellm.litellm_core_utils.token_counter import get_modified_max_tokens - This avoids importing `litellm.litellm_core_utils.token_counter` at `litellm` import time. - The function is cached after the first import. - - This is used internally by utils.py functions that need the token counter but shouldn't - trigger its import during module load. - """ - global _get_modified_max_tokens_func - if _get_modified_max_tokens_func is None: - from litellm.litellm_core_utils.token_counter import ( - get_modified_max_tokens as _get_modified_max_tokens_imported, - ) - - _get_modified_max_tokens_func = _get_modified_max_tokens_imported - return _get_modified_max_tokens_func - - -# Lazy loader for token_counter to avoid importing token_counter module at module import time -_token_counter_new_func: "Callable[..., int] | None" = None -_messages_reach_token_count_func: "Callable[..., bool] | None" = None + return get_modified_max_tokens def get_token_counter_new() -> "Callable[..., int]": - """ - Lazily load and cache the token_counter function (aliased as token_counter_new). + from litellm.litellm_core_utils.token_counter import token_counter - This avoids importing `litellm.litellm_core_utils.token_counter` at `litellm` import time. - The function is cached after the first import. - - This is used internally by utils.py functions that need the token counter but shouldn't - trigger its import during module load. - """ - global _token_counter_new_func - if _token_counter_new_func is None: - from litellm.litellm_core_utils.token_counter import ( - token_counter as _token_counter_imported, - ) - - _token_counter_new_func = _token_counter_imported - return _token_counter_new_func + return token_counter _get_token_counter_new = get_token_counter_new def get_messages_reach_token_count() -> "Callable[..., bool]": - """Lazily load ``messages_reach_token_count`` for the same reason as ``get_token_counter_new``.""" - global _messages_reach_token_count_func - if _messages_reach_token_count_func is None: - from litellm.litellm_core_utils.token_counter import ( - messages_reach_token_count as _messages_reach_token_count_imported, - ) + from litellm.litellm_core_utils.token_counter import messages_reach_token_count - _messages_reach_token_count_func = _messages_reach_token_count_imported - return _messages_reach_token_count_func + return messages_reach_token_count _get_messages_reach_token_count = get_messages_reach_token_count -# ============================================================================ -# MAIN LAZY IMPORT SYSTEM -# ============================================================================ - -# This registry maps attribute names (like "ModelResponse") to handler functions -# It's built once the first time someone accesses a lazy-loaded attribute -# Example: {"ModelResponse": _lazy_import_utils, "Cache": _lazy_import_caching, ...} -_LAZY_IMPORT_REGISTRY: dict[str, Callable[[str], object]] | None = None +_NOT_LOADED: Final = object() -def get_lazy_import_registry() -> dict[str, Callable[[str], object]]: - """ - Build the registry that maps attribute names to their handler functions. - - This is called once, the first time someone accesses a lazy-loaded attribute. - After that, we just look up the handler function in this dictionary. - - Returns: - Dictionary like {"ModelResponse": _lazy_import_utils, ...} - """ - global _LAZY_IMPORT_REGISTRY - if _LAZY_IMPORT_REGISTRY is None: - # Build the registry by going through each category and mapping - # all the names in that category to their handler function - _LAZY_IMPORT_REGISTRY = {} - # For each category, map all its names to the handler function - # Example: All names in UTILS_NAMES get mapped to _lazy_import_utils - for name in COST_CALCULATOR_NAMES: - _LAZY_IMPORT_REGISTRY[name] = _lazy_import_cost_calculator - for name in LITELLM_LOGGING_NAMES: - _LAZY_IMPORT_REGISTRY[name] = _lazy_import_litellm_logging - for name in UTILS_NAMES: - _LAZY_IMPORT_REGISTRY[name] = _lazy_import_utils - for name in TOKEN_COUNTER_NAMES: - _LAZY_IMPORT_REGISTRY[name] = _lazy_import_token_counter - for name in LLM_CLIENT_CACHE_NAMES: - _LAZY_IMPORT_REGISTRY[name] = _lazy_import_llm_client_cache - for name in BEDROCK_TYPES_NAMES: - _LAZY_IMPORT_REGISTRY[name] = _lazy_import_bedrock_types - for name in TYPES_UTILS_NAMES: - _LAZY_IMPORT_REGISTRY[name] = _lazy_import_types_utils - for name in CACHING_NAMES: - _LAZY_IMPORT_REGISTRY[name] = _lazy_import_caching - for name in HTTP_HANDLER_NAMES: - _LAZY_IMPORT_REGISTRY[name] = _lazy_import_http_handlers - for name in DOTPROMPT_NAMES: - _LAZY_IMPORT_REGISTRY[name] = _lazy_import_dotprompt - for name in LLM_CONFIG_NAMES: - _LAZY_IMPORT_REGISTRY[name] = _lazy_import_llm_configs - for name in TYPES_NAMES: - _LAZY_IMPORT_REGISTRY[name] = _lazy_import_types - for name in LLM_PROVIDER_LOGIC_NAMES: - _LAZY_IMPORT_REGISTRY[name] = _lazy_import_llm_provider_logic - for name in UTILS_MODULE_NAMES: - _LAZY_IMPORT_REGISTRY[name] = _lazy_import_utils_module - - return _LAZY_IMPORT_REGISTRY +def _cached(namespace: str, name: str) -> object: + return vars(sys.modules[namespace]).get(name, _NOT_LOADED) -_get_lazy_import_registry = get_lazy_import_registry +def _cache(namespace: str, name: str, value: object) -> object: + setattr(sys.modules[namespace], name, value) + return value class _AttributeView(TypedDict): - """Holds one module attribute so the lazily fetched value is read back as ``object``.""" - value: ReadOnly[object] @@ -240,241 +70,88 @@ def _module_attribute(module: ModuleType, attr_name: str) -> object: return attribute["value"] -def _generic_lazy_import(name: str, import_map: Mapping[str, tuple[str, str]], category: str) -> object: - """ - Generic function that handles lazy importing for most attributes. +def _import(namespace: str, name: str, location: tuple[str, str]) -> object: + cached: Final = _cached(namespace, name) + if cached is not _NOT_LOADED: + return cached + module_path, attr_name = location + module: Final[ModuleType] = importlib.import_module(module_path, package="litellm") + return _cache(namespace, name, _module_attribute(module, attr_name)) - This is the workhorse function - it does the actual importing and caching. - Most handler functions just call this with their specific import map. - Steps: - 1. Check if the name exists in the import map (if not, raise error) - 2. Check if we've already imported it (if yes, return cached value) - 3. Look up where to find it (module_path and attr_name from the map) - 4. Import the module (Python caches this automatically) - 5. Get the attribute from the module - 6. Cache it in _globals so we don't import again - 7. Return it +def _instance_of(class_name: str) -> Callable[[], object]: + def create() -> object: + cls: Final = resolve_lazy_attribute("litellm", class_name) + assert isinstance(cls, type) + return cls() - Args: - name: The attribute name someone is trying to access (e.g., "ModelResponse") - import_map: Dictionary telling us where to find each attribute - Format: {"ModelResponse": (".utils", "ModelResponse")} - category: Just for error messages (e.g., "Utils", "Cost calculator") - """ - # Step 1: Make sure this attribute exists in our map - if name not in import_map: - raise AttributeError(f"{category} lazy import: unknown attribute {name!r}") + return create - # Step 2: Get the cache (where we store imported things) - _globals: Final = get_litellm_globals() - # Step 3: If we've already imported it, just return the cached version - if name in _globals: - return _globals[name] +def _submodule(module_path: str) -> Callable[[], object]: + return lambda: importlib.import_module(module_path) - # Step 4: Look up where to find this attribute - # The map tells us: (module_path, attribute_name) - # Example: (".utils", "ModelResponse") means "look in .utils module, get ModelResponse" - module_path, attr_name = import_map[name] - # Step 5: Import the module - # Python automatically caches modules in sys.modules, so calling this twice is fast - # If module_path starts with ".", it's a relative import (needs package="litellm") - # Otherwise it's an absolute import (like "litellm.caching.caching") - if module_path.startswith("."): - module = importlib.import_module(module_path, package="litellm") - else: - module = importlib.import_module(module_path) +def _request_timeout() -> "float | httpx.Timeout | None": + import httpx - # Step 6: Get the actual attribute from the module - # Example: getattr(utils_module, "ModelResponse") returns the ModelResponse class - value: Final = _module_attribute(module, attr_name) + timeout: Final = _cached("litellm", "request_timeout") + return timeout if isinstance(timeout, (int, float, httpx.Timeout)) else None - # Step 7: Cache it so we don't have to import again next time - _globals[name] = value - # Step 8: Return it - return value +def _module_level_aclient() -> object: + from litellm.llms.custom_httpx.http_handler import get_async_httpx_client + return get_async_httpx_client( + llm_provider="litellm_module_level_client", + params={"timeout": _request_timeout(), "client_alias": "module level aclient"}, + ) -# ============================================================================ -# HANDLER FUNCTIONS -# ============================================================================ -# These functions are called when someone accesses a lazy-loaded attribute. -# Most of them just call _generic_lazy_import with their specific import map. -# The registry (above) maps attribute names to these handler functions. +def _module_level_client() -> object: + from litellm.llms.custom_httpx.http_handler import HTTPHandler -def _lazy_import_utils(name: str) -> object: - """Handler for utils module attributes (ModelResponse, token_counter, etc.)""" - return _generic_lazy_import(name, _UTILS_IMPORT_MAP, "Utils") + return HTTPHandler(timeout=_request_timeout()) -def _lazy_import_cost_calculator(name: str) -> object: - """Handler for cost calculator functions (completion_cost, cost_per_token, etc.)""" - return _generic_lazy_import(name, _COST_CALCULATOR_IMPORT_MAP, "Cost calculator") +def _provider_list() -> object: + from litellm.types.utils import LlmProviders + return list(LlmProviders) -def _lazy_import_token_counter(name: str) -> object: - """Handler for token counter utilities""" - return _generic_lazy_import(name, _TOKEN_COUNTER_IMPORT_MAP, "Token counter") +_LITELLM_FACTORIES: Final[Mapping[str, Callable[[], object]]] = MappingProxyType( + { + "in_memory_llm_clients_cache": _instance_of("LLMClientCache"), + "module_level_aclient": _module_level_aclient, + "module_level_client": _module_level_client, + "openaiOSeriesConfig": _instance_of("OpenAIOSeriesConfig"), + "openAIGPTConfig": _instance_of("OpenAIGPTConfig"), + "openAIGPTAudioConfig": _instance_of("OpenAIGPTAudioConfig"), + "openAIGPT5Config": _instance_of("OpenAIGPT5Config"), + "nvidiaNimConfig": _instance_of("NvidiaNimConfig"), + "nvidiaNimEmbeddingConfig": _instance_of("NvidiaNimEmbeddingConfig"), + "priority_reservation_settings": _instance_of("PriorityReservationSettings"), + "logging_callback_manager": _instance_of("LoggingCallbackManager"), + "provider_list": _provider_list, + "proxy": _submodule("litellm.proxy"), + "guardrails": _submodule("litellm.guardrails"), + "harness": _submodule("litellm.harness"), + "_service_logger": _submodule("litellm._service_logger"), + } +) -def _lazy_import_bedrock_types(name: str) -> object: - """Handler for Bedrock type aliases""" - return _generic_lazy_import(name, _BEDROCK_TYPES_IMPORT_MAP, "Bedrock types") - -def _lazy_import_types_utils(name: str) -> object: - """Handler for types from litellm.types.utils (BudgetConfig, ImageObject, etc.)""" - return _generic_lazy_import(name, _TYPES_UTILS_IMPORT_MAP, "Types utils") - - -def _lazy_import_caching(name: str) -> object: - """Handler for caching classes (Cache, DualCache, RedisCache, etc.)""" - return _generic_lazy_import(name, _CACHING_IMPORT_MAP, "Caching") - - -def _lazy_import_dotprompt(name: str) -> object: - """Handler for dotprompt integration globals""" - return _generic_lazy_import(name, _DOTPROMPT_IMPORT_MAP, "Dotprompt") - - -def _lazy_import_types(name: str) -> object: - """Handler for type classes (GuardrailItem, etc.)""" - return _generic_lazy_import(name, _TYPES_IMPORT_MAP, "Types") - - -def _lazy_import_llm_configs(name: str) -> object: - """Handler for LLM config classes (AnthropicConfig, OpenAILikeChatConfig, etc.)""" - return _generic_lazy_import(name, _LLM_CONFIGS_IMPORT_MAP, "LLM config") - - -def _lazy_import_litellm_logging(name: str) -> object: - """Handler for litellm_logging module (Logging, modify_integration)""" - return _generic_lazy_import(name, _LITELLM_LOGGING_IMPORT_MAP, "Litellm logging") - - -def _lazy_import_llm_provider_logic(name: str) -> object: - """Handler for LLM provider logic functions (get_llm_provider, etc.)""" - return _generic_lazy_import(name, _LLM_PROVIDER_LOGIC_IMPORT_MAP, "LLM provider logic") - - -def _lazy_import_utils_module(name: str) -> object: - """ - Handler for utils module lazy imports. - - This uses a custom implementation because utils module needs to use - _get_utils_globals() instead of get_litellm_globals() for caching. - """ - # Check if this attribute exists in our map - if name not in _UTILS_MODULE_IMPORT_MAP: - raise AttributeError(f"Utils module lazy import: unknown attribute {name!r}") - - # Get the cache (where we store imported things) - use utils globals - _globals: Final = _get_utils_globals() - - # If we've already imported it, just return the cached version - if name in _globals: - return _globals[name] - - # Look up where to find this attribute - module_path, attr_name = _UTILS_MODULE_IMPORT_MAP[name] - - # Import the module - if module_path.startswith("."): - module = importlib.import_module(module_path, package="litellm") - else: - module = importlib.import_module(module_path) - - # Get the actual attribute from the module - value: Final = _module_attribute(module, attr_name) - - # Cache it so we don't have to import again next time - _globals[name] = value - - # Return it - return value - - -# ============================================================================ -# SPECIAL HANDLERS -# ============================================================================ -# These handlers have custom logic that doesn't fit the generic pattern - - -def _lazy_import_llm_client_cache(name: str) -> object: - """ - Handler for LLM client cache - has special logic for singleton instance. - - This one is different because: - - "LLMClientCache" is the class itself - - "in_memory_llm_clients_cache" is a singleton instance of that class - So we need custom logic to handle both cases. - """ - _globals: Final = get_litellm_globals() - - # If already cached, return it - if name in _globals: - return _globals[name] - - # Import the class - from litellm.caching.llm_caching_handler import LLMClientCache - - # If they want the class itself, return it - if name == "LLMClientCache": - _globals["LLMClientCache"] = LLMClientCache - return LLMClientCache - - # If they want the singleton instance, create it (only once) - if name == "in_memory_llm_clients_cache": - instance: Final = LLMClientCache() - _globals["in_memory_llm_clients_cache"] = instance - return instance - - raise AttributeError(f"LLM client cache lazy import: unknown attribute {name!r}") - - -def _lazy_import_http_handlers(name: str) -> object: - """ - Handler for HTTP clients - has special logic for creating client instances. - - This one is different because: - - These aren't just imports, they're actual client instances that need to be created - - They need configuration (timeout, etc.) from the module globals - - They use factory functions instead of direct instantiation - """ - _globals: Final = get_litellm_globals() - - if name == "module_level_aclient": - # Create an async HTTP client using the factory function - from litellm.llms.custom_httpx.http_handler import get_async_httpx_client - - # Get timeout from module config (if set) - async_timeout: Final = _get_module_level_client_timeout(_globals) - params: Final = {"timeout": async_timeout, "client_alias": "module level aclient"} - - # Create the client instance - provider_id: Final = "litellm_module_level_client" - async_client: Final = get_async_httpx_client( - llm_provider=provider_id, - params=params, - ) - - # Cache it so we don't create it again - _globals["module_level_aclient"] = async_client - return async_client - - if name == "module_level_client": - # Create a sync HTTP client - from litellm.llms.custom_httpx.http_handler import HTTPHandler - - sync_timeout: Final = _get_module_level_client_timeout(_globals) - sync_client: Final = HTTPHandler(timeout=sync_timeout) - - # Cache it - _globals["module_level_client"] = sync_client - return sync_client - - raise AttributeError(f"HTTP handlers lazy import: unknown attribute {name!r}") +def resolve_lazy_attribute(module_name: str, name: str) -> object: + """Import, cache and return `name`, the way `module_name.__getattr__` would.""" + litellm_location: Final = LITELLM_ATTRIBUTES.get(name) + if litellm_location is not None: + return _import("litellm", name, litellm_location) + utils_location: Final = UTILS_ATTRIBUTES.get(name) + if utils_location is not None: + return _import("litellm.utils", name, utils_location) + factory: Final = _LITELLM_FACTORIES.get(name) if module_name == "litellm" else None + if factory is None: + raise AttributeError(f"module {module_name!r} has no attribute {name!r}") + cached: Final = _cached("litellm", name) + return cached if cached is not _NOT_LOADED else _cache("litellm", name, factory()) diff --git a/litellm/_lazy_imports_registry.py b/litellm/_lazy_imports_registry.py index bf903e23bc0..1cd82200087 100644 --- a/litellm/_lazy_imports_registry.py +++ b/litellm/_lazy_imports_registry.py @@ -1,1658 +1,666 @@ -""" -Registry data for lazy imports. - -This module contains all the name tuples and import maps used by the lazy import system. -Separated from the handler functions for better organization. -""" +"""Where each lazily loaded attribute of `litellm` and `litellm.utils` lives, as name -> (module, attribute).""" +from collections.abc import Mapping +from types import MappingProxyType from typing import Final -# Cost calculator names that support lazy loading via _lazy_import_cost_calculator -COST_CALCULATOR_NAMES: Final = ( - "completion_cost", - "cost_per_token", - "response_cost_calculator", +LITELLM_ATTRIBUTES: Final[Mapping[str, tuple[str, str]]] = MappingProxyType( + { + "completion_cost": (".cost_calculator", "completion_cost"), + "cost_per_token": (".cost_calculator", "cost_per_token"), + "response_cost_calculator": (".cost_calculator", "response_cost_calculator"), + "Logging": ("litellm.litellm_core_utils.litellm_logging", "Logging"), + "modify_integration": ("litellm.litellm_core_utils.litellm_logging", "modify_integration"), + "run_server": ("litellm.proxy.proxy_cli", "run_server"), + "get_optional_params": (".utils", "get_optional_params"), + "get_response_string": (".utils", "get_response_string"), + "token_counter": (".utils", "token_counter"), + "create_pretrained_tokenizer": (".utils", "create_pretrained_tokenizer"), + "create_tokenizer": (".utils", "create_tokenizer"), + "supports_function_calling": (".utils", "supports_function_calling"), + "supports_web_search": (".utils", "supports_web_search"), + "supports_tool_search": (".utils", "supports_tool_search"), + "supports_url_context": (".utils", "supports_url_context"), + "supports_continuation": (".utils", "supports_continuation"), + "supports_response_schema": (".utils", "supports_response_schema"), + "supports_parallel_function_calling": (".utils", "supports_parallel_function_calling"), + "supports_vision": (".utils", "supports_vision"), + "supports_audio_input": (".utils", "supports_audio_input"), + "supports_video_input": (".utils", "supports_video_input"), + "supports_box_questions": (".utils", "supports_box_questions"), + "supports_audio_output": (".utils", "supports_audio_output"), + "supports_system_messages": (".utils", "supports_system_messages"), + "supports_reasoning": (".utils", "supports_reasoning"), + "acreate": (".utils", "acreate"), + "get_max_tokens": (".utils", "get_max_tokens"), + "get_model_info": (".utils", "get_model_info"), + "register_prompt_template": (".utils", "register_prompt_template"), + "validate_environment": (".utils", "validate_environment"), + "check_valid_key": (".utils", "check_valid_key"), + "register_model": (".utils", "register_model"), + "encode": (".utils", "encode"), + "decode": (".utils", "decode"), + "calculate_retry_after": (".utils", "calculate_retry_after"), + "_calculate_retry_after": (".utils", "calculate_retry_after"), + "should_retry": (".utils", "should_retry"), + "_should_retry": (".utils", "should_retry"), + "get_first_chars_messages": (".utils", "get_first_chars_messages"), + "ModelResponse": (".utils", "ModelResponse"), + "ModelResponseStream": (".utils", "ModelResponseStream"), + "EmbeddingResponse": (".utils", "EmbeddingResponse"), + "ImageResponse": (".utils", "ImageResponse"), + "TranscriptionResponse": (".utils", "TranscriptionResponse"), + "TextCompletionResponse": (".utils", "TextCompletionResponse"), + "get_provider_fields": (".utils", "get_provider_fields"), + "ModelResponseListIterator": (".utils", "ModelResponseListIterator"), + "get_valid_models": (".utils", "get_valid_models"), + "timeout": (".timeout", "timeout"), + "get_modified_max_tokens": ("litellm.litellm_core_utils.token_counter", "get_modified_max_tokens"), + "COHERE_EMBEDDING_INPUT_TYPES": ("litellm.types.llms.bedrock", "COHERE_EMBEDDING_INPUT_TYPES"), + "ImageObject": (".types.utils", "ImageObject"), + "BudgetConfig": (".types.utils", "BudgetConfig"), + "all_litellm_params": (".types.utils", "all_litellm_params"), + "_litellm_completion_params": (".types.utils", "all_litellm_params"), + "CredentialItem": (".types.utils", "CredentialItem"), + "PriorityReservationDict": (".types.utils", "PriorityReservationDict"), + "StandardKeyGenerationConfig": (".types.utils", "StandardKeyGenerationConfig"), + "SearchProviders": (".types.utils", "SearchProviders"), + "GenericStreamingChunk": (".types.utils", "GenericStreamingChunk"), + "Cache": ("litellm.caching.caching", "Cache"), + "DualCache": ("litellm.caching.caching", "DualCache"), + "RedisCache": ("litellm.caching.caching", "RedisCache"), + "InMemoryCache": ("litellm.caching.caching", "InMemoryCache"), + "global_prompt_manager": ("litellm.integrations.dotprompt", "global_prompt_manager"), + "global_prompt_directory": ("litellm.integrations.dotprompt", "global_prompt_directory"), + "set_global_prompt_directory": ("litellm.integrations.dotprompt", "set_global_prompt_directory"), + "AmazonConverseConfig": (".llms.bedrock.chat.converse_transformation", "AmazonConverseConfig"), + "OpenAILikeChatConfig": (".llms.openai_like.chat.handler", "OpenAILikeChatConfig"), + "GaladrielChatConfig": (".llms.galadriel.chat.transformation", "GaladrielChatConfig"), + "GithubChatConfig": (".llms.github.chat.transformation", "GithubChatConfig"), + "AzureAnthropicConfig": (".llms.azure_ai.anthropic.transformation", "AzureAnthropicConfig"), + "BytezChatConfig": (".llms.bytez.chat.transformation", "BytezChatConfig"), + "CompactifAIChatConfig": (".llms.compactifai.chat.transformation", "CompactifAIChatConfig"), + "EmpowerChatConfig": (".llms.empower.chat.transformation", "EmpowerChatConfig"), + "MinimaxChatConfig": (".llms.minimax.chat.transformation", "MinimaxChatConfig"), + "AiohttpOpenAIChatConfig": (".llms.aiohttp_openai.chat.transformation", "AiohttpOpenAIChatConfig"), + "HuggingFaceChatConfig": (".llms.huggingface.chat.transformation", "HuggingFaceChatConfig"), + "HuggingFaceEmbeddingConfig": (".llms.huggingface.embedding.transformation", "HuggingFaceEmbeddingConfig"), + "OobaboogaConfig": (".llms.oobabooga.chat.transformation", "OobaboogaConfig"), + "MaritalkConfig": (".llms.maritalk", "MaritalkConfig"), + "OpenrouterConfig": (".llms.openrouter.chat.transformation", "OpenrouterConfig"), + "DataRobotConfig": (".llms.datarobot.chat.transformation", "DataRobotConfig"), + "AnthropicConfig": (".llms.anthropic.chat.transformation", "AnthropicConfig"), + "BedrockClaudePlatformConfig": (".llms.bedrock.claude_platform.transformation", "BedrockClaudePlatformConfig"), + "AnthropicTextConfig": (".llms.anthropic.completion.transformation", "AnthropicTextConfig"), + "GroqSTTConfig": (".llms.groq.stt.transformation", "GroqSTTConfig"), + "TritonConfig": (".llms.triton.completion.transformation", "TritonConfig"), + "TritonGenerateConfig": (".llms.triton.completion.transformation", "TritonGenerateConfig"), + "TritonInferConfig": (".llms.triton.completion.transformation", "TritonInferConfig"), + "TritonEmbeddingConfig": (".llms.triton.embedding.transformation", "TritonEmbeddingConfig"), + "HuggingFaceRerankConfig": (".llms.huggingface.rerank.transformation", "HuggingFaceRerankConfig"), + "DatabricksConfig": (".llms.databricks.chat.transformation", "DatabricksConfig"), + "DatabricksEmbeddingConfig": (".llms.databricks.embed.transformation", "DatabricksEmbeddingConfig"), + "PredibaseConfig": (".llms.predibase.chat.transformation", "PredibaseConfig"), + "ReplicateConfig": (".llms.replicate.chat.transformation", "ReplicateConfig"), + "SnowflakeConfig": (".llms.snowflake.chat.transformation", "SnowflakeConfig"), + "CohereRerankConfig": (".llms.cohere.rerank.transformation", "CohereRerankConfig"), + "CohereRerankV2Config": (".llms.cohere.rerank_v2.transformation", "CohereRerankV2Config"), + "AzureAIRerankConfig": (".llms.azure_ai.rerank.transformation", "AzureAIRerankConfig"), + "InfinityRerankConfig": (".llms.infinity.rerank.transformation", "InfinityRerankConfig"), + "JinaAIRerankConfig": (".llms.jina_ai.rerank.transformation", "JinaAIRerankConfig"), + "ScalewayRerankConfig": (".llms.scaleway.rerank.transformation", "ScalewayRerankConfig"), + "DeepinfraRerankConfig": (".llms.deepinfra.rerank.transformation", "DeepinfraRerankConfig"), + "HostedVLLMRerankConfig": (".llms.hosted_vllm.rerank.transformation", "HostedVLLMRerankConfig"), + "PerplexityDecisionsConfig": (".llms.perplexity.decisions.transformation", "PerplexityDecisionsConfig"), + "NaceDecisionsConfig": (".llms.nace.decisions.transformation", "NaceDecisionsConfig"), + "TypeSafeDecisionsConfig": (".llms.typesafe.decisions.transformation", "TypeSafeDecisionsConfig"), + "ParallelAIDecisionsConfig": (".llms.parallel_ai.decisions.transformation", "ParallelAIDecisionsConfig"), + "OpenRouterDecisionsConfig": (".llms.openrouter.decisions.transformation", "OpenRouterDecisionsConfig"), + "FireworksAIDecisionsConfig": (".llms.fireworks_ai.decisions.transformation", "FireworksAIDecisionsConfig"), + "CloudflareDecisionsConfig": (".llms.cloudflare.decisions.transformation", "CloudflareDecisionsConfig"), + "CloudflareExtractionConfig": (".llms.cloudflare.extraction.transformation", "CloudflareExtractionConfig"), + "StrandsDeciderDecisionsConfig": ( + ".llms.strands_decider.decisions.transformation", + "StrandsDeciderDecisionsConfig", + ), + "DatabricksDecisionsConfig": (".llms.databricks.decisions.transformation", "DatabricksDecisionsConfig"), + "HostedVLLMDecisionsConfig": (".llms.hosted_vllm.decisions.transformation", "HostedVLLMDecisionsConfig"), + "LMStudioDecisionsConfig": (".llms.lm_studio.decisions.transformation", "LMStudioDecisionsConfig"), + "OllamaDecisionsConfig": (".llms.ollama.decisions.transformation", "OllamaDecisionsConfig"), + "LayaDecisionsConfig": (".llms.laya.decisions.transformation", "LayaDecisionsConfig"), + "BespokeDecisionsConfig": (".llms.bespoke.decisions.transformation", "BespokeDecisionsConfig"), + "EmpirioLabsDecisionsConfig": (".llms.empiriolabs.decisions.transformation", "EmpirioLabsDecisionsConfig"), + "EuJevDecisionsConfig": (".llms.eu_jev.decisions.transformation", "EuJevDecisionsConfig"), + "OpenAIDecisionsConfig": (".llms.openai.decisions.transformation", "OpenAIDecisionsConfig"), + "AzureDecisionsConfig": (".llms.azure.decisions.transformation", "AzureDecisionsConfig"), + "AzureAIDecisionsConfig": (".llms.azure_ai.decisions.transformation", "AzureAIDecisionsConfig"), + "NvidiaNimRerankConfig": (".llms.nvidia_nim.rerank.transformation", "NvidiaNimRerankConfig"), + "NvidiaNimRankingConfig": (".llms.nvidia_nim.rerank.ranking_transformation", "NvidiaNimRankingConfig"), + "VertexAIRerankConfig": (".llms.vertex_ai.rerank.transformation", "VertexAIRerankConfig"), + "FireworksAIRerankConfig": (".llms.fireworks_ai.rerank.transformation", "FireworksAIRerankConfig"), + "VoyageRerankConfig": (".llms.voyage.rerank.transformation", "VoyageRerankConfig"), + "IBMWatsonXRerankConfig": (".llms.watsonx.rerank.transformation", "IBMWatsonXRerankConfig"), + "ClarifaiConfig": (".llms.clarifai.chat.transformation", "ClarifaiConfig"), + "AI21ChatConfig": (".llms.ai21.chat.transformation", "AI21ChatConfig"), + "LlamaAPIConfig": (".llms.meta_llama.chat.transformation", "LlamaAPIConfig"), + "TogetherAITextCompletionConfig": ( + ".llms.together_ai.completion.transformation", + "TogetherAITextCompletionConfig", + ), + "CloudflareChatConfig": (".llms.cloudflare.chat.transformation", "CloudflareChatConfig"), + "NovitaConfig": (".llms.novita.chat.transformation", "NovitaConfig"), + "PetalsConfig": (".llms.petals.completion.transformation", "PetalsConfig"), + "OllamaChatConfig": (".llms.ollama.chat.transformation", "OllamaChatConfig"), + "OllamaConfig": (".llms.ollama.completion.transformation", "OllamaConfig"), + "SagemakerConfig": (".llms.sagemaker.completion.transformation", "SagemakerConfig"), + "SagemakerChatConfig": (".llms.sagemaker.chat.transformation", "SagemakerChatConfig"), + "SagemakerNovaConfig": (".llms.sagemaker.nova.transformation", "SagemakerNovaConfig"), + "CohereChatConfig": (".llms.cohere.chat.transformation", "CohereChatConfig"), + "AnthropicMessagesConfig": (".llms.anthropic.messages.native.transformation", "AnthropicMessagesConfig"), + "BedrockClaudePlatformMessagesConfig": ( + ".llms.bedrock.claude_platform.messages_transformation", + "BedrockClaudePlatformMessagesConfig", + ), + "AmazonAnthropicClaudeMessagesConfig": ( + ".llms.bedrock.messages.invoke_transformations.anthropic_claude_transformation", + "AmazonAnthropicClaudeMessagesConfig", + ), + "AmazonMantleMessagesConfig": (".llms.bedrock.messages.mantle_transformation", "AmazonMantleMessagesConfig"), + "BedrockMantleAnthropicMessagesConfig": ( + ".llms.bedrock_mantle.messages.transformation", + "BedrockMantleAnthropicMessagesConfig", + ), + "TogetherAIConfig": (".llms.together_ai.chat", "TogetherAIConfig"), + "TogetherAIChatConfig": (".llms.together_ai.chat.transformation", "TogetherAIChatConfig"), + "NLPCloudConfig": (".llms.nlp_cloud.chat.handler", "NLPCloudConfig"), + "VertexGeminiConfig": (".llms.vertex_ai.gemini.vertex_and_google_ai_studio_gemini", "VertexGeminiConfig"), + "GoogleAIStudioGeminiConfig": (".llms.gemini.chat.transformation", "GoogleAIStudioGeminiConfig"), + "VertexAIAnthropicConfig": ( + ".llms.vertex_ai.vertex_ai_partner_models.anthropic.transformation", + "VertexAIAnthropicConfig", + ), + "VertexAILlama3Config": ( + ".llms.vertex_ai.vertex_ai_partner_models.llama.transformation", + "VertexAILlama3Config", + ), + "VertexAIAi21Config": (".llms.vertex_ai.vertex_ai_partner_models.ai21.transformation", "VertexAIAi21Config"), + "VertexAIMistralConfig": ( + ".llms.vertex_ai.vertex_ai_partner_models.mistral.transformation", + "VertexAIMistralConfig", + ), + "AmazonCohereChatConfig": (".llms.bedrock.chat.invoke_handler", "AmazonCohereChatConfig"), + "AmazonBedrockGlobalConfig": (".llms.bedrock.common_utils", "AmazonBedrockGlobalConfig"), + "AmazonAI21Config": ( + ".llms.bedrock.chat.invoke_transformations.amazon_ai21_transformation", + "AmazonAI21Config", + ), + "AmazonInvokeNovaConfig": ( + ".llms.bedrock.chat.invoke_transformations.amazon_nova_transformation", + "AmazonInvokeNovaConfig", + ), + "AmazonQwen2Config": ( + ".llms.bedrock.chat.invoke_transformations.amazon_qwen2_transformation", + "AmazonQwen2Config", + ), + "AmazonQwen3Config": ( + ".llms.bedrock.chat.invoke_transformations.amazon_qwen3_transformation", + "AmazonQwen3Config", + ), + "VertexAIConfig": (".llms.vertex_ai.gemini.vertex_and_google_ai_studio_gemini", "VertexGeminiConfig"), + "GeminiConfig": (".llms.gemini.chat.transformation", "GoogleAIStudioGeminiConfig"), + "AmazonAnthropicConfig": ( + ".llms.bedrock.chat.invoke_transformations.anthropic_legacy_text_completions_transformation", + "AmazonAnthropicConfig", + ), + "AmazonAnthropicClaudeConfig": ( + ".llms.bedrock.chat.invoke_transformations.anthropic_claude_transformation", + "AmazonAnthropicClaudeConfig", + ), + "AmazonCohereConfig": ( + ".llms.bedrock.chat.invoke_transformations.amazon_cohere_transformation", + "AmazonCohereConfig", + ), + "AmazonLlamaConfig": ( + ".llms.bedrock.chat.invoke_transformations.amazon_llama_transformation", + "AmazonLlamaConfig", + ), + "AmazonDeepSeekR1Config": ( + ".llms.bedrock.chat.invoke_transformations.amazon_deepseek_transformation", + "AmazonDeepSeekR1Config", + ), + "AmazonMistralConfig": ( + ".llms.bedrock.chat.invoke_transformations.amazon_mistral_transformation", + "AmazonMistralConfig", + ), + "AmazonMoonshotConfig": ( + ".llms.bedrock.chat.invoke_transformations.amazon_moonshot_transformation", + "AmazonMoonshotConfig", + ), + "AmazonTitanConfig": ( + ".llms.bedrock.chat.invoke_transformations.amazon_titan_transformation", + "AmazonTitanConfig", + ), + "AmazonTwelveLabsPegasusConfig": ( + ".llms.bedrock.chat.invoke_transformations.amazon_twelvelabs_pegasus_transformation", + "AmazonTwelveLabsPegasusConfig", + ), + "AmazonInvokeConfig": ( + ".llms.bedrock.chat.invoke_transformations.base_invoke_transformation", + "AmazonInvokeConfig", + ), + "AmazonBedrockOpenAIConfig": ( + ".llms.bedrock.chat.invoke_transformations.amazon_openai_transformation", + "AmazonBedrockOpenAIConfig", + ), + "AmazonBedrockRuntimeChatCompletionsConfig": ( + ".llms.bedrock.chat.chat_completions.transformation", + "AmazonBedrockRuntimeChatCompletionsConfig", + ), + "AmazonStabilityConfig": ( + ".llms.bedrock.image_generation.amazon_stability1_transformation", + "AmazonStabilityConfig", + ), + "AmazonStability3Config": ( + ".llms.bedrock.image_generation.amazon_stability3_transformation", + "AmazonStability3Config", + ), + "AmazonNovaCanvasConfig": ( + ".llms.bedrock.image_generation.amazon_nova_canvas_transformation", + "AmazonNovaCanvasConfig", + ), + "AmazonTitanG1Config": (".llms.bedrock.embed.amazon_titan_g1_transformation", "AmazonTitanG1Config"), + "AmazonTitanMultimodalEmbeddingG1Config": ( + ".llms.bedrock.embed.amazon_titan_multimodal_transformation", + "AmazonTitanMultimodalEmbeddingG1Config", + ), + "CohereV2ChatConfig": (".llms.cohere.chat.v2_transformation", "CohereV2ChatConfig"), + "BedrockCohereEmbeddingConfig": (".llms.bedrock.embed.cohere_transformation", "BedrockCohereEmbeddingConfig"), + "TwelveLabsMarengoEmbeddingConfig": ( + ".llms.bedrock.embed.twelvelabs_marengo_transformation", + "TwelveLabsMarengoEmbeddingConfig", + ), + "AmazonNovaEmbeddingConfig": (".llms.bedrock.embed.amazon_nova_transformation", "AmazonNovaEmbeddingConfig"), + "OpenAIConfig": (".llms.openai.openai", "OpenAIConfig"), + "MistralEmbeddingConfig": (".llms.openai.openai", "MistralEmbeddingConfig"), + "OpenAIImageVariationConfig": (".llms.openai.image_variations.transformation", "OpenAIImageVariationConfig"), + "DeepInfraConfig": (".llms.deepinfra.chat.transformation", "DeepInfraConfig"), + "ClfAiGatewayConfig": (".llms.clf_ai_gateway.chat.transformation", "ClfAiGatewayConfig"), + "DeepgramAudioTranscriptionConfig": ( + ".llms.deepgram.audio_transcription.transformation", + "DeepgramAudioTranscriptionConfig", + ), + "TopazImageVariationConfig": (".llms.topaz.image_variations.transformation", "TopazImageVariationConfig"), + "OpenAITextCompletionConfig": ("litellm.llms.openai.completion.transformation", "OpenAITextCompletionConfig"), + "GroqChatConfig": (".llms.groq.chat.transformation", "GroqChatConfig"), + "BedrockOpenAIResponsesConfig": (".llms.bedrock.responses.transformation", "BedrockOpenAIResponsesConfig"), + "BedrockMantleChatConfig": (".llms.bedrock_mantle.chat.transformation", "BedrockMantleChatConfig"), + "A2AConfig": (".llms.a2a.chat.transformation", "A2AConfig"), + "GenAIHubOrchestrationConfig": (".llms.sap.chat.transformation", "GenAIHubOrchestrationConfig"), + "VoyageEmbeddingConfig": (".llms.voyage.embedding.transformation", "VoyageEmbeddingConfig"), + "VoyageContextualEmbeddingConfig": ( + ".llms.voyage.embedding.transformation_contextual", + "VoyageContextualEmbeddingConfig", + ), + "VoyageMultimodalEmbeddingConfig": ( + ".llms.voyage.embedding.transformation_multimodal", + "VoyageMultimodalEmbeddingConfig", + ), + "InfinityEmbeddingConfig": (".llms.infinity.embedding.transformation", "InfinityEmbeddingConfig"), + "PerplexityEmbeddingConfig": (".llms.perplexity.embedding.transformation", "PerplexityEmbeddingConfig"), + "AzureAIStudioConfig": (".llms.azure_ai.chat.transformation", "AzureAIStudioConfig"), + "MistralConfig": (".llms.mistral.chat.transformation", "MistralConfig"), + "OpenAIResponsesAPIConfig": (".llms.openai.responses.transformation", "OpenAIResponsesAPIConfig"), + "AzureOpenAIResponsesAPIConfig": (".llms.azure.responses.transformation", "AzureOpenAIResponsesAPIConfig"), + "AzureOpenAIOSeriesResponsesAPIConfig": ( + ".llms.azure.responses.o_series_transformation", + "AzureOpenAIOSeriesResponsesAPIConfig", + ), + "AzureAIResponsesAPIConfig": (".llms.azure_ai.responses.transformation", "AzureAIResponsesAPIConfig"), + "XAIResponsesAPIConfig": (".llms.xai.responses.transformation", "XAIResponsesAPIConfig"), + "LiteLLMProxyResponsesAPIConfig": ( + ".llms.litellm_proxy.responses.transformation", + "LiteLLMProxyResponsesAPIConfig", + ), + "HostedVLLMResponsesAPIConfig": (".llms.hosted_vllm.responses.transformation", "HostedVLLMResponsesAPIConfig"), + "FireworksAIResponsesAPIConfig": ( + ".llms.fireworks_ai.responses.transformation", + "FireworksAIResponsesAPIConfig", + ), + "VolcEngineResponsesAPIConfig": (".llms.volcengine.responses.transformation", "VolcEngineResponsesAPIConfig"), + "ManusResponsesAPIConfig": (".llms.manus.responses.transformation", "ManusResponsesAPIConfig"), + "PerplexityResponsesConfig": (".llms.perplexity.responses.transformation", "PerplexityResponsesConfig"), + "DatabricksResponsesAPIConfig": (".llms.databricks.responses.transformation", "DatabricksResponsesAPIConfig"), + "OpenRouterResponsesAPIConfig": (".llms.openrouter.responses.transformation", "OpenRouterResponsesAPIConfig"), + "BedrockMantleResponsesAPIConfig": ( + ".llms.bedrock_mantle.responses.transformation", + "BedrockMantleResponsesAPIConfig", + ), + "GoogleAIStudioInteractionsConfig": ( + ".llms.gemini.interactions.transformation", + "GoogleAIStudioInteractionsConfig", + ), + "VertexAIInteractionsConfig": (".llms.vertex_ai.interactions.transformation", "VertexAIInteractionsConfig"), + "OpenAIOSeriesConfig": (".llms.openai.chat.o_series_transformation", "OpenAIOSeriesConfig"), + "AnthropicSkillsConfig": (".llms.anthropic.skills.transformation", "AnthropicSkillsConfig"), + "BaseSkillsAPIConfig": (".llms.base_llm.skills.transformation", "BaseSkillsAPIConfig"), + "GradientAIConfig": (".llms.gradient_ai.chat.transformation", "GradientAIConfig"), + "OpenAIO1Config": (".llms.openai.chat.o_series_transformation", "OpenAIOSeriesConfig"), + "OpenAIGPTConfig": (".llms.openai.chat.gpt_transformation", "OpenAIGPTConfig"), + "OpenAIGPT5Config": (".llms.openai.chat.gpt_reasoning_transformation", "OpenAIGPT5Config"), + "OpenAIWhisperAudioTranscriptionConfig": ( + ".llms.openai.transcriptions.whisper_transformation", + "OpenAIWhisperAudioTranscriptionConfig", + ), + "OpenAIGPTAudioTranscriptionConfig": ( + ".llms.openai.transcriptions.gpt_transformation", + "OpenAIGPTAudioTranscriptionConfig", + ), + "OpenAIGPTAudioConfig": (".llms.openai.chat.gpt_audio_transformation", "OpenAIGPTAudioConfig"), + "NvidiaNimConfig": (".llms.nvidia_nim.chat.transformation", "NvidiaNimConfig"), + "NvidiaNimEmbeddingConfig": (".llms.nvidia_nim.embed", "NvidiaNimEmbeddingConfig"), + "FeatherlessAIConfig": (".llms.featherless_ai.chat.transformation", "FeatherlessAIConfig"), + "ScaleDownChatConfig": (".llms.scaledown.chat.transformation", "ScaleDownChatConfig"), + "CerebrasConfig": (".llms.cerebras.chat", "CerebrasConfig"), + "NadirConfig": (".llms.nadir.chat.transformation", "NadirConfig"), + "BasetenConfig": (".llms.baseten.chat", "BasetenConfig"), + "SambanovaConfig": (".llms.sambanova.chat", "SambanovaConfig"), + "SambaNovaEmbeddingConfig": (".llms.sambanova.embedding.transformation", "SambaNovaEmbeddingConfig"), + "FireworksAIConfig": (".llms.fireworks_ai.chat.transformation", "FireworksAIConfig"), + "FireworksAITextCompletionConfig": ( + ".llms.fireworks_ai.completion.transformation", + "FireworksAITextCompletionConfig", + ), + "FireworksAIEmbeddingConfig": ( + ".llms.fireworks_ai.embed.fireworks_ai_transformation", + "FireworksAIEmbeddingConfig", + ), + "FriendliaiChatConfig": (".llms.friendliai.chat.transformation", "FriendliaiChatConfig"), + "JinaAIEmbeddingConfig": (".llms.jina_ai.embedding.transformation", "JinaAIEmbeddingConfig"), + "XAIChatConfig": (".llms.xai.chat.transformation", "XAIChatConfig"), + "ZAIChatConfig": (".llms.zai.chat.transformation", "ZAIChatConfig"), + "AIMLChatConfig": (".llms.aiml.chat.transformation", "AIMLChatConfig"), + "VolcEngineChatConfig": (".llms.volcengine.chat.transformation", "VolcEngineChatConfig"), + "CodestralTextCompletionConfig": (".llms.codestral.completion.transformation", "CodestralTextCompletionConfig"), + "InceptionTextCompletionConfig": (".llms.inception.completion.transformation", "InceptionTextCompletionConfig"), + "AzureOpenAIAssistantsAPIConfig": (".llms.azure.azure", "AzureOpenAIAssistantsAPIConfig"), + "HerokuChatConfig": (".llms.heroku.chat.transformation", "HerokuChatConfig"), + "CometAPIConfig": (".llms.cometapi.chat.transformation", "CometAPIConfig"), + "AzureOpenAIConfig": (".llms.azure.chat.gpt_transformation", "AzureOpenAIConfig"), + "AzureOpenAIGPT5Config": (".llms.azure.chat.gpt_reasoning_transformation", "AzureOpenAIGPT5Config"), + "AzureOpenAITextConfig": (".llms.azure.completion.transformation", "AzureOpenAITextConfig"), + "AzureSpeechAudioTranscriptionConfig": ( + ".llms.azure.audio_transcription.transformation", + "AzureSpeechAudioTranscriptionConfig", + ), + "HostedVLLMChatConfig": (".llms.hosted_vllm.chat.transformation", "HostedVLLMChatConfig"), + "HostedVLLMEmbeddingConfig": (".llms.hosted_vllm.embedding.transformation", "HostedVLLMEmbeddingConfig"), + "VolcEngineConfig": (".llms.volcengine.chat.transformation", "VolcEngineChatConfig"), + "LlamafileChatConfig": (".llms.llamafile.chat.transformation", "LlamafileChatConfig"), + "LiteLLMProxyChatConfig": (".llms.litellm_proxy.chat.transformation", "LiteLLMProxyChatConfig"), + "VLLMConfig": (".llms.vllm.completion.transformation", "VLLMConfig"), + "DeepSeekChatConfig": (".llms.deepseek.chat.transformation", "DeepSeekChatConfig"), + "TencentChatConfig": (".llms.tencent.chat.transformation", "TencentChatConfig"), + "LMStudioChatConfig": (".llms.lm_studio.chat.transformation", "LMStudioChatConfig"), + "LmStudioEmbeddingConfig": (".llms.lm_studio.embed.transformation", "LmStudioEmbeddingConfig"), + "NscaleConfig": (".llms.nscale.chat.transformation", "NscaleConfig"), + "PerplexityChatConfig": (".llms.perplexity.chat.transformation", "PerplexityChatConfig"), + "AzureOpenAIO1Config": (".llms.azure.chat.o_series_transformation", "AzureOpenAIO1Config"), + "IBMWatsonXAIConfig": (".llms.watsonx.completion.transformation", "IBMWatsonXAIConfig"), + "IBMWatsonXChatConfig": (".llms.watsonx.chat.transformation", "IBMWatsonXChatConfig"), + "IBMWatsonXEmbeddingConfig": (".llms.watsonx.embed.transformation", "IBMWatsonXEmbeddingConfig"), + "GenAIHubEmbeddingConfig": (".llms.sap.embed.transformation", "GenAIHubEmbeddingConfig"), + "IBMWatsonXAudioTranscriptionConfig": ( + ".llms.watsonx.audio_transcription.transformation", + "IBMWatsonXAudioTranscriptionConfig", + ), + "GithubCopilotConfig": (".llms.github_copilot.chat.transformation", "GithubCopilotConfig"), + "GithubCopilotResponsesAPIConfig": ( + ".llms.github_copilot.responses.transformation", + "GithubCopilotResponsesAPIConfig", + ), + "GithubCopilotEmbeddingConfig": ( + ".llms.github_copilot.embedding.transformation", + "GithubCopilotEmbeddingConfig", + ), + "ChatGPTConfig": (".llms.chatgpt.chat.transformation", "ChatGPTConfig"), + "ChatGPTResponsesAPIConfig": (".llms.chatgpt.responses.transformation", "ChatGPTResponsesAPIConfig"), + "NebiusConfig": (".llms.nebius.chat.transformation", "NebiusConfig"), + "WandbConfig": (".llms.wandb.chat.transformation", "WandbConfig"), + "GigaChatConfig": (".llms.gigachat.chat.transformation", "GigaChatConfig"), + "GigaChatEmbeddingConfig": (".llms.gigachat.embedding.transformation", "GigaChatEmbeddingConfig"), + "DashScopeChatConfig": (".llms.dashscope.chat.transformation", "DashScopeChatConfig"), + "QwenCloudChatConfig": (".llms.dashscope.qwencloud", "QwenCloudChatConfig"), + "QwenAIPlatformChatConfig": (".llms.dashscope.qwen_ai_platform", "QwenAIPlatformChatConfig"), + "GDCGeminiConfig": (".llms.gdc.chat.transformation", "GDCGeminiConfig"), + "ModelScopeChatConfig": (".llms.modelscope.chat.transformation", "ModelScopeChatConfig"), + "MoonshotChatConfig": (".llms.moonshot.chat.transformation", "MoonshotChatConfig"), + "DockerModelRunnerChatConfig": (".llms.docker_model_runner.chat.transformation", "DockerModelRunnerChatConfig"), + "V0ChatConfig": (".llms.v0.chat.transformation", "V0ChatConfig"), + "OCIChatConfig": (".llms.oci.chat.transformation", "OCIChatConfig"), + "MorphChatConfig": (".llms.morph.chat.transformation", "MorphChatConfig"), + "RAGFlowConfig": (".llms.ragflow.chat.transformation", "RAGFlowConfig"), + "LambdaAIChatConfig": (".llms.lambda_ai.chat.transformation", "LambdaAIChatConfig"), + "InceptionChatConfig": (".llms.inception.chat.transformation", "InceptionChatConfig"), + "HyperbolicChatConfig": (".llms.hyperbolic.chat.transformation", "HyperbolicChatConfig"), + "VercelAIGatewayConfig": (".llms.vercel_ai_gateway.chat.transformation", "VercelAIGatewayConfig"), + "EdenAIChatConfig": (".llms.edenai.chat.transformation", "EdenAIChatConfig"), + "EdenAIResponsesAPIConfig": (".llms.edenai.responses.transformation", "EdenAIResponsesAPIConfig"), + "EdenAIAnthropicMessagesConfig": (".llms.edenai.messages.transformation", "EdenAIAnthropicMessagesConfig"), + "EdenAIEmbeddingConfig": (".llms.edenai.embedding.transformation", "EdenAIEmbeddingConfig"), + "EdenAIAudioTranscriptionConfig": ( + ".llms.edenai.audio_transcription.transformation", + "EdenAIAudioTranscriptionConfig", + ), + "EdenAITextToSpeechConfig": (".llms.edenai.text_to_speech.transformation", "EdenAITextToSpeechConfig"), + "EdenAIImageGenerationConfig": (".llms.edenai.image_generation.transformation", "EdenAIImageGenerationConfig"), + "EdenAIVideoConfig": (".llms.edenai.videos.transformation", "EdenAIVideoConfig"), + "FalAIChatConfig": (".llms.fal_ai.chat.transformation", "FalAIChatConfig"), + "FalAIError": (".llms.fal_ai.chat.transformation", "FalAIError"), + "OVHCloudChatConfig": (".llms.ovhcloud.chat.transformation", "OVHCloudChatConfig"), + "OVHCloudEmbeddingConfig": (".llms.ovhcloud.embedding.transformation", "OVHCloudEmbeddingConfig"), + "CometAPIEmbeddingConfig": (".llms.cometapi.embed.transformation", "CometAPIEmbeddingConfig"), + "LemonadeChatConfig": (".llms.lemonade.chat.transformation", "LemonadeChatConfig"), + "SnowflakeEmbeddingConfig": (".llms.snowflake.embedding.transformation", "SnowflakeEmbeddingConfig"), + "AmazonNovaChatConfig": (".llms.amazon_nova.chat.transformation", "AmazonNovaChatConfig"), + "SonioxAudioTranscriptionConfig": ( + ".llms.soniox.audio_transcription.transformation", + "SonioxAudioTranscriptionConfig", + ), + "GuardrailItem": ("litellm.types.guardrails", "GuardrailItem"), + "DefaultTeamSSOParams": ("litellm.types.proxy.management_endpoints.ui_sso", "DefaultTeamSSOParams"), + "LiteLLM_UpperboundKeyGenerateParams": ( + "litellm.types.proxy.management_endpoints.ui_sso", + "LiteLLM_UpperboundKeyGenerateParams", + ), + "KeyManagementSystem": ("litellm.types.secret_managers.main", "KeyManagementSystem"), + "PriorityReservationSettings": ("litellm.types.utils", "PriorityReservationSettings"), + "CustomLogger": ("litellm.integrations.custom_logger", "CustomLogger"), + "LoggingCallbackManager": ("litellm.litellm_core_utils.logging_callback_manager", "LoggingCallbackManager"), + "DatadogLLMObsInitParams": ("litellm.types.integrations.datadog_llm_obs", "DatadogLLMObsInitParams"), + "remove_index_from_tool_calls": ("litellm.litellm_core_utils.core_helpers", "remove_index_from_tool_calls"), + "LLMClientCache": (".caching.llm_caching_handler", "LLMClientCache"), + "bedrock_tool_name_mappings": (".llms.bedrock.chat.invoke_handler", "bedrock_tool_name_mappings"), + "AzureOpenAIError": (".llms.azure.common_utils", "AzureOpenAIError"), + "agent": (".harness", "agent"), + "aagent": (".harness", "aagent"), + "agent_session": (".harness", "agent_session"), + "aagent_session": (".harness", "aagent_session"), + "agent_resume": (".harness", "agent_resume"), + "aagent_resume": (".harness", "aagent_resume"), + "agent_capabilities": (".harness", "agent_capabilities"), + "Harness": (".harness", "Harness"), + "ClaudeCodeOptions": (".harness", "ClaudeCodeOptions"), + "CodexOptions": (".harness", "CodexOptions"), + "OpenCodeOptions": (".harness", "OpenCodeOptions"), + "PiOptions": (".harness", "PiOptions"), + "DeepAgentsOptions": (".harness", "DeepAgentsOptions"), + "ToolLoopOptions": (".harness", "ToolLoopOptions"), + "acreate_eval": (".evals.main", "acreate_eval"), + "alist_evals": (".evals.main", "alist_evals"), + "aget_eval": (".evals.main", "aget_eval"), + "aupdate_eval": (".evals.main", "aupdate_eval"), + "adelete_eval": (".evals.main", "adelete_eval"), + "acancel_eval": (".evals.main", "acancel_eval"), + "create_eval": (".evals.main", "create_eval"), + "list_evals": (".evals.main", "list_evals"), + "get_eval": (".evals.main", "get_eval"), + "update_eval": (".evals.main", "update_eval"), + "delete_eval": (".evals.main", "delete_eval"), + "cancel_eval": (".evals.main", "cancel_eval"), + "acreate_run": (".evals.main", "acreate_run"), + "alist_runs": (".evals.main", "alist_runs"), + "aget_run": (".evals.main", "aget_run"), + "acancel_run": (".evals.main", "acancel_run"), + "adelete_run": (".evals.main", "adelete_run"), + "create_run": (".evals.main", "create_run"), + "list_runs": (".evals.main", "list_runs"), + "get_run": (".evals.main", "get_run"), + "cancel_run": (".evals.main", "cancel_run"), + "delete_run": (".evals.main", "delete_run"), + } ) -# Litellm logging names that support lazy loading via _lazy_import_litellm_logging -LITELLM_LOGGING_NAMES: Final = ( - "Logging", - "modify_integration", +UTILS_ATTRIBUTES: Final[Mapping[str, tuple[str, str]]] = MappingProxyType( + { + "encoding": ("litellm.main", "encoding"), + "BaseVectorStore": ("litellm.integrations.vector_store_integrations.base_vector_store", "BaseVectorStore"), + "CredentialAccessor": ("litellm.litellm_core_utils.credential_accessor", "CredentialAccessor"), + "exception_type": ("litellm.litellm_core_utils.exception_mapping_utils", "exception_type"), + "get_error_message": ("litellm.litellm_core_utils.exception_mapping_utils", "get_error_message"), + "_get_response_headers": ("litellm.litellm_core_utils.exception_mapping_utils", "_get_response_headers"), + "get_llm_provider": ("litellm.litellm_core_utils.get_llm_provider_logic", "get_llm_provider"), + "_is_non_openai_azure_model": ( + "litellm.litellm_core_utils.get_llm_provider_logic", + "is_non_openai_azure_model", + ), + "is_non_openai_azure_model": ("litellm.litellm_core_utils.get_llm_provider_logic", "is_non_openai_azure_model"), + "get_supported_openai_params": ( + "litellm.litellm_core_utils.get_supported_openai_params", + "get_supported_openai_params", + ), + "LiteLLMResponseObjectHandler": ( + "litellm.litellm_core_utils.llm_response_utils.convert_dict_to_response", + "LiteLLMResponseObjectHandler", + ), + "_handle_invalid_parallel_tool_calls": ( + "litellm.litellm_core_utils.llm_response_utils.convert_dict_to_response", + "handle_invalid_parallel_tool_calls", + ), + "handle_invalid_parallel_tool_calls": ( + "litellm.litellm_core_utils.llm_response_utils.convert_dict_to_response", + "handle_invalid_parallel_tool_calls", + ), + "convert_to_model_response_object": ( + "litellm.litellm_core_utils.llm_response_utils.convert_dict_to_response", + "convert_to_model_response_object", + ), + "convert_to_streaming_response": ( + "litellm.litellm_core_utils.llm_response_utils.convert_dict_to_response", + "convert_to_streaming_response", + ), + "convert_to_streaming_response_async": ( + "litellm.litellm_core_utils.llm_response_utils.convert_dict_to_response", + "convert_to_streaming_response_async", + ), + "get_api_base": ("litellm.litellm_core_utils.llm_response_utils.get_api_base", "get_api_base"), + "ResponseMetadata": ("litellm.litellm_core_utils.llm_response_utils.response_metadata", "ResponseMetadata"), + "_parse_content_for_reasoning": ( + "litellm.litellm_core_utils.prompt_templates.common_utils", + "parse_content_for_reasoning", + ), + "parse_content_for_reasoning": ( + "litellm.litellm_core_utils.prompt_templates.common_utils", + "parse_content_for_reasoning", + ), + "LiteLLMLoggingObject": ("litellm.litellm_core_utils.redact_messages", "LiteLLMLoggingObject"), + "redact_message_input_output_from_logging": ( + "litellm.litellm_core_utils.redact_messages", + "redact_message_input_output_from_logging", + ), + "CustomStreamWrapper": ("litellm.litellm_core_utils.streaming_handler", "CustomStreamWrapper"), + "BaseGoogleGenAIGenerateContentConfig": ( + "litellm.llms.base_llm.google_genai.transformation", + "BaseGoogleGenAIGenerateContentConfig", + ), + "BaseSearchConfig": ("litellm.llms.base_llm.search.transformation", "BaseSearchConfig"), + "BaseTextToSpeechConfig": ("litellm.llms.base_llm.text_to_speech.transformation", "BaseTextToSpeechConfig"), + "BedrockModelInfo": ("litellm.llms.bedrock.common_utils", "BedrockModelInfo"), + "CohereModelInfo": ("litellm.llms.cohere.common_utils", "CohereModelInfo"), + "Rules": ("litellm.litellm_core_utils.rules", "Rules"), + "AsyncHTTPHandler": ("litellm.llms.custom_httpx.http_handler", "AsyncHTTPHandler"), + "HTTPHandler": ("litellm.llms.custom_httpx.http_handler", "HTTPHandler"), + "get_num_retries_from_retry_policy": ( + "litellm.litellm_core_utils.get_retry_from_policy", + "get_num_retries_from_retry_policy", + ), + "reset_retry_policy": ("litellm.litellm_core_utils.get_retry_from_policy", "reset_retry_policy"), + "get_coroutine_checker": ("litellm.litellm_core_utils.cached_imports", "get_coroutine_checker"), + "get_litellm_logging_class": ("litellm.litellm_core_utils.cached_imports", "get_litellm_logging_class"), + "get_set_callbacks": ("litellm.litellm_core_utils.cached_imports", "get_set_callbacks"), + "get_litellm_metadata_from_kwargs": ( + "litellm.litellm_core_utils.core_helpers", + "get_litellm_metadata_from_kwargs", + ), + "map_finish_reason": ("litellm.litellm_core_utils.core_helpers", "map_finish_reason"), + "process_response_headers": ("litellm.litellm_core_utils.core_helpers", "process_response_headers"), + "delete_nested_value": ("litellm.litellm_core_utils.dot_notation_indexing", "delete_nested_value"), + "is_nested_path": ("litellm.litellm_core_utils.dot_notation_indexing", "is_nested_path"), + "_get_base_model_from_litellm_call_metadata": ( + "litellm.litellm_core_utils.get_litellm_params", + "get_base_model_from_litellm_call_metadata", + ), + "get_base_model_from_litellm_call_metadata": ( + "litellm.litellm_core_utils.get_litellm_params", + "get_base_model_from_litellm_call_metadata", + ), + "get_litellm_params": ("litellm.litellm_core_utils.get_litellm_params", "get_litellm_params"), + "_ensure_extra_body_is_safe": ("litellm.litellm_core_utils.llm_request_utils", "ensure_extra_body_is_safe"), + "ensure_extra_body_is_safe": ("litellm.litellm_core_utils.llm_request_utils", "ensure_extra_body_is_safe"), + "get_formatted_prompt": ( + "litellm.litellm_core_utils.llm_response_utils.get_formatted_prompt", + "get_formatted_prompt", + ), + "get_response_headers": ("litellm.litellm_core_utils.llm_response_utils.get_headers", "get_response_headers"), + "update_response_metadata": ( + "litellm.litellm_core_utils.llm_response_utils.response_metadata", + "update_response_metadata", + ), + "executor": ("litellm.litellm_core_utils.thread_pool_executor", "executor"), + "BaseAnthropicMessagesConfig": ( + "litellm.llms.base_llm.anthropic_messages.transformation", + "BaseAnthropicMessagesConfig", + ), + "BaseAudioTranscriptionConfig": ( + "litellm.llms.base_llm.audio_transcription.transformation", + "BaseAudioTranscriptionConfig", + ), + "BaseBatchesConfig": ("litellm.llms.base_llm.batches.transformation", "BaseBatchesConfig"), + "BaseContainerConfig": ("litellm.llms.base_llm.containers.transformation", "BaseContainerConfig"), + "BaseEmbeddingConfig": ("litellm.llms.base_llm.embedding.transformation", "BaseEmbeddingConfig"), + "BaseImageEditConfig": ("litellm.llms.base_llm.image_edit.transformation", "BaseImageEditConfig"), + "BaseImageGenerationConfig": ( + "litellm.llms.base_llm.image_generation.transformation", + "BaseImageGenerationConfig", + ), + "BaseImageVariationConfig": ( + "litellm.llms.base_llm.image_variations.transformation", + "BaseImageVariationConfig", + ), + "BasePassthroughConfig": ("litellm.llms.base_llm.passthrough.transformation", "BasePassthroughConfig"), + "BaseRealtimeConfig": ("litellm.llms.base_llm.realtime.transformation", "BaseRealtimeConfig"), + "BaseRerankConfig": ("litellm.llms.base_llm.rerank.transformation", "BaseRerankConfig"), + "BaseVectorStoreConfig": ("litellm.llms.base_llm.vector_store.transformation", "BaseVectorStoreConfig"), + "BaseVectorStoreFilesConfig": ( + "litellm.llms.base_llm.vector_store_files.transformation", + "BaseVectorStoreFilesConfig", + ), + "BaseVideoConfig": ("litellm.llms.base_llm.videos.transformation", "BaseVideoConfig"), + "ANTHROPIC_API_ONLY_HEADERS": ("litellm.types.llms.anthropic", "ANTHROPIC_API_ONLY_HEADERS"), + "AnthropicThinkingParam": ("litellm.types.llms.anthropic", "AnthropicThinkingParam"), + "RerankResponse": ("litellm.types.rerank", "RerankResponse"), + "ChatCompletionDeltaToolCallChunk": ("litellm.types.llms.openai", "ChatCompletionDeltaToolCallChunk"), + "ChatCompletionToolCallChunk": ("litellm.types.llms.openai", "ChatCompletionToolCallChunk"), + "ChatCompletionToolCallFunctionChunk": ("litellm.types.llms.openai", "ChatCompletionToolCallFunctionChunk"), + "LiteLLM_Params": ("litellm.types.router", "LiteLLM_Params"), + } ) - -# Utils names that support lazy loading via _lazy_import_utils -UTILS_NAMES: Final = ( - "run_server", - "exception_type", - "get_optional_params", - "get_response_string", - "token_counter", - "create_pretrained_tokenizer", - "create_tokenizer", - "supports_function_calling", - "supports_web_search", - "supports_tool_search", - "supports_url_context", - "supports_continuation", - "supports_response_schema", - "supports_parallel_function_calling", - "supports_vision", - "supports_audio_input", - "supports_video_input", - "supports_box_questions", - "supports_audio_output", - "supports_system_messages", - "supports_reasoning", - "get_litellm_params", - "acreate", - "get_max_tokens", - "get_model_info", - "register_prompt_template", - "validate_environment", - "check_valid_key", - "register_model", - "encode", - "decode", - "calculate_retry_after", - "_calculate_retry_after", - "should_retry", - "_should_retry", - "get_supported_openai_params", - "get_api_base", - "get_first_chars_messages", - "ModelResponse", - "ModelResponseStream", - "EmbeddingResponse", - "ImageResponse", - "TranscriptionResponse", - "TextCompletionResponse", - "get_provider_fields", - "ModelResponseListIterator", - "get_valid_models", - "timeout", - "get_llm_provider", - "remove_index_from_tool_calls", -) - -# Token counter names that support lazy loading via _lazy_import_token_counter -TOKEN_COUNTER_NAMES: Final = ("get_modified_max_tokens",) - -# LLM client cache names that support lazy loading via _lazy_import_llm_client_cache -LLM_CLIENT_CACHE_NAMES: Final = ( - "LLMClientCache", - "in_memory_llm_clients_cache", -) - -# Bedrock type names that support lazy loading via _lazy_import_bedrock_types -BEDROCK_TYPES_NAMES: Final = ("COHERE_EMBEDDING_INPUT_TYPES",) - -# Common types from litellm.types.utils that support lazy loading via -# _lazy_import_types_utils -TYPES_UTILS_NAMES: Final = ( - "ImageObject", - "BudgetConfig", - "all_litellm_params", - "_litellm_completion_params", - "CredentialItem", - "PriorityReservationDict", - "StandardKeyGenerationConfig", - "SearchProviders", - "GenericStreamingChunk", -) - -# Caching / cache classes that support lazy loading via _lazy_import_caching -CACHING_NAMES: Final = ( - "Cache", - "DualCache", - "RedisCache", - "InMemoryCache", -) - -# HTTP handler names that support lazy loading via _lazy_import_http_handlers -HTTP_HANDLER_NAMES: Final = ( - "module_level_aclient", - "module_level_client", -) - -# Dotprompt integration names that support lazy loading via _lazy_import_dotprompt -DOTPROMPT_NAMES: Final = ( - "global_prompt_manager", - "global_prompt_directory", - "set_global_prompt_directory", -) - -# LLM config classes that support lazy loading via _lazy_import_llm_configs -LLM_CONFIG_NAMES: Final = ( - "AmazonConverseConfig", - "OpenAILikeChatConfig", - "GaladrielChatConfig", - "GithubChatConfig", - "AzureAnthropicConfig", - "BytezChatConfig", - "CompactifAIChatConfig", - "EmpowerChatConfig", - "MinimaxChatConfig", - "AiohttpOpenAIChatConfig", - "HuggingFaceChatConfig", - "HuggingFaceEmbeddingConfig", - "OobaboogaConfig", - "MaritalkConfig", - "OpenrouterConfig", - "DataRobotConfig", - "AnthropicConfig", - "BedrockClaudePlatformConfig", - "AnthropicTextConfig", - "GroqSTTConfig", - "TritonConfig", - "TritonGenerateConfig", - "TritonInferConfig", - "TritonEmbeddingConfig", - "HuggingFaceRerankConfig", - "DatabricksConfig", - "DatabricksEmbeddingConfig", - "PredibaseConfig", - "ReplicateConfig", - "SnowflakeConfig", - "CohereRerankConfig", - "CohereRerankV2Config", - "AzureAIRerankConfig", - "InfinityRerankConfig", - "JinaAIRerankConfig", - "ScalewayRerankConfig", - "DeepinfraRerankConfig", - "HostedVLLMRerankConfig", - "PerplexityDecisionsConfig", - "TypeSafeDecisionsConfig", - "ParallelAIDecisionsConfig", - "NaceDecisionsConfig", - "OpenRouterDecisionsConfig", - "FireworksAIDecisionsConfig", - "CloudflareDecisionsConfig", - "CloudflareExtractionConfig", - "StrandsDeciderDecisionsConfig", - "DatabricksDecisionsConfig", - "HostedVLLMDecisionsConfig", - "LMStudioDecisionsConfig", - "OllamaDecisionsConfig", - "LayaDecisionsConfig", - "BespokeDecisionsConfig", - "EmpirioLabsDecisionsConfig", - "EuJevDecisionsConfig", - "OpenAIDecisionsConfig", - "AzureDecisionsConfig", - "AzureAIDecisionsConfig", - "NvidiaNimRerankConfig", - "NvidiaNimRankingConfig", - "VertexAIRerankConfig", - "FireworksAIRerankConfig", - "VoyageRerankConfig", - "IBMWatsonXRerankConfig", - "ClarifaiConfig", - "AI21ChatConfig", - "LlamaAPIConfig", - "TogetherAITextCompletionConfig", - "CloudflareChatConfig", - "NovitaConfig", - "PetalsConfig", - "OllamaChatConfig", - "OllamaConfig", - "SagemakerConfig", - "SagemakerChatConfig", - "SagemakerNovaConfig", - "CohereChatConfig", - "AnthropicMessagesConfig", - "BedrockClaudePlatformMessagesConfig", - "AmazonAnthropicClaudeMessagesConfig", - "AmazonMantleMessagesConfig", - "BedrockMantleAnthropicMessagesConfig", - "TogetherAIConfig", - "TogetherAIChatConfig", - "NLPCloudConfig", - "VertexGeminiConfig", - "GoogleAIStudioGeminiConfig", - "VertexAIAnthropicConfig", - "VertexAILlama3Config", - "VertexAIAi21Config", - "VertexAIMistralConfig", - "AmazonCohereChatConfig", - "AmazonBedrockGlobalConfig", - "AmazonAI21Config", - "AmazonInvokeNovaConfig", - "AmazonQwen2Config", - "AmazonQwen3Config", - # Aliases for backwards compatibility - "VertexAIConfig", # Alias for VertexGeminiConfig - "GeminiConfig", # Alias for GoogleAIStudioGeminiConfig - "AmazonAnthropicConfig", - "AmazonAnthropicClaudeConfig", - "AmazonCohereConfig", - "AmazonLlamaConfig", - "AmazonDeepSeekR1Config", - "AmazonMistralConfig", - "AmazonMoonshotConfig", - "AmazonTitanConfig", - "AmazonTwelveLabsPegasusConfig", - "AmazonInvokeConfig", - "AmazonBedrockOpenAIConfig", - "AmazonBedrockRuntimeChatCompletionsConfig", - "AmazonStabilityConfig", - "AmazonStability3Config", - "AmazonNovaCanvasConfig", - "AmazonTitanG1Config", - "AmazonTitanMultimodalEmbeddingG1Config", - "CohereV2ChatConfig", - "BedrockCohereEmbeddingConfig", - "TwelveLabsMarengoEmbeddingConfig", - "AmazonNovaEmbeddingConfig", - "OpenAIConfig", - "MistralEmbeddingConfig", - "OpenAIImageVariationConfig", - "DeepInfraConfig", - "ClfAiGatewayConfig", - "DeepgramAudioTranscriptionConfig", - "TopazImageVariationConfig", - "OpenAITextCompletionConfig", - "GroqChatConfig", - "BedrockMantleChatConfig", - "A2AConfig", - "GenAIHubOrchestrationConfig", - "VoyageEmbeddingConfig", - "VoyageContextualEmbeddingConfig", - "VoyageMultimodalEmbeddingConfig", - "InfinityEmbeddingConfig", - "PerplexityEmbeddingConfig", - "AzureAIStudioConfig", - "MistralConfig", - "OpenAIResponsesAPIConfig", - "AzureOpenAIResponsesAPIConfig", - "AzureOpenAIOSeriesResponsesAPIConfig", - "AzureAIResponsesAPIConfig", - "XAIResponsesAPIConfig", - "LiteLLMProxyResponsesAPIConfig", - "HostedVLLMResponsesAPIConfig", - "FireworksAIResponsesAPIConfig", - "VolcEngineResponsesAPIConfig", - "PerplexityResponsesConfig", - "DatabricksResponsesAPIConfig", - "OpenRouterResponsesAPIConfig", - "BedrockOpenAIResponsesConfig", - "BedrockMantleResponsesAPIConfig", - "GoogleAIStudioInteractionsConfig", - "VertexAIInteractionsConfig", - "OpenAIOSeriesConfig", - "AnthropicSkillsConfig", - "BaseSkillsAPIConfig", - "GradientAIConfig", - # Alias for backwards compatibility - "OpenAIO1Config", # Alias for OpenAIOSeriesConfig - "OpenAIGPTConfig", - "OpenAIGPT5Config", - "OpenAIWhisperAudioTranscriptionConfig", - "OpenAIGPTAudioTranscriptionConfig", - "OpenAIGPTAudioConfig", - "NvidiaNimConfig", - "NvidiaNimEmbeddingConfig", - "FeatherlessAIConfig", - "ScaleDownChatConfig", - "CerebrasConfig", - "NadirConfig", - "BasetenConfig", - "SambanovaConfig", - "SambaNovaEmbeddingConfig", - "FireworksAIConfig", - "FireworksAITextCompletionConfig", - "FireworksAIEmbeddingConfig", - "FriendliaiChatConfig", - "JinaAIEmbeddingConfig", - "XAIChatConfig", - "ZAIChatConfig", - "AIMLChatConfig", - "VolcEngineChatConfig", - "CodestralTextCompletionConfig", - "InceptionTextCompletionConfig", - "AzureOpenAIAssistantsAPIConfig", - "HerokuChatConfig", - "CometAPIConfig", - "AzureOpenAIConfig", - "AzureOpenAIGPT5Config", - "AzureOpenAITextConfig", - "AzureSpeechAudioTranscriptionConfig", - "HostedVLLMChatConfig", - "HostedVLLMEmbeddingConfig", - # Alias for backwards compatibility - "VolcEngineConfig", # Alias for VolcEngineChatConfig - "LlamafileChatConfig", - "LiteLLMProxyChatConfig", - "VLLMConfig", - "DeepSeekChatConfig", - "TencentChatConfig", - "LMStudioChatConfig", - "LmStudioEmbeddingConfig", - "NscaleConfig", - "PerplexityChatConfig", - "AzureOpenAIO1Config", - "IBMWatsonXAIConfig", - "IBMWatsonXChatConfig", - "IBMWatsonXEmbeddingConfig", - "GenAIHubEmbeddingConfig", - "IBMWatsonXAudioTranscriptionConfig", - "GithubCopilotConfig", - "GithubCopilotResponsesAPIConfig", - "ChatGPTConfig", - "ChatGPTResponsesAPIConfig", - "ManusResponsesAPIConfig", - "GithubCopilotEmbeddingConfig", - "NebiusConfig", - "WandbConfig", - "GigaChatConfig", - "GigaChatEmbeddingConfig", - "DashScopeChatConfig", - "QwenCloudChatConfig", - "QwenAIPlatformChatConfig", - "ModelScopeChatConfig", - "MoonshotChatConfig", - "DockerModelRunnerChatConfig", - "V0ChatConfig", - "OCIChatConfig", - "MorphChatConfig", - "RAGFlowConfig", - "LambdaAIChatConfig", - "InceptionChatConfig", - "HyperbolicChatConfig", - "VercelAIGatewayConfig", - "EdenAIChatConfig", - "EdenAIResponsesAPIConfig", - "EdenAIAnthropicMessagesConfig", - "EdenAIEmbeddingConfig", - "EdenAIAudioTranscriptionConfig", - "EdenAITextToSpeechConfig", - "EdenAIImageGenerationConfig", - "EdenAIVideoConfig", - "FalAIChatConfig", - "FalAIError", - "OVHCloudChatConfig", - "OVHCloudEmbeddingConfig", - "CometAPIEmbeddingConfig", - "LemonadeChatConfig", - "SnowflakeEmbeddingConfig", - "AmazonNovaChatConfig", - "SonioxAudioTranscriptionConfig", - "GDCGeminiConfig", -) - -# Types that support lazy loading via _lazy_import_types -TYPES_NAMES: Final = ( - "GuardrailItem", - "DefaultTeamSSOParams", - "LiteLLM_UpperboundKeyGenerateParams", - "KeyManagementSystem", - "PriorityReservationSettings", - "CustomLogger", - "LoggingCallbackManager", - "DatadogLLMObsInitParams", - # Note: LlmProviders is NOT lazy-loaded because it's imported during import time - # in multiple places including openai.py (via main import) - # Note: KeyManagementSettings is NOT lazy-loaded because _key_management_settings - # is accessed during import time in secret_managers/main.py -) - -# LLM provider logic names that support lazy loading via _lazy_import_llm_provider_logic -LLM_PROVIDER_LOGIC_NAMES: Final = ( - "get_llm_provider", - "remove_index_from_tool_calls", -) - -# Utils module names that support lazy loading via _lazy_import_utils_module -# These are attributes accessed from litellm.utils module -UTILS_MODULE_NAMES: Final = ( - "encoding", - "BaseVectorStore", - "CredentialAccessor", - "exception_type", - "get_error_message", - "_get_response_headers", - "get_llm_provider", - "_is_non_openai_azure_model", - "is_non_openai_azure_model", - "get_supported_openai_params", - "LiteLLMResponseObjectHandler", - "_handle_invalid_parallel_tool_calls", - "handle_invalid_parallel_tool_calls", - "convert_to_model_response_object", - "convert_to_streaming_response", - "convert_to_streaming_response_async", - "get_api_base", - "ResponseMetadata", - "_parse_content_for_reasoning", - "parse_content_for_reasoning", - "LiteLLMLoggingObject", - "redact_message_input_output_from_logging", - "CustomStreamWrapper", - "BaseGoogleGenAIGenerateContentConfig", - "BaseSearchConfig", - "BaseTextToSpeechConfig", - "BedrockModelInfo", - "CohereModelInfo", - "Rules", - "AsyncHTTPHandler", - "HTTPHandler", - "get_num_retries_from_retry_policy", - "reset_retry_policy", - "get_coroutine_checker", - "get_litellm_logging_class", - "get_set_callbacks", - "get_litellm_metadata_from_kwargs", - "map_finish_reason", - "process_response_headers", - "delete_nested_value", - "is_nested_path", - "_get_base_model_from_litellm_call_metadata", - "get_base_model_from_litellm_call_metadata", - "get_litellm_params", - "_ensure_extra_body_is_safe", - "ensure_extra_body_is_safe", - "get_formatted_prompt", - "get_response_headers", - "update_response_metadata", - "executor", - "BaseAnthropicMessagesConfig", - "BaseAudioTranscriptionConfig", - "BaseBatchesConfig", - "BaseContainerConfig", - "BaseEmbeddingConfig", - "BaseImageEditConfig", - "BaseImageGenerationConfig", - "BaseImageVariationConfig", - "BasePassthroughConfig", - "BaseRealtimeConfig", - "BaseRerankConfig", - "BaseVectorStoreConfig", - "BaseVectorStoreFilesConfig", - "BaseVideoConfig", - "ANTHROPIC_API_ONLY_HEADERS", - "AnthropicThinkingParam", - "RerankResponse", - "ChatCompletionDeltaToolCallChunk", - "ChatCompletionToolCallChunk", - "ChatCompletionToolCallFunctionChunk", - "LiteLLM_Params", -) - -# Import maps for registry pattern - reduces repetition -_UTILS_IMPORT_MAP: Final = { - "run_server": ("litellm.proxy.proxy_cli", "run_server"), - "exception_type": (".utils", "exception_type"), - "get_optional_params": (".utils", "get_optional_params"), - "get_response_string": (".utils", "get_response_string"), - "token_counter": (".utils", "token_counter"), - "create_pretrained_tokenizer": (".utils", "create_pretrained_tokenizer"), - "create_tokenizer": (".utils", "create_tokenizer"), - "supports_function_calling": (".utils", "supports_function_calling"), - "supports_web_search": (".utils", "supports_web_search"), - "supports_tool_search": (".utils", "supports_tool_search"), - "supports_url_context": (".utils", "supports_url_context"), - "supports_continuation": (".utils", "supports_continuation"), - "supports_response_schema": (".utils", "supports_response_schema"), - "supports_parallel_function_calling": ( - ".utils", - "supports_parallel_function_calling", - ), - "supports_vision": (".utils", "supports_vision"), - "supports_audio_input": (".utils", "supports_audio_input"), - "supports_video_input": (".utils", "supports_video_input"), - "supports_box_questions": (".utils", "supports_box_questions"), - "supports_audio_output": (".utils", "supports_audio_output"), - "supports_system_messages": (".utils", "supports_system_messages"), - "supports_reasoning": (".utils", "supports_reasoning"), - "get_litellm_params": (".utils", "get_litellm_params"), - "acreate": (".utils", "acreate"), - "get_max_tokens": (".utils", "get_max_tokens"), - "get_model_info": (".utils", "get_model_info"), - "register_prompt_template": (".utils", "register_prompt_template"), - "validate_environment": (".utils", "validate_environment"), - "check_valid_key": (".utils", "check_valid_key"), - "register_model": (".utils", "register_model"), - "encode": (".utils", "encode"), - "decode": (".utils", "decode"), - "calculate_retry_after": (".utils", "calculate_retry_after"), - "_calculate_retry_after": (".utils", "calculate_retry_after"), - "should_retry": (".utils", "should_retry"), - "_should_retry": (".utils", "should_retry"), - "get_supported_openai_params": (".utils", "get_supported_openai_params"), - "get_api_base": (".utils", "get_api_base"), - "get_first_chars_messages": (".utils", "get_first_chars_messages"), - "ModelResponse": (".utils", "ModelResponse"), - "ModelResponseStream": (".utils", "ModelResponseStream"), - "EmbeddingResponse": (".utils", "EmbeddingResponse"), - "ImageResponse": (".utils", "ImageResponse"), - "TranscriptionResponse": (".utils", "TranscriptionResponse"), - "TextCompletionResponse": (".utils", "TextCompletionResponse"), - "get_provider_fields": (".utils", "get_provider_fields"), - "ModelResponseListIterator": (".utils", "ModelResponseListIterator"), - "get_valid_models": (".utils", "get_valid_models"), - "timeout": (".timeout", "timeout"), - "get_llm_provider": ( - "litellm.litellm_core_utils.get_llm_provider_logic", - "get_llm_provider", - ), - "remove_index_from_tool_calls": ( - "litellm.litellm_core_utils.core_helpers", - "remove_index_from_tool_calls", - ), -} - -_COST_CALCULATOR_IMPORT_MAP: Final = { - "completion_cost": (".cost_calculator", "completion_cost"), - "cost_per_token": (".cost_calculator", "cost_per_token"), - "response_cost_calculator": (".cost_calculator", "response_cost_calculator"), -} - -_TYPES_UTILS_IMPORT_MAP: Final = { - "ImageObject": (".types.utils", "ImageObject"), - "BudgetConfig": (".types.utils", "BudgetConfig"), - "all_litellm_params": (".types.utils", "all_litellm_params"), - "_litellm_completion_params": (".types.utils", "all_litellm_params"), # Alias - "CredentialItem": (".types.utils", "CredentialItem"), - "PriorityReservationDict": (".types.utils", "PriorityReservationDict"), - "StandardKeyGenerationConfig": (".types.utils", "StandardKeyGenerationConfig"), - "SearchProviders": (".types.utils", "SearchProviders"), - "GenericStreamingChunk": (".types.utils", "GenericStreamingChunk"), -} - -_TOKEN_COUNTER_IMPORT_MAP: Final = { - "get_modified_max_tokens": ( - "litellm.litellm_core_utils.token_counter", - "get_modified_max_tokens", - ), -} - -_BEDROCK_TYPES_IMPORT_MAP: Final = { - "COHERE_EMBEDDING_INPUT_TYPES": ( - "litellm.types.llms.bedrock", - "COHERE_EMBEDDING_INPUT_TYPES", - ), -} - -_CACHING_IMPORT_MAP: Final = { - "Cache": ("litellm.caching.caching", "Cache"), - "DualCache": ("litellm.caching.caching", "DualCache"), - "RedisCache": ("litellm.caching.caching", "RedisCache"), - "InMemoryCache": ("litellm.caching.caching", "InMemoryCache"), -} - -_LITELLM_LOGGING_IMPORT_MAP: Final = { - "Logging": ("litellm.litellm_core_utils.litellm_logging", "Logging"), - "modify_integration": ( - "litellm.litellm_core_utils.litellm_logging", - "modify_integration", - ), -} - -_DOTPROMPT_IMPORT_MAP: Final = { - "global_prompt_manager": ( - "litellm.integrations.dotprompt", - "global_prompt_manager", - ), - "global_prompt_directory": ( - "litellm.integrations.dotprompt", - "global_prompt_directory", - ), - "set_global_prompt_directory": ( - "litellm.integrations.dotprompt", - "set_global_prompt_directory", - ), -} - -_TYPES_IMPORT_MAP: Final = { - "GuardrailItem": ("litellm.types.guardrails", "GuardrailItem"), - "DefaultTeamSSOParams": ( - "litellm.types.proxy.management_endpoints.ui_sso", - "DefaultTeamSSOParams", - ), - "LiteLLM_UpperboundKeyGenerateParams": ( - "litellm.types.proxy.management_endpoints.ui_sso", - "LiteLLM_UpperboundKeyGenerateParams", - ), - "KeyManagementSystem": ( - "litellm.types.secret_managers.main", - "KeyManagementSystem", - ), - "PriorityReservationSettings": ( - "litellm.types.utils", - "PriorityReservationSettings", - ), - "CustomLogger": ("litellm.integrations.custom_logger", "CustomLogger"), - "LoggingCallbackManager": ( - "litellm.litellm_core_utils.logging_callback_manager", - "LoggingCallbackManager", - ), - "DatadogLLMObsInitParams": ( - "litellm.types.integrations.datadog_llm_obs", - "DatadogLLMObsInitParams", - ), -} - -_LLM_PROVIDER_LOGIC_IMPORT_MAP: Final = { - "get_llm_provider": ( - "litellm.litellm_core_utils.get_llm_provider_logic", - "get_llm_provider", - ), - "remove_index_from_tool_calls": ( - "litellm.litellm_core_utils.core_helpers", - "remove_index_from_tool_calls", - ), -} - -_LLM_CONFIGS_IMPORT_MAP: Final = { - "AmazonConverseConfig": ( - ".llms.bedrock.chat.converse_transformation", - "AmazonConverseConfig", - ), - "OpenAILikeChatConfig": (".llms.openai_like.chat.handler", "OpenAILikeChatConfig"), - "GaladrielChatConfig": ( - ".llms.galadriel.chat.transformation", - "GaladrielChatConfig", - ), - "GithubChatConfig": (".llms.github.chat.transformation", "GithubChatConfig"), - "AzureAnthropicConfig": ( - ".llms.azure_ai.anthropic.transformation", - "AzureAnthropicConfig", - ), - "BytezChatConfig": (".llms.bytez.chat.transformation", "BytezChatConfig"), - "CompactifAIChatConfig": ( - ".llms.compactifai.chat.transformation", - "CompactifAIChatConfig", - ), - "EmpowerChatConfig": (".llms.empower.chat.transformation", "EmpowerChatConfig"), - "MinimaxChatConfig": (".llms.minimax.chat.transformation", "MinimaxChatConfig"), - "AiohttpOpenAIChatConfig": ( - ".llms.aiohttp_openai.chat.transformation", - "AiohttpOpenAIChatConfig", - ), - "HuggingFaceChatConfig": ( - ".llms.huggingface.chat.transformation", - "HuggingFaceChatConfig", - ), - "HuggingFaceEmbeddingConfig": ( - ".llms.huggingface.embedding.transformation", - "HuggingFaceEmbeddingConfig", - ), - "OobaboogaConfig": (".llms.oobabooga.chat.transformation", "OobaboogaConfig"), - "MaritalkConfig": (".llms.maritalk", "MaritalkConfig"), - "OpenrouterConfig": (".llms.openrouter.chat.transformation", "OpenrouterConfig"), - "DataRobotConfig": (".llms.datarobot.chat.transformation", "DataRobotConfig"), - "AnthropicConfig": (".llms.anthropic.chat.transformation", "AnthropicConfig"), - "BedrockClaudePlatformConfig": ( - ".llms.bedrock.claude_platform.transformation", - "BedrockClaudePlatformConfig", - ), - "AnthropicTextConfig": ( - ".llms.anthropic.completion.transformation", - "AnthropicTextConfig", - ), - "GroqSTTConfig": (".llms.groq.stt.transformation", "GroqSTTConfig"), - "TritonConfig": (".llms.triton.completion.transformation", "TritonConfig"), - "TritonGenerateConfig": ( - ".llms.triton.completion.transformation", - "TritonGenerateConfig", - ), - "TritonInferConfig": ( - ".llms.triton.completion.transformation", - "TritonInferConfig", - ), - "TritonEmbeddingConfig": ( - ".llms.triton.embedding.transformation", - "TritonEmbeddingConfig", - ), - "HuggingFaceRerankConfig": ( - ".llms.huggingface.rerank.transformation", - "HuggingFaceRerankConfig", - ), - "DatabricksConfig": (".llms.databricks.chat.transformation", "DatabricksConfig"), - "DatabricksEmbeddingConfig": ( - ".llms.databricks.embed.transformation", - "DatabricksEmbeddingConfig", - ), - "PredibaseConfig": (".llms.predibase.chat.transformation", "PredibaseConfig"), - "ReplicateConfig": (".llms.replicate.chat.transformation", "ReplicateConfig"), - "SnowflakeConfig": (".llms.snowflake.chat.transformation", "SnowflakeConfig"), - "CohereRerankConfig": (".llms.cohere.rerank.transformation", "CohereRerankConfig"), - "CohereRerankV2Config": ( - ".llms.cohere.rerank_v2.transformation", - "CohereRerankV2Config", - ), - "AzureAIRerankConfig": ( - ".llms.azure_ai.rerank.transformation", - "AzureAIRerankConfig", - ), - "InfinityRerankConfig": ( - ".llms.infinity.rerank.transformation", - "InfinityRerankConfig", - ), - "JinaAIRerankConfig": (".llms.jina_ai.rerank.transformation", "JinaAIRerankConfig"), - "ScalewayRerankConfig": (".llms.scaleway.rerank.transformation", "ScalewayRerankConfig"), - "DeepinfraRerankConfig": ( - ".llms.deepinfra.rerank.transformation", - "DeepinfraRerankConfig", - ), - "HostedVLLMRerankConfig": ( - ".llms.hosted_vllm.rerank.transformation", - "HostedVLLMRerankConfig", - ), - "PerplexityDecisionsConfig": (".llms.perplexity.decisions.transformation", "PerplexityDecisionsConfig"), - "NaceDecisionsConfig": (".llms.nace.decisions.transformation", "NaceDecisionsConfig"), - "TypeSafeDecisionsConfig": (".llms.typesafe.decisions.transformation", "TypeSafeDecisionsConfig"), - "ParallelAIDecisionsConfig": (".llms.parallel_ai.decisions.transformation", "ParallelAIDecisionsConfig"), - "OpenRouterDecisionsConfig": (".llms.openrouter.decisions.transformation", "OpenRouterDecisionsConfig"), - "FireworksAIDecisionsConfig": (".llms.fireworks_ai.decisions.transformation", "FireworksAIDecisionsConfig"), - "CloudflareDecisionsConfig": (".llms.cloudflare.decisions.transformation", "CloudflareDecisionsConfig"), - "CloudflareExtractionConfig": (".llms.cloudflare.extraction.transformation", "CloudflareExtractionConfig"), - "StrandsDeciderDecisionsConfig": ( - ".llms.strands_decider.decisions.transformation", - "StrandsDeciderDecisionsConfig", - ), - "DatabricksDecisionsConfig": (".llms.databricks.decisions.transformation", "DatabricksDecisionsConfig"), - "HostedVLLMDecisionsConfig": ( - ".llms.hosted_vllm.decisions.transformation", - "HostedVLLMDecisionsConfig", - ), - "LMStudioDecisionsConfig": (".llms.lm_studio.decisions.transformation", "LMStudioDecisionsConfig"), - "OllamaDecisionsConfig": (".llms.ollama.decisions.transformation", "OllamaDecisionsConfig"), - "LayaDecisionsConfig": (".llms.laya.decisions.transformation", "LayaDecisionsConfig"), - "BespokeDecisionsConfig": (".llms.bespoke.decisions.transformation", "BespokeDecisionsConfig"), - "EmpirioLabsDecisionsConfig": (".llms.empiriolabs.decisions.transformation", "EmpirioLabsDecisionsConfig"), - "EuJevDecisionsConfig": (".llms.eu_jev.decisions.transformation", "EuJevDecisionsConfig"), - "OpenAIDecisionsConfig": (".llms.openai.decisions.transformation", "OpenAIDecisionsConfig"), - "AzureDecisionsConfig": (".llms.azure.decisions.transformation", "AzureDecisionsConfig"), - "AzureAIDecisionsConfig": (".llms.azure_ai.decisions.transformation", "AzureAIDecisionsConfig"), - "NvidiaNimRerankConfig": ( - ".llms.nvidia_nim.rerank.transformation", - "NvidiaNimRerankConfig", - ), - "NvidiaNimRankingConfig": ( - ".llms.nvidia_nim.rerank.ranking_transformation", - "NvidiaNimRankingConfig", - ), - "VertexAIRerankConfig": ( - ".llms.vertex_ai.rerank.transformation", - "VertexAIRerankConfig", - ), - "FireworksAIRerankConfig": ( - ".llms.fireworks_ai.rerank.transformation", - "FireworksAIRerankConfig", - ), - "VoyageRerankConfig": (".llms.voyage.rerank.transformation", "VoyageRerankConfig"), - "IBMWatsonXRerankConfig": ( - ".llms.watsonx.rerank.transformation", - "IBMWatsonXRerankConfig", - ), - "ClarifaiConfig": (".llms.clarifai.chat.transformation", "ClarifaiConfig"), - "AI21ChatConfig": (".llms.ai21.chat.transformation", "AI21ChatConfig"), - "LlamaAPIConfig": (".llms.meta_llama.chat.transformation", "LlamaAPIConfig"), - "TogetherAITextCompletionConfig": ( - ".llms.together_ai.completion.transformation", - "TogetherAITextCompletionConfig", - ), - "CloudflareChatConfig": ( - ".llms.cloudflare.chat.transformation", - "CloudflareChatConfig", - ), - "NovitaConfig": (".llms.novita.chat.transformation", "NovitaConfig"), - "PetalsConfig": (".llms.petals.completion.transformation", "PetalsConfig"), - "OllamaChatConfig": (".llms.ollama.chat.transformation", "OllamaChatConfig"), - "OllamaConfig": (".llms.ollama.completion.transformation", "OllamaConfig"), - "SagemakerConfig": (".llms.sagemaker.completion.transformation", "SagemakerConfig"), - "SagemakerChatConfig": ( - ".llms.sagemaker.chat.transformation", - "SagemakerChatConfig", - ), - "SagemakerNovaConfig": ( - ".llms.sagemaker.nova.transformation", - "SagemakerNovaConfig", - ), - "CohereChatConfig": (".llms.cohere.chat.transformation", "CohereChatConfig"), - "AnthropicMessagesConfig": ( - ".llms.anthropic.messages.native.transformation", - "AnthropicMessagesConfig", - ), - "BedrockClaudePlatformMessagesConfig": ( - ".llms.bedrock.claude_platform.messages_transformation", - "BedrockClaudePlatformMessagesConfig", - ), - "AmazonAnthropicClaudeMessagesConfig": ( - ".llms.bedrock.messages.invoke_transformations.anthropic_claude_transformation", - "AmazonAnthropicClaudeMessagesConfig", - ), - "AmazonMantleMessagesConfig": ( - ".llms.bedrock.messages.mantle_transformation", - "AmazonMantleMessagesConfig", - ), - "BedrockMantleAnthropicMessagesConfig": ( - ".llms.bedrock_mantle.messages.transformation", - "BedrockMantleAnthropicMessagesConfig", - ), - "TogetherAIConfig": (".llms.together_ai.chat", "TogetherAIConfig"), - "TogetherAIChatConfig": ( - ".llms.together_ai.chat.transformation", - "TogetherAIChatConfig", - ), - "NLPCloudConfig": (".llms.nlp_cloud.chat.handler", "NLPCloudConfig"), - "VertexGeminiConfig": ( - ".llms.vertex_ai.gemini.vertex_and_google_ai_studio_gemini", - "VertexGeminiConfig", - ), - "GoogleAIStudioGeminiConfig": ( - ".llms.gemini.chat.transformation", - "GoogleAIStudioGeminiConfig", - ), - "VertexAIAnthropicConfig": ( - ".llms.vertex_ai.vertex_ai_partner_models.anthropic.transformation", - "VertexAIAnthropicConfig", - ), - "VertexAILlama3Config": ( - ".llms.vertex_ai.vertex_ai_partner_models.llama.transformation", - "VertexAILlama3Config", - ), - "VertexAIAi21Config": ( - ".llms.vertex_ai.vertex_ai_partner_models.ai21.transformation", - "VertexAIAi21Config", - ), - "VertexAIMistralConfig": ( - ".llms.vertex_ai.vertex_ai_partner_models.mistral.transformation", - "VertexAIMistralConfig", - ), - "AmazonCohereChatConfig": ( - ".llms.bedrock.chat.invoke_handler", - "AmazonCohereChatConfig", - ), - "AmazonBedrockGlobalConfig": ( - ".llms.bedrock.common_utils", - "AmazonBedrockGlobalConfig", - ), - "AmazonAI21Config": ( - ".llms.bedrock.chat.invoke_transformations.amazon_ai21_transformation", - "AmazonAI21Config", - ), - "AmazonInvokeNovaConfig": ( - ".llms.bedrock.chat.invoke_transformations.amazon_nova_transformation", - "AmazonInvokeNovaConfig", - ), - "AmazonQwen2Config": ( - ".llms.bedrock.chat.invoke_transformations.amazon_qwen2_transformation", - "AmazonQwen2Config", - ), - "AmazonQwen3Config": ( - ".llms.bedrock.chat.invoke_transformations.amazon_qwen3_transformation", - "AmazonQwen3Config", - ), - # Aliases for backwards compatibility - "VertexAIConfig": ( - ".llms.vertex_ai.gemini.vertex_and_google_ai_studio_gemini", - "VertexGeminiConfig", - ), # Alias - "GeminiConfig": ( - ".llms.gemini.chat.transformation", - "GoogleAIStudioGeminiConfig", - ), # Alias - "AmazonAnthropicConfig": ( - ".llms.bedrock.chat.invoke_transformations.anthropic_legacy_text_completions_transformation", - "AmazonAnthropicConfig", - ), - "AmazonAnthropicClaudeConfig": ( - ".llms.bedrock.chat.invoke_transformations.anthropic_claude_transformation", - "AmazonAnthropicClaudeConfig", - ), - "AmazonCohereConfig": ( - ".llms.bedrock.chat.invoke_transformations.amazon_cohere_transformation", - "AmazonCohereConfig", - ), - "AmazonLlamaConfig": ( - ".llms.bedrock.chat.invoke_transformations.amazon_llama_transformation", - "AmazonLlamaConfig", - ), - "AmazonDeepSeekR1Config": ( - ".llms.bedrock.chat.invoke_transformations.amazon_deepseek_transformation", - "AmazonDeepSeekR1Config", - ), - "AmazonMistralConfig": ( - ".llms.bedrock.chat.invoke_transformations.amazon_mistral_transformation", - "AmazonMistralConfig", - ), - "AmazonMoonshotConfig": ( - ".llms.bedrock.chat.invoke_transformations.amazon_moonshot_transformation", - "AmazonMoonshotConfig", - ), - "AmazonTitanConfig": ( - ".llms.bedrock.chat.invoke_transformations.amazon_titan_transformation", - "AmazonTitanConfig", - ), - "AmazonTwelveLabsPegasusConfig": ( - ".llms.bedrock.chat.invoke_transformations.amazon_twelvelabs_pegasus_transformation", - "AmazonTwelveLabsPegasusConfig", - ), - "AmazonInvokeConfig": ( - ".llms.bedrock.chat.invoke_transformations.base_invoke_transformation", - "AmazonInvokeConfig", - ), - "AmazonBedrockOpenAIConfig": ( - ".llms.bedrock.chat.invoke_transformations.amazon_openai_transformation", - "AmazonBedrockOpenAIConfig", - ), - "AmazonBedrockRuntimeChatCompletionsConfig": ( - ".llms.bedrock.chat.chat_completions.transformation", - "AmazonBedrockRuntimeChatCompletionsConfig", - ), - "AmazonStabilityConfig": ( - ".llms.bedrock.image_generation.amazon_stability1_transformation", - "AmazonStabilityConfig", - ), - "AmazonStability3Config": ( - ".llms.bedrock.image_generation.amazon_stability3_transformation", - "AmazonStability3Config", - ), - "AmazonNovaCanvasConfig": ( - ".llms.bedrock.image_generation.amazon_nova_canvas_transformation", - "AmazonNovaCanvasConfig", - ), - "AmazonTitanG1Config": ( - ".llms.bedrock.embed.amazon_titan_g1_transformation", - "AmazonTitanG1Config", - ), - "AmazonTitanMultimodalEmbeddingG1Config": ( - ".llms.bedrock.embed.amazon_titan_multimodal_transformation", - "AmazonTitanMultimodalEmbeddingG1Config", - ), - "CohereV2ChatConfig": (".llms.cohere.chat.v2_transformation", "CohereV2ChatConfig"), - "BedrockCohereEmbeddingConfig": ( - ".llms.bedrock.embed.cohere_transformation", - "BedrockCohereEmbeddingConfig", - ), - "TwelveLabsMarengoEmbeddingConfig": ( - ".llms.bedrock.embed.twelvelabs_marengo_transformation", - "TwelveLabsMarengoEmbeddingConfig", - ), - "AmazonNovaEmbeddingConfig": ( - ".llms.bedrock.embed.amazon_nova_transformation", - "AmazonNovaEmbeddingConfig", - ), - "OpenAIConfig": (".llms.openai.openai", "OpenAIConfig"), - "MistralEmbeddingConfig": (".llms.openai.openai", "MistralEmbeddingConfig"), - "OpenAIImageVariationConfig": ( - ".llms.openai.image_variations.transformation", - "OpenAIImageVariationConfig", - ), - "DeepInfraConfig": (".llms.deepinfra.chat.transformation", "DeepInfraConfig"), - "ClfAiGatewayConfig": ( - ".llms.clf_ai_gateway.chat.transformation", - "ClfAiGatewayConfig", - ), - "DeepgramAudioTranscriptionConfig": ( - ".llms.deepgram.audio_transcription.transformation", - "DeepgramAudioTranscriptionConfig", - ), - "TopazImageVariationConfig": ( - ".llms.topaz.image_variations.transformation", - "TopazImageVariationConfig", - ), - "OpenAITextCompletionConfig": ( - "litellm.llms.openai.completion.transformation", - "OpenAITextCompletionConfig", - ), - "GroqChatConfig": (".llms.groq.chat.transformation", "GroqChatConfig"), - "BedrockOpenAIResponsesConfig": ( - ".llms.bedrock.responses.transformation", - "BedrockOpenAIResponsesConfig", - ), - "BedrockMantleChatConfig": ( - ".llms.bedrock_mantle.chat.transformation", - "BedrockMantleChatConfig", - ), - "A2AConfig": (".llms.a2a.chat.transformation", "A2AConfig"), - "GenAIHubOrchestrationConfig": ( - ".llms.sap.chat.transformation", - "GenAIHubOrchestrationConfig", - ), - "VoyageEmbeddingConfig": ( - ".llms.voyage.embedding.transformation", - "VoyageEmbeddingConfig", - ), - "VoyageContextualEmbeddingConfig": ( - ".llms.voyage.embedding.transformation_contextual", - "VoyageContextualEmbeddingConfig", - ), - "VoyageMultimodalEmbeddingConfig": ( - ".llms.voyage.embedding.transformation_multimodal", - "VoyageMultimodalEmbeddingConfig", - ), - "InfinityEmbeddingConfig": ( - ".llms.infinity.embedding.transformation", - "InfinityEmbeddingConfig", - ), - "PerplexityEmbeddingConfig": ( - ".llms.perplexity.embedding.transformation", - "PerplexityEmbeddingConfig", - ), - "AzureAIStudioConfig": ( - ".llms.azure_ai.chat.transformation", - "AzureAIStudioConfig", - ), - "MistralConfig": (".llms.mistral.chat.transformation", "MistralConfig"), - "OpenAIResponsesAPIConfig": ( - ".llms.openai.responses.transformation", - "OpenAIResponsesAPIConfig", - ), - "AzureOpenAIResponsesAPIConfig": ( - ".llms.azure.responses.transformation", - "AzureOpenAIResponsesAPIConfig", - ), - "AzureOpenAIOSeriesResponsesAPIConfig": ( - ".llms.azure.responses.o_series_transformation", - "AzureOpenAIOSeriesResponsesAPIConfig", - ), - "AzureAIResponsesAPIConfig": ( - ".llms.azure_ai.responses.transformation", - "AzureAIResponsesAPIConfig", - ), - "XAIResponsesAPIConfig": ( - ".llms.xai.responses.transformation", - "XAIResponsesAPIConfig", - ), - "LiteLLMProxyResponsesAPIConfig": ( - ".llms.litellm_proxy.responses.transformation", - "LiteLLMProxyResponsesAPIConfig", - ), - "HostedVLLMResponsesAPIConfig": ( - ".llms.hosted_vllm.responses.transformation", - "HostedVLLMResponsesAPIConfig", - ), - "FireworksAIResponsesAPIConfig": ( - ".llms.fireworks_ai.responses.transformation", - "FireworksAIResponsesAPIConfig", - ), - "VolcEngineResponsesAPIConfig": ( - ".llms.volcengine.responses.transformation", - "VolcEngineResponsesAPIConfig", - ), - "ManusResponsesAPIConfig": ( - ".llms.manus.responses.transformation", - "ManusResponsesAPIConfig", - ), - "PerplexityResponsesConfig": ( - ".llms.perplexity.responses.transformation", - "PerplexityResponsesConfig", - ), - "DatabricksResponsesAPIConfig": ( - ".llms.databricks.responses.transformation", - "DatabricksResponsesAPIConfig", - ), - "OpenRouterResponsesAPIConfig": ( - ".llms.openrouter.responses.transformation", - "OpenRouterResponsesAPIConfig", - ), - "BedrockMantleResponsesAPIConfig": ( - ".llms.bedrock_mantle.responses.transformation", - "BedrockMantleResponsesAPIConfig", - ), - "GoogleAIStudioInteractionsConfig": ( - ".llms.gemini.interactions.transformation", - "GoogleAIStudioInteractionsConfig", - ), - "VertexAIInteractionsConfig": ( - ".llms.vertex_ai.interactions.transformation", - "VertexAIInteractionsConfig", - ), - "OpenAIOSeriesConfig": ( - ".llms.openai.chat.o_series_transformation", - "OpenAIOSeriesConfig", - ), - "AnthropicSkillsConfig": ( - ".llms.anthropic.skills.transformation", - "AnthropicSkillsConfig", - ), - "BaseSkillsAPIConfig": ( - ".llms.base_llm.skills.transformation", - "BaseSkillsAPIConfig", - ), - "GradientAIConfig": (".llms.gradient_ai.chat.transformation", "GradientAIConfig"), - # Alias for backwards compatibility - "OpenAIO1Config": ( - ".llms.openai.chat.o_series_transformation", - "OpenAIOSeriesConfig", - ), # Alias - "OpenAIGPTConfig": (".llms.openai.chat.gpt_transformation", "OpenAIGPTConfig"), - "OpenAIGPT5Config": (".llms.openai.chat.gpt_reasoning_transformation", "OpenAIGPT5Config"), - "OpenAIWhisperAudioTranscriptionConfig": ( - ".llms.openai.transcriptions.whisper_transformation", - "OpenAIWhisperAudioTranscriptionConfig", - ), - "OpenAIGPTAudioTranscriptionConfig": ( - ".llms.openai.transcriptions.gpt_transformation", - "OpenAIGPTAudioTranscriptionConfig", - ), - "OpenAIGPTAudioConfig": ( - ".llms.openai.chat.gpt_audio_transformation", - "OpenAIGPTAudioConfig", - ), - "NvidiaNimConfig": (".llms.nvidia_nim.chat.transformation", "NvidiaNimConfig"), - "NvidiaNimEmbeddingConfig": (".llms.nvidia_nim.embed", "NvidiaNimEmbeddingConfig"), - "FeatherlessAIConfig": ( - ".llms.featherless_ai.chat.transformation", - "FeatherlessAIConfig", - ), - "ScaleDownChatConfig": ( - ".llms.scaledown.chat.transformation", - "ScaleDownChatConfig", - ), - "CerebrasConfig": (".llms.cerebras.chat", "CerebrasConfig"), - "NadirConfig": (".llms.nadir.chat.transformation", "NadirConfig"), - "BasetenConfig": (".llms.baseten.chat", "BasetenConfig"), - "SambanovaConfig": (".llms.sambanova.chat", "SambanovaConfig"), - "SambaNovaEmbeddingConfig": ( - ".llms.sambanova.embedding.transformation", - "SambaNovaEmbeddingConfig", - ), - "FireworksAIConfig": ( - ".llms.fireworks_ai.chat.transformation", - "FireworksAIConfig", - ), - "FireworksAITextCompletionConfig": ( - ".llms.fireworks_ai.completion.transformation", - "FireworksAITextCompletionConfig", - ), - "FireworksAIEmbeddingConfig": ( - ".llms.fireworks_ai.embed.fireworks_ai_transformation", - "FireworksAIEmbeddingConfig", - ), - "FriendliaiChatConfig": ( - ".llms.friendliai.chat.transformation", - "FriendliaiChatConfig", - ), - "JinaAIEmbeddingConfig": ( - ".llms.jina_ai.embedding.transformation", - "JinaAIEmbeddingConfig", - ), - "XAIChatConfig": (".llms.xai.chat.transformation", "XAIChatConfig"), - "ZAIChatConfig": (".llms.zai.chat.transformation", "ZAIChatConfig"), - "AIMLChatConfig": (".llms.aiml.chat.transformation", "AIMLChatConfig"), - "VolcEngineChatConfig": ( - ".llms.volcengine.chat.transformation", - "VolcEngineChatConfig", - ), - "CodestralTextCompletionConfig": ( - ".llms.codestral.completion.transformation", - "CodestralTextCompletionConfig", - ), - "InceptionTextCompletionConfig": ( - ".llms.inception.completion.transformation", - "InceptionTextCompletionConfig", - ), - "AzureOpenAIAssistantsAPIConfig": ( - ".llms.azure.azure", - "AzureOpenAIAssistantsAPIConfig", - ), - "HerokuChatConfig": (".llms.heroku.chat.transformation", "HerokuChatConfig"), - "CometAPIConfig": (".llms.cometapi.chat.transformation", "CometAPIConfig"), - "AzureOpenAIConfig": (".llms.azure.chat.gpt_transformation", "AzureOpenAIConfig"), - "AzureOpenAIGPT5Config": ( - ".llms.azure.chat.gpt_reasoning_transformation", - "AzureOpenAIGPT5Config", - ), - "AzureOpenAITextConfig": ( - ".llms.azure.completion.transformation", - "AzureOpenAITextConfig", - ), - "AzureSpeechAudioTranscriptionConfig": ( - ".llms.azure.audio_transcription.transformation", - "AzureSpeechAudioTranscriptionConfig", - ), - "HostedVLLMChatConfig": ( - ".llms.hosted_vllm.chat.transformation", - "HostedVLLMChatConfig", - ), - "HostedVLLMEmbeddingConfig": ( - ".llms.hosted_vllm.embedding.transformation", - "HostedVLLMEmbeddingConfig", - ), - # Alias for backwards compatibility - "VolcEngineConfig": ( - ".llms.volcengine.chat.transformation", - "VolcEngineChatConfig", - ), # Alias - "LlamafileChatConfig": ( - ".llms.llamafile.chat.transformation", - "LlamafileChatConfig", - ), - "LiteLLMProxyChatConfig": ( - ".llms.litellm_proxy.chat.transformation", - "LiteLLMProxyChatConfig", - ), - "VLLMConfig": (".llms.vllm.completion.transformation", "VLLMConfig"), - "DeepSeekChatConfig": (".llms.deepseek.chat.transformation", "DeepSeekChatConfig"), - "TencentChatConfig": (".llms.tencent.chat.transformation", "TencentChatConfig"), - "LMStudioChatConfig": (".llms.lm_studio.chat.transformation", "LMStudioChatConfig"), - "LmStudioEmbeddingConfig": ( - ".llms.lm_studio.embed.transformation", - "LmStudioEmbeddingConfig", - ), - "NscaleConfig": (".llms.nscale.chat.transformation", "NscaleConfig"), - "PerplexityChatConfig": ( - ".llms.perplexity.chat.transformation", - "PerplexityChatConfig", - ), - "AzureOpenAIO1Config": ( - ".llms.azure.chat.o_series_transformation", - "AzureOpenAIO1Config", - ), - "IBMWatsonXAIConfig": ( - ".llms.watsonx.completion.transformation", - "IBMWatsonXAIConfig", - ), - "IBMWatsonXChatConfig": ( - ".llms.watsonx.chat.transformation", - "IBMWatsonXChatConfig", - ), - "IBMWatsonXEmbeddingConfig": ( - ".llms.watsonx.embed.transformation", - "IBMWatsonXEmbeddingConfig", - ), - "GenAIHubEmbeddingConfig": ( - ".llms.sap.embed.transformation", - "GenAIHubEmbeddingConfig", - ), - "IBMWatsonXAudioTranscriptionConfig": ( - ".llms.watsonx.audio_transcription.transformation", - "IBMWatsonXAudioTranscriptionConfig", - ), - "GithubCopilotConfig": ( - ".llms.github_copilot.chat.transformation", - "GithubCopilotConfig", - ), - "GithubCopilotResponsesAPIConfig": ( - ".llms.github_copilot.responses.transformation", - "GithubCopilotResponsesAPIConfig", - ), - "GithubCopilotEmbeddingConfig": ( - ".llms.github_copilot.embedding.transformation", - "GithubCopilotEmbeddingConfig", - ), - "ChatGPTConfig": (".llms.chatgpt.chat.transformation", "ChatGPTConfig"), - "ChatGPTResponsesAPIConfig": ( - ".llms.chatgpt.responses.transformation", - "ChatGPTResponsesAPIConfig", - ), - "NebiusConfig": (".llms.nebius.chat.transformation", "NebiusConfig"), - "WandbConfig": (".llms.wandb.chat.transformation", "WandbConfig"), - "GigaChatConfig": (".llms.gigachat.chat.transformation", "GigaChatConfig"), - "GigaChatEmbeddingConfig": ( - ".llms.gigachat.embedding.transformation", - "GigaChatEmbeddingConfig", - ), - "DashScopeChatConfig": ( - ".llms.dashscope.chat.transformation", - "DashScopeChatConfig", - ), - "QwenCloudChatConfig": ( - ".llms.dashscope.qwencloud", - "QwenCloudChatConfig", - ), - "QwenAIPlatformChatConfig": ( - ".llms.dashscope.qwen_ai_platform", - "QwenAIPlatformChatConfig", - ), - "GDCGeminiConfig": ( - ".llms.gdc.chat.transformation", - "GDCGeminiConfig", - ), - "ModelScopeChatConfig": ( - ".llms.modelscope.chat.transformation", - "ModelScopeChatConfig", - ), - "MoonshotChatConfig": (".llms.moonshot.chat.transformation", "MoonshotChatConfig"), - "DockerModelRunnerChatConfig": ( - ".llms.docker_model_runner.chat.transformation", - "DockerModelRunnerChatConfig", - ), - "V0ChatConfig": (".llms.v0.chat.transformation", "V0ChatConfig"), - "OCIChatConfig": (".llms.oci.chat.transformation", "OCIChatConfig"), - "MorphChatConfig": (".llms.morph.chat.transformation", "MorphChatConfig"), - "RAGFlowConfig": (".llms.ragflow.chat.transformation", "RAGFlowConfig"), - "LambdaAIChatConfig": (".llms.lambda_ai.chat.transformation", "LambdaAIChatConfig"), - "InceptionChatConfig": ( - ".llms.inception.chat.transformation", - "InceptionChatConfig", - ), - "HyperbolicChatConfig": ( - ".llms.hyperbolic.chat.transformation", - "HyperbolicChatConfig", - ), - "VercelAIGatewayConfig": ( - ".llms.vercel_ai_gateway.chat.transformation", - "VercelAIGatewayConfig", - ), - "EdenAIChatConfig": (".llms.edenai.chat.transformation", "EdenAIChatConfig"), - "EdenAIResponsesAPIConfig": (".llms.edenai.responses.transformation", "EdenAIResponsesAPIConfig"), - "EdenAIAnthropicMessagesConfig": (".llms.edenai.messages.transformation", "EdenAIAnthropicMessagesConfig"), - "EdenAIEmbeddingConfig": (".llms.edenai.embedding.transformation", "EdenAIEmbeddingConfig"), - "EdenAIAudioTranscriptionConfig": ( - ".llms.edenai.audio_transcription.transformation", - "EdenAIAudioTranscriptionConfig", - ), - "EdenAITextToSpeechConfig": (".llms.edenai.text_to_speech.transformation", "EdenAITextToSpeechConfig"), - "EdenAIImageGenerationConfig": (".llms.edenai.image_generation.transformation", "EdenAIImageGenerationConfig"), - "EdenAIVideoConfig": (".llms.edenai.videos.transformation", "EdenAIVideoConfig"), - "FalAIChatConfig": (".llms.fal_ai.chat.transformation", "FalAIChatConfig"), - "FalAIError": (".llms.fal_ai.chat.transformation", "FalAIError"), - "OVHCloudChatConfig": (".llms.ovhcloud.chat.transformation", "OVHCloudChatConfig"), - "OVHCloudEmbeddingConfig": ( - ".llms.ovhcloud.embedding.transformation", - "OVHCloudEmbeddingConfig", - ), - "CometAPIEmbeddingConfig": ( - ".llms.cometapi.embed.transformation", - "CometAPIEmbeddingConfig", - ), - "LemonadeChatConfig": (".llms.lemonade.chat.transformation", "LemonadeChatConfig"), - "SnowflakeEmbeddingConfig": ( - ".llms.snowflake.embedding.transformation", - "SnowflakeEmbeddingConfig", - ), - "AmazonNovaChatConfig": ( - ".llms.amazon_nova.chat.transformation", - "AmazonNovaChatConfig", - ), - "SonioxAudioTranscriptionConfig": ( - ".llms.soniox.audio_transcription.transformation", - "SonioxAudioTranscriptionConfig", - ), -} - -# Import map for utils module lazy imports -_UTILS_MODULE_IMPORT_MAP: Final = { - "encoding": ("litellm.main", "encoding"), - "BaseVectorStore": ( - "litellm.integrations.vector_store_integrations.base_vector_store", - "BaseVectorStore", - ), - "CredentialAccessor": ( - "litellm.litellm_core_utils.credential_accessor", - "CredentialAccessor", - ), - "exception_type": ( - "litellm.litellm_core_utils.exception_mapping_utils", - "exception_type", - ), - "get_error_message": ( - "litellm.litellm_core_utils.exception_mapping_utils", - "get_error_message", - ), - "_get_response_headers": ( - "litellm.litellm_core_utils.exception_mapping_utils", - "_get_response_headers", - ), - "get_llm_provider": ( - "litellm.litellm_core_utils.get_llm_provider_logic", - "get_llm_provider", - ), - "_is_non_openai_azure_model": ( - "litellm.litellm_core_utils.get_llm_provider_logic", - "is_non_openai_azure_model", - ), - "is_non_openai_azure_model": ( - "litellm.litellm_core_utils.get_llm_provider_logic", - "is_non_openai_azure_model", - ), - "get_supported_openai_params": ( - "litellm.litellm_core_utils.get_supported_openai_params", - "get_supported_openai_params", - ), - "LiteLLMResponseObjectHandler": ( - "litellm.litellm_core_utils.llm_response_utils.convert_dict_to_response", - "LiteLLMResponseObjectHandler", - ), - "_handle_invalid_parallel_tool_calls": ( - "litellm.litellm_core_utils.llm_response_utils.convert_dict_to_response", - "handle_invalid_parallel_tool_calls", - ), - "handle_invalid_parallel_tool_calls": ( - "litellm.litellm_core_utils.llm_response_utils.convert_dict_to_response", - "handle_invalid_parallel_tool_calls", - ), - "convert_to_model_response_object": ( - "litellm.litellm_core_utils.llm_response_utils.convert_dict_to_response", - "convert_to_model_response_object", - ), - "convert_to_streaming_response": ( - "litellm.litellm_core_utils.llm_response_utils.convert_dict_to_response", - "convert_to_streaming_response", - ), - "convert_to_streaming_response_async": ( - "litellm.litellm_core_utils.llm_response_utils.convert_dict_to_response", - "convert_to_streaming_response_async", - ), - "get_api_base": ( - "litellm.litellm_core_utils.llm_response_utils.get_api_base", - "get_api_base", - ), - "ResponseMetadata": ( - "litellm.litellm_core_utils.llm_response_utils.response_metadata", - "ResponseMetadata", - ), - "_parse_content_for_reasoning": ( - "litellm.litellm_core_utils.prompt_templates.common_utils", - "parse_content_for_reasoning", - ), - "parse_content_for_reasoning": ( - "litellm.litellm_core_utils.prompt_templates.common_utils", - "parse_content_for_reasoning", - ), - "LiteLLMLoggingObject": ( - "litellm.litellm_core_utils.redact_messages", - "LiteLLMLoggingObject", - ), - "redact_message_input_output_from_logging": ( - "litellm.litellm_core_utils.redact_messages", - "redact_message_input_output_from_logging", - ), - "CustomStreamWrapper": ( - "litellm.litellm_core_utils.streaming_handler", - "CustomStreamWrapper", - ), - "BaseGoogleGenAIGenerateContentConfig": ( - "litellm.llms.base_llm.google_genai.transformation", - "BaseGoogleGenAIGenerateContentConfig", - ), - "BaseSearchConfig": ( - "litellm.llms.base_llm.search.transformation", - "BaseSearchConfig", - ), - "BaseTextToSpeechConfig": ( - "litellm.llms.base_llm.text_to_speech.transformation", - "BaseTextToSpeechConfig", - ), - "BedrockModelInfo": ("litellm.llms.bedrock.common_utils", "BedrockModelInfo"), - "CohereModelInfo": ("litellm.llms.cohere.common_utils", "CohereModelInfo"), - "Rules": ("litellm.litellm_core_utils.rules", "Rules"), - "AsyncHTTPHandler": ("litellm.llms.custom_httpx.http_handler", "AsyncHTTPHandler"), - "HTTPHandler": ("litellm.llms.custom_httpx.http_handler", "HTTPHandler"), - "get_num_retries_from_retry_policy": ( - "litellm.litellm_core_utils.get_retry_from_policy", - "get_num_retries_from_retry_policy", - ), - "reset_retry_policy": ( - "litellm.litellm_core_utils.get_retry_from_policy", - "reset_retry_policy", - ), - "get_coroutine_checker": ( - "litellm.litellm_core_utils.cached_imports", - "get_coroutine_checker", - ), - "get_litellm_logging_class": ( - "litellm.litellm_core_utils.cached_imports", - "get_litellm_logging_class", - ), - "get_set_callbacks": ( - "litellm.litellm_core_utils.cached_imports", - "get_set_callbacks", - ), - "get_litellm_metadata_from_kwargs": ( - "litellm.litellm_core_utils.core_helpers", - "get_litellm_metadata_from_kwargs", - ), - "map_finish_reason": ( - "litellm.litellm_core_utils.core_helpers", - "map_finish_reason", - ), - "process_response_headers": ( - "litellm.litellm_core_utils.core_helpers", - "process_response_headers", - ), - "delete_nested_value": ( - "litellm.litellm_core_utils.dot_notation_indexing", - "delete_nested_value", - ), - "is_nested_path": ( - "litellm.litellm_core_utils.dot_notation_indexing", - "is_nested_path", - ), - "_get_base_model_from_litellm_call_metadata": ( - "litellm.litellm_core_utils.get_litellm_params", - "get_base_model_from_litellm_call_metadata", - ), - "get_base_model_from_litellm_call_metadata": ( - "litellm.litellm_core_utils.get_litellm_params", - "get_base_model_from_litellm_call_metadata", - ), - "get_litellm_params": ( - "litellm.litellm_core_utils.get_litellm_params", - "get_litellm_params", - ), - "_ensure_extra_body_is_safe": ( - "litellm.litellm_core_utils.llm_request_utils", - "ensure_extra_body_is_safe", - ), - "ensure_extra_body_is_safe": ( - "litellm.litellm_core_utils.llm_request_utils", - "ensure_extra_body_is_safe", - ), - "get_formatted_prompt": ( - "litellm.litellm_core_utils.llm_response_utils.get_formatted_prompt", - "get_formatted_prompt", - ), - "get_response_headers": ( - "litellm.litellm_core_utils.llm_response_utils.get_headers", - "get_response_headers", - ), - "update_response_metadata": ( - "litellm.litellm_core_utils.llm_response_utils.response_metadata", - "update_response_metadata", - ), - "executor": ("litellm.litellm_core_utils.thread_pool_executor", "executor"), - "BaseAnthropicMessagesConfig": ( - "litellm.llms.base_llm.anthropic_messages.transformation", - "BaseAnthropicMessagesConfig", - ), - "BaseAudioTranscriptionConfig": ( - "litellm.llms.base_llm.audio_transcription.transformation", - "BaseAudioTranscriptionConfig", - ), - "BaseBatchesConfig": ( - "litellm.llms.base_llm.batches.transformation", - "BaseBatchesConfig", - ), - "BaseContainerConfig": ( - "litellm.llms.base_llm.containers.transformation", - "BaseContainerConfig", - ), - "BaseEmbeddingConfig": ( - "litellm.llms.base_llm.embedding.transformation", - "BaseEmbeddingConfig", - ), - "BaseImageEditConfig": ( - "litellm.llms.base_llm.image_edit.transformation", - "BaseImageEditConfig", - ), - "BaseImageGenerationConfig": ( - "litellm.llms.base_llm.image_generation.transformation", - "BaseImageGenerationConfig", - ), - "BaseImageVariationConfig": ( - "litellm.llms.base_llm.image_variations.transformation", - "BaseImageVariationConfig", - ), - "BasePassthroughConfig": ( - "litellm.llms.base_llm.passthrough.transformation", - "BasePassthroughConfig", - ), - "BaseRealtimeConfig": ( - "litellm.llms.base_llm.realtime.transformation", - "BaseRealtimeConfig", - ), - "BaseRerankConfig": ( - "litellm.llms.base_llm.rerank.transformation", - "BaseRerankConfig", - ), - "BaseVectorStoreConfig": ( - "litellm.llms.base_llm.vector_store.transformation", - "BaseVectorStoreConfig", - ), - "BaseVectorStoreFilesConfig": ( - "litellm.llms.base_llm.vector_store_files.transformation", - "BaseVectorStoreFilesConfig", - ), - "BaseVideoConfig": ( - "litellm.llms.base_llm.videos.transformation", - "BaseVideoConfig", - ), - "ANTHROPIC_API_ONLY_HEADERS": ( - "litellm.types.llms.anthropic", - "ANTHROPIC_API_ONLY_HEADERS", - ), - "AnthropicThinkingParam": ( - "litellm.types.llms.anthropic", - "AnthropicThinkingParam", - ), - "RerankResponse": ("litellm.types.rerank", "RerankResponse"), - "ChatCompletionDeltaToolCallChunk": ( - "litellm.types.llms.openai", - "ChatCompletionDeltaToolCallChunk", - ), - "ChatCompletionToolCallChunk": ( - "litellm.types.llms.openai", - "ChatCompletionToolCallChunk", - ), - "ChatCompletionToolCallFunctionChunk": ( - "litellm.types.llms.openai", - "ChatCompletionToolCallFunctionChunk", - ), - "LiteLLM_Params": ("litellm.types.router", "LiteLLM_Params"), -} - -# Export all name tuples and import maps for use in _lazy_imports.py -__all__ = [ - "BEDROCK_TYPES_NAMES", - "CACHING_NAMES", - "COST_CALCULATOR_NAMES", - "DOTPROMPT_NAMES", - "HTTP_HANDLER_NAMES", - "LITELLM_LOGGING_NAMES", - "LLM_CLIENT_CACHE_NAMES", - "LLM_CONFIG_NAMES", - "LLM_PROVIDER_LOGIC_NAMES", - "TOKEN_COUNTER_NAMES", - "TYPES_NAMES", - "TYPES_UTILS_NAMES", - "UTILS_MODULE_NAMES", - "UTILS_NAMES", - "_BEDROCK_TYPES_IMPORT_MAP", - "_CACHING_IMPORT_MAP", - "_COST_CALCULATOR_IMPORT_MAP", - "_DOTPROMPT_IMPORT_MAP", - "_LITELLM_LOGGING_IMPORT_MAP", - "_LLM_CONFIGS_IMPORT_MAP", - "_LLM_PROVIDER_LOGIC_IMPORT_MAP", - "_TOKEN_COUNTER_IMPORT_MAP", - "_TYPES_IMPORT_MAP", - "_TYPES_UTILS_IMPORT_MAP", - "_UTILS_IMPORT_MAP", - "_UTILS_MODULE_IMPORT_MAP", -] diff --git a/litellm/utils.py b/litellm/utils.py index 5ec089a106a..c7f3d4fb357 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -12025,15 +12025,6 @@ def should_run_mock_completion( def __getattr__(name: str) -> Any: - """Lazy import handler for utils module with cached registry for improved performance.""" - # Use cached registry from _lazy_imports instead of importing tuples every time - from litellm._lazy_imports import get_lazy_import_registry + from litellm._lazy_imports import resolve_lazy_attribute - registry: Final = get_lazy_import_registry() - - # Check if name is in registry and call the cached handler function - if name in registry: - handler_func: Final = registry[name] - return handler_func(name) - - raise AttributeError(f"module {__name__!r} has no attribute {name!r}") + return resolve_lazy_attribute(__name__, name) diff --git a/tests/unit/test_lazy_imports.py b/tests/unit/test_lazy_imports.py index 43aee4616d2..1f39bdede5a 100644 --- a/tests/unit/test_lazy_imports.py +++ b/tests/unit/test_lazy_imports.py @@ -1,5 +1,4 @@ -"""Simple tests for lazy import functionality.""" - +import importlib import os import subprocess import sys @@ -7,38 +6,9 @@ from typing import Final import pytest - import litellm -from litellm._lazy_imports import ( - COST_CALCULATOR_NAMES, - LITELLM_LOGGING_NAMES, - UTILS_NAMES, - TOKEN_COUNTER_NAMES, - CACHING_NAMES, - BEDROCK_TYPES_NAMES, - TYPES_UTILS_NAMES, - LLM_CLIENT_CACHE_NAMES, - HTTP_HANDLER_NAMES, - _lazy_import_cost_calculator, - _lazy_import_litellm_logging, - _lazy_import_utils, - _lazy_import_token_counter, - _lazy_import_bedrock_types, - _lazy_import_types_utils, - _lazy_import_caching, - _lazy_import_llm_client_cache, - _lazy_import_http_handlers, - DOTPROMPT_NAMES, - _lazy_import_dotprompt, - LLM_CONFIG_NAMES, - _lazy_import_llm_configs, - TYPES_NAMES, - _lazy_import_types, - LLM_PROVIDER_LOGIC_NAMES, - _lazy_import_llm_provider_logic, - UTILS_MODULE_NAMES, - _lazy_import_utils_module, -) +import litellm.utils +from litellm._lazy_imports_registry import LITELLM_ATTRIBUTES, UTILS_ATTRIBUTES from tests.test_litellm_rust.support.child_interpreter import run_child_interpreter @@ -58,314 +28,75 @@ def test_import_litellm_does_not_load_fastapi_or_bpe_table(): assert result.stdout.strip() == "" -def _clear_names_from_globals(names: tuple): - """Clear all names from litellm globals.""" - # Get the actual globals dict, not a copy - litellm_globals = sys.modules["litellm"].__dict__ - for name in names: - if name in litellm_globals: - del litellm_globals[name] - - -def _clear_names_from_utils_globals(names: tuple): - """Clear all names from litellm.utils globals.""" - # Get the actual globals dict, not a copy - utils_globals = sys.modules["litellm.utils"].__dict__ - for name in names: - if name in utils_globals: - del utils_globals[name] - - -def _verify_only_requested_name_imported(name: str, all_names: tuple): - """Verify that only the requested name is in globals, not the others.""" - # Get the actual globals dict, not a copy - litellm_globals = sys.modules["litellm"].__dict__ - for other_name in all_names: - if other_name != name: - assert ( - other_name not in litellm_globals - ), f"{other_name} should not be imported when importing {name}" - - -def _verify_only_requested_name_imported_in_utils(name: str, all_names: tuple): - """Verify that only the requested name is in utils globals, not the others.""" - # Get the actual globals dict, not a copy - utils_globals = sys.modules["litellm.utils"].__dict__ - for other_name in all_names: - if other_name != name: - assert ( - other_name not in utils_globals - ), f"{other_name} should not be imported when importing {name}" - - -def test_cost_calculator_lazy_imports(): - """Test that all cost calculator functions can be lazy imported.""" - # Get the actual globals dict, not a copy - litellm_globals = sys.modules["litellm"].__dict__ - - # Test each name individually - only that name should be imported - for name in COST_CALCULATOR_NAMES: - # Clear all names before importing just one - _clear_names_from_globals(COST_CALCULATOR_NAMES) - - func = _lazy_import_cost_calculator(name) - assert func is not None - assert callable(func) - assert name in litellm_globals - - # Verify only the requested name is in globals, not the others - _verify_only_requested_name_imported(name, COST_CALCULATOR_NAMES) - - -def test_litellm_logging_lazy_imports(): - """Test that all litellm_logging items can be lazy imported.""" - # Get the actual globals dict, not a copy - litellm_globals = sys.modules["litellm"].__dict__ - - # Test each name individually - only that name should be imported - for name in LITELLM_LOGGING_NAMES: - # Clear all names before importing just one - _clear_names_from_globals(LITELLM_LOGGING_NAMES) - - item = _lazy_import_litellm_logging(name) - assert item is not None - assert name in litellm_globals - - # Verify only the requested name is in globals, not the others - _verify_only_requested_name_imported(name, LITELLM_LOGGING_NAMES) - - -def test_utils_lazy_imports(): - """Test that all utils functions can be lazy imported.""" - # Get the actual globals dict, not a copy - litellm_globals = sys.modules["litellm"].__dict__ - - # Test each name individually - only that name should be imported - for name in UTILS_NAMES: - # Clear all names before importing just one - _clear_names_from_globals(UTILS_NAMES) - - attr = _lazy_import_utils(name) - assert attr is not None - assert name in litellm_globals - - # Verify only the requested name is in globals, not the others - _verify_only_requested_name_imported(name, UTILS_NAMES) - - -def test_caching_lazy_imports(): - """Test that all caching classes can be lazy imported.""" - # Get the actual globals dict, not a copy - litellm_globals = sys.modules["litellm"].__dict__ - - # Test each name individually - only that name should be imported - for name in CACHING_NAMES: - # Clear all names before importing just one - _clear_names_from_globals(CACHING_NAMES) - - cls = _lazy_import_caching(name) - assert cls is not None - assert name in litellm_globals - - # Verify only the requested name is in globals, not the others - _verify_only_requested_name_imported(name, CACHING_NAMES) - - -def test_token_counter_lazy_imports(): - """Test that token counter utilities can be lazy imported.""" - # Get the actual globals dict, not a copy - litellm_globals = sys.modules["litellm"].__dict__ - - for name in TOKEN_COUNTER_NAMES: - _clear_names_from_globals(TOKEN_COUNTER_NAMES) - - func = _lazy_import_token_counter(name) - assert func is not None - assert name in litellm_globals - - _verify_only_requested_name_imported(name, TOKEN_COUNTER_NAMES) - - -def test_bedrock_types_lazy_imports(): - """Test that Bedrock type aliases can be lazy imported.""" - # Get the actual globals dict, not a copy - litellm_globals = sys.modules["litellm"].__dict__ - - for name in BEDROCK_TYPES_NAMES: - _clear_names_from_globals(BEDROCK_TYPES_NAMES) - - alias = _lazy_import_bedrock_types(name) - assert alias is not None - assert name in litellm_globals - - _verify_only_requested_name_imported(name, BEDROCK_TYPES_NAMES) - - -def test_types_utils_lazy_imports(): - """Test that common types.utils symbols can be lazy imported.""" - # Get the actual globals dict, not a copy - litellm_globals = sys.modules["litellm"].__dict__ - - for name in TYPES_UTILS_NAMES: - _clear_names_from_globals(TYPES_UTILS_NAMES) - - obj = _lazy_import_types_utils(name) - assert obj is not None - assert name in litellm_globals - - _verify_only_requested_name_imported(name, TYPES_UTILS_NAMES) - - -def test_llm_client_cache_lazy_imports(): - """Test that LLM client cache class and singleton can be lazy imported.""" - # Get the actual globals dict, not a copy - litellm_globals = sys.modules["litellm"].__dict__ - - for name in LLM_CLIENT_CACHE_NAMES: - _clear_names_from_globals(LLM_CLIENT_CACHE_NAMES) - - obj = _lazy_import_llm_client_cache(name) - assert obj is not None - assert name in litellm_globals - - _verify_only_requested_name_imported(name, LLM_CLIENT_CACHE_NAMES) - - -def test_http_handler_lazy_imports(): - """Test that HTTP handler singletons can be lazy imported.""" - # Get the actual globals dict, not a copy - litellm_globals = sys.modules["litellm"].__dict__ - - for name in HTTP_HANDLER_NAMES: - _clear_names_from_globals(HTTP_HANDLER_NAMES) - - handler = _lazy_import_http_handlers(name) - assert handler is not None - assert name in litellm_globals - - _verify_only_requested_name_imported(name, HTTP_HANDLER_NAMES) - - -def test_dotprompt_lazy_imports(): - """Test that dotprompt globals can be lazy imported.""" - # Get the actual globals dict, not a copy - litellm_globals = sys.modules["litellm"].__dict__ - - for name in DOTPROMPT_NAMES: - _clear_names_from_globals(DOTPROMPT_NAMES) - - obj = _lazy_import_dotprompt(name) - assert name in litellm_globals - - # Only the setter must be callable; others may be None by default - if name == "set_global_prompt_directory": - assert callable(obj), f"{name} should be callable" - - _verify_only_requested_name_imported(name, DOTPROMPT_NAMES) - - -def test_unknown_attribute_raises_error(): - """Test that unknown attributes raise AttributeError.""" - with pytest.raises(AttributeError): - _lazy_import_cost_calculator("unknown") - - with pytest.raises(AttributeError): - _lazy_import_litellm_logging("unknown") - - with pytest.raises(AttributeError): - _lazy_import_utils("unknown") - - with pytest.raises(AttributeError): - _lazy_import_caching("unknown") - - with pytest.raises(AttributeError): - _lazy_import_token_counter("unknown") - - with pytest.raises(AttributeError): - _lazy_import_llm_client_cache("unknown") - - with pytest.raises(AttributeError): - _lazy_import_bedrock_types("unknown") - - with pytest.raises(AttributeError): - _lazy_import_types_utils("unknown") - - with pytest.raises(AttributeError): - _lazy_import_llm_configs("unknown") - - with pytest.raises(AttributeError): - _lazy_import_types("unknown") - - with pytest.raises(AttributeError): - _lazy_import_llm_provider_logic("unknown") - - with pytest.raises(AttributeError): - _lazy_import_utils_module("unknown") - - -def test_llm_config_lazy_imports(): - """Test that LLM config classes can be lazy imported.""" - # Get the actual globals dict, not a copy - litellm_globals = sys.modules["litellm"].__dict__ - - for name in LLM_CONFIG_NAMES: - _clear_names_from_globals(LLM_CONFIG_NAMES) - - obj = _lazy_import_llm_configs(name) - assert obj is not None - assert name in litellm_globals - # Config classes should be classes/types - assert isinstance(obj, type), f"{name} should be a class" - - _verify_only_requested_name_imported(name, LLM_CONFIG_NAMES) - - -def test_types_lazy_imports(): - """Test that type classes can be lazy imported.""" - # Get the actual globals dict, not a copy - litellm_globals = sys.modules["litellm"].__dict__ - - for name in TYPES_NAMES: - _clear_names_from_globals(TYPES_NAMES) - - obj = _lazy_import_types(name) - assert obj is not None - assert name in litellm_globals - # Type classes should be classes/types - assert isinstance(obj, type), f"{name} should be a class" - - _verify_only_requested_name_imported(name, TYPES_NAMES) - - -def test_llm_provider_logic_lazy_imports(): - """Test that LLM provider logic functions can be lazy imported.""" - # Get the actual globals dict, not a copy - litellm_globals = sys.modules["litellm"].__dict__ - - for name in LLM_PROVIDER_LOGIC_NAMES: - _clear_names_from_globals(LLM_PROVIDER_LOGIC_NAMES) - - func = _lazy_import_llm_provider_logic(name) - assert func is not None - assert callable(func) - assert name in litellm_globals - - _verify_only_requested_name_imported(name, LLM_PROVIDER_LOGIC_NAMES) - - -def test_utils_module_lazy_imports(): - """Test that utils module attributes can be lazy imported.""" - # Get the actual globals dict, not a copy - utils_globals = sys.modules["litellm.utils"].__dict__ - - for name in UTILS_MODULE_NAMES: - _clear_names_from_utils_globals(UTILS_MODULE_NAMES) - - obj = _lazy_import_utils_module(name) - assert obj is not None - assert name in utils_globals - - _verify_only_requested_name_imported_in_utils(name, UTILS_MODULE_NAMES) +def _declared(location: tuple[str, str]) -> object: + module_path, attr_name = location + return getattr(importlib.import_module(module_path, package="litellm"), attr_name) + + +@pytest.mark.parametrize("name", sorted(LITELLM_ATTRIBUTES)) +def test_litellm_attribute_is_the_declared_object(name: str): + assert getattr(litellm, name) is _declared(LITELLM_ATTRIBUTES[name]) + + +@pytest.mark.parametrize("name", sorted(UTILS_ATTRIBUTES)) +def test_utils_attribute_is_the_same_object_from_litellm_and_litellm_utils(name: str): + expected: Final = _declared(UTILS_ATTRIBUTES[name]) + assert getattr(litellm.utils, name) is expected + assert getattr(litellm, name) is expected + + +@pytest.mark.parametrize( + ("instance_name", "class_name"), + [ + ("in_memory_llm_clients_cache", "LLMClientCache"), + ("openaiOSeriesConfig", "OpenAIOSeriesConfig"), + ("openAIGPTConfig", "OpenAIGPTConfig"), + ("openAIGPTAudioConfig", "OpenAIGPTAudioConfig"), + ("openAIGPT5Config", "OpenAIGPT5Config"), + ("nvidiaNimConfig", "NvidiaNimConfig"), + ("nvidiaNimEmbeddingConfig", "NvidiaNimEmbeddingConfig"), + ("priority_reservation_settings", "PriorityReservationSettings"), + ("logging_callback_manager", "LoggingCallbackManager"), + ], +) +def test_lazy_instance_is_a_single_instance_of_its_class(instance_name: str, class_name: str): + instance: Final = getattr(litellm, instance_name) + assert type(instance) is getattr(litellm, class_name) + assert getattr(litellm, instance_name) is instance + + +def test_module_level_http_clients_use_request_timeout(monkeypatch: pytest.MonkeyPatch): + client_names: Final = ("module_level_client", "module_level_aclient") + monkeypatch.setattr(litellm, "request_timeout", 7) + for client_name in client_names: + monkeypatch.delitem(vars(litellm), client_name, raising=False) + try: + assert litellm.module_level_client.timeout == 7 + assert litellm.module_level_aclient.timeout == 7 + assert litellm.module_level_client is litellm.module_level_client + finally: + for client_name in client_names: + vars(litellm).pop(client_name, None) + + +def test_provider_list_lists_every_provider(): + assert litellm.provider_list == list(litellm.LlmProviders) + + +@pytest.mark.parametrize("name", ["proxy", "guardrails", "harness", "_service_logger"]) +def test_submodule_attribute_is_the_submodule(name: str): + assert getattr(litellm, name) is importlib.import_module(f"litellm.{name}") + + +@pytest.mark.parametrize("module", [litellm, litellm.utils]) +def test_unknown_attribute_raises_attribute_error(module: object): + with pytest.raises(AttributeError, match="not_a_litellm_attribute"): + getattr(module, "not_a_litellm_attribute") + assert not hasattr(module, "not_a_litellm_attribute") + + +def test_litellm_instances_are_not_attributes_of_litellm_utils(): + assert not hasattr(litellm.utils, "module_level_client") @pytest.mark.parametrize( diff --git a/tests/unit/test_private_usage_aliases.py b/tests/unit/test_private_usage_aliases.py index d257866b654..fb42f6229e0 100644 --- a/tests/unit/test_private_usage_aliases.py +++ b/tests/unit/test_private_usage_aliases.py @@ -1185,7 +1185,6 @@ ALIAS_CASES: Final = ( ("litellm", "", "_turn_on_debug", "turn_on_debug", False), ("litellm", "", "_turn_on_json", "turn_on_json", False), ("litellm._lazy_imports", "", "_get_default_encoding", "get_default_encoding", False), - ("litellm._lazy_imports", "", "_get_lazy_import_registry", "get_lazy_import_registry", False), ("litellm._lazy_imports", "", "_get_messages_reach_token_count", "get_messages_reach_token_count", False), ("litellm._lazy_imports", "", "_get_token_counter_new", "get_token_counter_new", False), ("litellm._logging", "", "_is_debugging_on", "is_debugging_on", False),