mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-12 23:01:41 +00:00
refactor(utils): lazy load CustomStreamWrapper to improve import time
- Move CustomStreamWrapper from streaming_handler to lazy loading via __getattr__ - Add type stub in TYPE_CHECKING block for mypy type checking - CustomStreamWrapper is not used internally in utils.py, only exported for other modules This reduces import time by deferring the streaming_handler module import until CustomStreamWrapper is actually accessed.
This commit is contained in:
parent
2943a2d652
commit
b52feaa965
1 changed files with 11 additions and 1 deletions
|
|
@ -99,7 +99,6 @@ from litellm.litellm_core_utils.llm_response_utils.get_headers import (
|
|||
get_response_headers,
|
||||
)
|
||||
from litellm.litellm_core_utils.rules import Rules
|
||||
from litellm.litellm_core_utils.streaming_handler import CustomStreamWrapper
|
||||
from litellm.llms.base_llm.google_genai.transformation import (
|
||||
BaseGoogleGenAIGenerateContentConfig,
|
||||
)
|
||||
|
|
@ -340,6 +339,7 @@ if TYPE_CHECKING:
|
|||
LiteLLMLoggingObject,
|
||||
redact_message_input_output_from_logging,
|
||||
)
|
||||
from litellm.litellm_core_utils.streaming_handler import CustomStreamWrapper
|
||||
|
||||
from litellm.llms.base_llm.batches.transformation import BaseBatchesConfig
|
||||
from litellm.llms.base_llm.chat.transformation import BaseConfig
|
||||
|
|
@ -8905,4 +8905,14 @@ def __getattr__(name: str) -> Any: # noqa: PLR0915
|
|||
_globals["redact_message_input_output_from_logging"] = _redact_message_input_output_from_logging
|
||||
return _globals["redact_message_input_output_from_logging"]
|
||||
|
||||
# Lazy load CustomStreamWrapper to avoid loading at module import time
|
||||
if name == "CustomStreamWrapper":
|
||||
# Check if already cached
|
||||
if "CustomStreamWrapper" not in _globals:
|
||||
from litellm.litellm_core_utils.streaming_handler import (
|
||||
CustomStreamWrapper as _CustomStreamWrapper,
|
||||
)
|
||||
_globals["CustomStreamWrapper"] = _CustomStreamWrapper
|
||||
return _globals["CustomStreamWrapper"]
|
||||
|
||||
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue