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:
Alexsander Hamir 2025-12-16 12:43:42 -08:00 committed by GitHub
parent 9b440caac2
commit 233e89976a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 1 deletions

View file

@ -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:

View file

@ -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}")