mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-10 22:41:41 +00:00
Lazy load OpenAILikeChatConfig to avoid heavy import (#18075)
- Remove direct import of OpenAILikeChatConfig from llms.openai_like.chat.handler - Add OpenAILikeChatConfig to LLM_CONFIG_NAMES for lazy loading - Add handler in _lazy_import_llm_configs() to lazy load when accessed - Add OpenAILikeChatConfig to TYPE_CHECKING block for type hints This defers the import until OpenAILikeChatConfig is actually needed, improving import time.
This commit is contained in:
parent
9b440caac2
commit
233e89976a
2 changed files with 10 additions and 1 deletions
|
|
@ -1056,7 +1056,6 @@ from .utils import client
|
|||
|
||||
from .llms.bytez.chat.transformation import BytezChatConfig
|
||||
from .llms.custom_llm import CustomLLM
|
||||
from .llms.openai_like.chat.handler import OpenAILikeChatConfig
|
||||
from .llms.aiohttp_openai.chat.transformation import AiohttpOpenAIChatConfig
|
||||
from .llms.galadriel.chat.transformation import GaladrielChatConfig
|
||||
from .llms.github.chat.transformation import GithubChatConfig
|
||||
|
|
@ -1554,6 +1553,7 @@ if TYPE_CHECKING:
|
|||
|
||||
# LLM config classes - lazy loaded only
|
||||
AmazonConverseConfig: Type[Any]
|
||||
OpenAILikeChatConfig: Type[Any]
|
||||
|
||||
|
||||
def __getattr__(name: str) -> Any:
|
||||
|
|
|
|||
|
|
@ -157,6 +157,7 @@ DOTPROMPT_NAMES = (
|
|||
# LLM config classes that support lazy loading via _lazy_import_llm_configs
|
||||
LLM_CONFIG_NAMES = (
|
||||
"AmazonConverseConfig",
|
||||
"OpenAILikeChatConfig",
|
||||
)
|
||||
|
||||
# Types that support lazy loading via _lazy_import_types
|
||||
|
|
@ -651,4 +652,12 @@ def _lazy_import_llm_configs(name: str) -> Any:
|
|||
_globals["AmazonConverseConfig"] = _AmazonConverseConfig
|
||||
return _AmazonConverseConfig
|
||||
|
||||
if name == "OpenAILikeChatConfig":
|
||||
from .llms.openai_like.chat.handler import (
|
||||
OpenAILikeChatConfig as _OpenAILikeChatConfig,
|
||||
)
|
||||
|
||||
_globals["OpenAILikeChatConfig"] = _OpenAILikeChatConfig
|
||||
return _OpenAILikeChatConfig
|
||||
|
||||
raise AttributeError(f"LLM config lazy import: unknown attribute {name!r}")
|
||||
Loading…
Add table
Reference in a new issue