Add lazy loading for GaladrielChatConfig to reduce import memory overhead (#18260)

Implements lazy loading pattern for GaladrielChatConfig following the existing approach used for other LLM config classes. This defers the import until the config is actually accessed, reducing memory usage during module initialization.
This commit is contained in:
Alexsander Hamir 2025-12-19 13:00:57 -08:00 committed by GitHub
parent 026c2ad693
commit f3b97356fb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 1 deletions

View file

@ -1066,7 +1066,6 @@ from .utils import client
from .llms.bytez.chat.transformation import BytezChatConfig
from .llms.custom_llm import CustomLLM
from .llms.aiohttp_openai.chat.transformation import AiohttpOpenAIChatConfig
from .llms.galadriel.chat.transformation import GaladrielChatConfig
from .llms.github.chat.transformation import GithubChatConfig
from .llms.compactifai.chat.transformation import CompactifAIChatConfig
from .llms.empower.chat.transformation import EmpowerChatConfig

View file

@ -158,6 +158,7 @@ DOTPROMPT_NAMES = (
LLM_CONFIG_NAMES = (
"AmazonConverseConfig",
"OpenAILikeChatConfig",
"GaladrielChatConfig",
)
# Types that support lazy loading via _lazy_import_types
@ -660,4 +661,12 @@ def _lazy_import_llm_configs(name: str) -> Any:
_globals["OpenAILikeChatConfig"] = _OpenAILikeChatConfig
return _OpenAILikeChatConfig
if name == "GaladrielChatConfig":
from .llms.galadriel.chat.transformation import (
GaladrielChatConfig as _GaladrielChatConfig,
)
_globals["GaladrielChatConfig"] = _GaladrielChatConfig
return _GaladrielChatConfig
raise AttributeError(f"LLM config lazy import: unknown attribute {name!r}")