Files
mai-bot/src/llm_models/model_client/__init__.py
DrSmoothl 2a33fd1121 refactor(llm): enable hot-reload for model config and client runtime
make LLM task config resolution dynamic in LLMRequest
load model clients on demand from latest config
clear client instance cache on config reload
remove stale module-level model_config usage in llm_api
add hot-reload tests for LLM/config watcher flow
2026-03-04 21:56:50 +08:00

29 lines
750 B
Python

from importlib import import_module
from src.config.config import config_manager
_CLIENT_MODULE_BY_TYPE: dict[str, str] = {
"openai": ".openai_client",
"gemini": ".gemini_client",
}
_LOADED_CLIENT_TYPES: set[str] = set()
def ensure_client_type_loaded(client_type: str) -> None:
if client_type in _LOADED_CLIENT_TYPES:
return
module_name = _CLIENT_MODULE_BY_TYPE.get(client_type)
if not module_name:
return
import_module(module_name, package=__name__)
_LOADED_CLIENT_TYPES.add(client_type)
def ensure_configured_clients_loaded() -> None:
for provider in config_manager.get_model_config().api_providers:
ensure_client_type_loaded(provider.client_type)
ensure_configured_clients_loaded()