|
78 | 78 | KeyManagementSystem, |
79 | 79 | KeyManagementSettings, |
80 | 80 | ) |
81 | | -from litellm.types.proxy.management_endpoints.ui_sso import ( |
82 | | - DefaultTeamSSOParams, |
83 | | - LiteLLM_UpperboundKeyGenerateParams, |
84 | | -) |
85 | | -# Types utils imports are lazy-loaded to reduce import-time memory cost |
86 | | -# They are created on first access via __getattr__ |
87 | | -# However, some are needed at module level for initialization, so import them directly |
88 | 81 | from litellm.types.utils import LlmProviders, PriorityReservationSettings |
89 | | -# Import only for type checking; runtime access is via __getattr__ |
90 | 82 | if TYPE_CHECKING: |
91 | 83 | from litellm.integrations.custom_logger import CustomLogger |
92 | 84 | from litellm.types.llms.bedrock import COHERE_EMBEDDING_INPUT_TYPES |
93 | 85 | from litellm.types.guardrails import GuardrailItem |
94 | | - from litellm.types.utils import CredentialItem, BudgetConfig, PriorityReservationDict, StandardKeyGenerationConfig |
| 86 | + from litellm.types.utils import CredentialItem, BudgetConfig, PriorityReservationDict, StandardKeyGenerationConfig, LlmProviders, PriorityReservationSettings |
| 87 | + from litellm.types.proxy.management_endpoints.ui_sso import DefaultTeamSSOParams, LiteLLM_UpperboundKeyGenerateParams |
95 | 88 | import httpx |
96 | 89 | import dotenv |
97 | 90 | from litellm.llms.custom_httpx.async_client_cleanup import register_async_client_cleanup |
@@ -382,10 +375,10 @@ def __getattr__(self, name: str) -> Any: |
382 | 375 | aws_sqs_callback_params: Optional[Dict] = None |
383 | 376 | generic_logger_headers: Optional[Dict] = None |
384 | 377 | default_key_generate_params: Optional[Dict] = None |
385 | | -upperbound_key_generate_params: Optional[LiteLLM_UpperboundKeyGenerateParams] = None |
| 378 | +upperbound_key_generate_params: Optional["LiteLLM_UpperboundKeyGenerateParams"] = None |
386 | 379 | key_generation_settings: Optional["StandardKeyGenerationConfig"] = None |
387 | 380 | default_internal_user_params: Optional[Dict] = None |
388 | | -default_team_params: Optional[Union[DefaultTeamSSOParams, Dict]] = None |
| 381 | +default_team_params: Optional[Union["DefaultTeamSSOParams", Dict]] = None |
389 | 382 | default_team_settings: Optional[List] = None |
390 | 383 | max_user_budget: Optional[float] = None |
391 | 384 | default_max_internal_user_budget: Optional[float] = None |
@@ -413,10 +406,6 @@ def __getattr__(self, name: str) -> Any: |
413 | 406 | public_model_groups_links: Dict[str, str] = {} |
414 | 407 | #### REQUEST PRIORITIZATION ####### |
415 | 408 | priority_reservation: Optional[Dict[str, Union[float, "PriorityReservationDict"]]] = None |
416 | | -# PriorityReservationSettings is imported at top level since it's needed for initialization |
417 | | -priority_reservation_settings: "PriorityReservationSettings" = ( |
418 | | - PriorityReservationSettings() |
419 | | -) |
420 | 409 |
|
421 | 410 |
|
422 | 411 | ######## Networking Settings ######## |
@@ -927,8 +916,6 @@ def add_known_models(): |
927 | 916 |
|
928 | 917 | model_list_set = set(model_list) |
929 | 918 |
|
930 | | -# LlmProviders is imported at top level since it's needed for initialization |
931 | | -provider_list: List[Union["LlmProviders", str]] = list(LlmProviders) |
932 | 919 |
|
933 | 920 |
|
934 | 921 | models_by_provider: dict = { |
@@ -1761,8 +1748,6 @@ def _lazy_import_caching(name: str) -> Any: |
1761 | 1748 | raise AttributeError(f"Caching lazy import: unknown attribute {name!r}") |
1762 | 1749 |
|
1763 | 1750 |
|
1764 | | -# Lazy import for types.utils to avoid loading the module at import time |
1765 | | -# This significantly reduces memory usage when importing litellm |
1766 | 1751 | def _lazy_import_types_utils(name: str) -> Any: |
1767 | 1752 | """Lazy import for types.utils module - imports only the requested item by name.""" |
1768 | 1753 | if name == "ImageObject": |
@@ -1818,6 +1803,21 @@ def _lazy_import_types_utils(name: str) -> Any: |
1818 | 1803 | raise AttributeError(f"Types utils lazy import: unknown attribute {name!r}") |
1819 | 1804 |
|
1820 | 1805 |
|
| 1806 | +def _lazy_import_ui_sso(name: str) -> Any: |
| 1807 | + """Lazy import for types.proxy.management_endpoints.ui_sso module - imports only the requested item by name.""" |
| 1808 | + if name == "DefaultTeamSSOParams": |
| 1809 | + from litellm.types.proxy.management_endpoints.ui_sso import DefaultTeamSSOParams as _DefaultTeamSSOParams |
| 1810 | + globals()["DefaultTeamSSOParams"] = _DefaultTeamSSOParams |
| 1811 | + return _DefaultTeamSSOParams |
| 1812 | + |
| 1813 | + if name == "LiteLLM_UpperboundKeyGenerateParams": |
| 1814 | + from litellm.types.proxy.management_endpoints.ui_sso import LiteLLM_UpperboundKeyGenerateParams as _LiteLLM_UpperboundKeyGenerateParams |
| 1815 | + globals()["LiteLLM_UpperboundKeyGenerateParams"] = _LiteLLM_UpperboundKeyGenerateParams |
| 1816 | + return _LiteLLM_UpperboundKeyGenerateParams |
| 1817 | + |
| 1818 | + raise AttributeError(f"UI SSO lazy import: unknown attribute {name!r}") |
| 1819 | + |
| 1820 | + |
1821 | 1821 | def __getattr__(name: str) -> Any: |
1822 | 1822 | """Lazy import for cost_calculator, litellm_logging, and utils functions.""" |
1823 | 1823 | if name in {"completion_cost", "response_cost_calculator", "cost_per_token"}: |
@@ -1867,6 +1867,19 @@ def __getattr__(name: str) -> Any: |
1867 | 1867 | if name in _types_utils_names: |
1868 | 1868 | return _lazy_import_types_utils(name) |
1869 | 1869 |
|
| 1870 | + if name in {"DefaultTeamSSOParams", "LiteLLM_UpperboundKeyGenerateParams"}: |
| 1871 | + return _lazy_import_ui_sso(name) |
| 1872 | + |
| 1873 | + if name == "provider_list": |
| 1874 | + provider_list_val = list(LlmProviders) |
| 1875 | + globals()["provider_list"] = provider_list_val |
| 1876 | + return provider_list_val |
| 1877 | + |
| 1878 | + if name == "priority_reservation_settings": |
| 1879 | + prs_val = PriorityReservationSettings() |
| 1880 | + globals()["priority_reservation_settings"] = prs_val |
| 1881 | + return prs_val |
| 1882 | + |
1870 | 1883 | # Lazy-load CustomLogger to avoid circular imports |
1871 | 1884 | if name == "CustomLogger": |
1872 | 1885 | from litellm.integrations.custom_logger import CustomLogger as _CustomLogger |
|
0 commit comments