Coverage for src/lexigram/ai/__init__.py: 100%

17 statements  

« prev     ^ index     » next       coverage.py v7.15.4, created at 2026-08-25 07:19 +0800

1"""Lexigram AI — Unified AI/ML Layer. 

2 

3Install `lexigram-ai` to get the full AI subsystem. 

4Import from sub-packages for granular control. 

5""" 

6 

7from __future__ import annotations 

8 

9from typing import TYPE_CHECKING 

10 

11__path__ = __import__("pkgutil").extend_path(__path__, __name__) 

12 

13from lexigram.ai.constants import __version__ as __version__ 

14 

15if TYPE_CHECKING: 

16 from lexigram.ai.config import AIConfig, ClientConfig, RAGConfig, VectorConfig 

17 from lexigram.ai.di.provider import AIProvider 

18 from lexigram.ai.module import AIModule 

19 

20_LAZY_IMPORTS: dict[str, tuple[str, str]] = { 

21 "AIConfig": ("lexigram.ai.config", "AIConfig"), 

22 "AIModule": ("lexigram.ai.module", "AIModule"), 

23 "AIProvider": ("lexigram.ai.di.provider", "AIProvider"), 

24 "ClientConfig": ("lexigram.ai.config", "ClientConfig"), 

25 "RAGConfig": ("lexigram.ai.config", "RAGConfig"), 

26 "VectorConfig": ("lexigram.ai.config", "VectorConfig"), 

27} 

28 

29__all__ = list(_LAZY_IMPORTS) 

30 

31 

32def __getattr__(name: str) -> object: 

33 """Lazy-load public symbols on first access.""" 

34 if name in _LAZY_IMPORTS: 

35 import importlib 

36 

37 module_path, attr = _LAZY_IMPORTS[name] 

38 mod = importlib.import_module(module_path) 

39 value = getattr(mod, attr) 

40 globals()[name] = value 

41 return value 

42 raise AttributeError(f"module {__name__!r} has no attribute {name!r}") 

43 

44 

45def __dir__() -> list[str]: 

46 """Expose lazy-loaded names for tab completion and dir().""" 

47 return list(_LAZY_IMPORTS)