Coverage for providers/__init__.py: 94%

1 from qrclaw.providers.base import LLMProvider

2 from qrclaw.config import LLM_PROVIDER

3 from qrclaw.logger import get_logger

4

5 logger = get_logger("qrclaw.providers")

6

7 _REGISTRY = {

8 "openai": "qrclaw.providers.openai.OpenAIProvider",

9 "vertex": "qrclaw.providers.vertex.VertexProvider",

10}

11

12

13 def _load_provider() -> LLMProvider:

14 path = _REGISTRY.get(LLM_PROVIDER)

15 if not path:

16 raise ValueError(f"未知的 LLM 渠道: {LLM_PROVIDER}，可选: {list(_REGISTRY.keys())}")

17

18 module_path, class_name = path.rsplit(".", 1)

19 import importlib

20 module = importlib.import_module(module_path)

21 cls = getattr(module, class_name)

22 logger.info(f"加载 LLM 渠道: {LLM_PROVIDER}")

23 return cls()

24

25

26 provider: LLMProvider = _load_provider()