Coverage for /home/admin/Documents/AI/applications/lexigram-dev/lexigram/experimental/ai/lexigram-ai-llm/src/lexigram/ai/llm/__init__.py: 94%
32 statements
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-25 07:19 +0800
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-25 07:19 +0800
1"""LLM module exports."""
3from __future__ import annotations
5import importlib.metadata
6from typing import TYPE_CHECKING, Any
8__path__ = __import__("pkgutil").extend_path(__path__, __name__)
10from lexigram.ai.llm.constants import __version__ as __version__
12if TYPE_CHECKING:
13 from lexigram.ai.llm.caching.core import (
14 CacheEntry,
15 CacheStats,
16 LLMCache,
17 RedisLLMCache,
18 )
19 from lexigram.ai.llm.clients.anthropic import AnthropicClient
20 from lexigram.ai.llm.clients.cohere import CohereClient
21 from lexigram.ai.llm.clients.groq import GroqClient
22 from lexigram.ai.llm.clients.mistral import MistralClient
23 from lexigram.ai.llm.clients.ollama import OllamaClient
24 from lexigram.ai.llm.clients.openai import OpenAIClient
25 from lexigram.ai.llm.clients.openrouter import OpenRouterClient
26 from lexigram.ai.llm.config import ClientConfig
27 from lexigram.ai.llm.conversation.manager import (
28 ConversationConfig,
29 ConversationManager,
30 ConversationStats,
31 )
32 from lexigram.ai.llm.events import LLMCompletionEvent
33 from lexigram.ai.llm.extraction.extractor import InstructorExtractor
34 from lexigram.ai.llm.hooks import (
35 LLMProviderRegisteredHook,
36 LLMRequestSentHook,
37 LLMResponseReceivedHook,
38 )
39from lexigram.ai.llm.pricing import (
40 AbstractPricingSource,
41 JSONFilePricingSource,
42 StaticPricingSource,
43)
44from lexigram.ai.llm.pricing.registry import TokenCounterRegistry
45from lexigram.ai.llm.protocols import LLMCacheProtocol
46from lexigram.ai.llm.rate_limiting.core import RateLimiter
47from lexigram.ai.llm.registry.core import ProviderInfo, ProviderRegistry
48from lexigram.ai.llm.routing.config import (
49 GenerationDefaults,
50 LLMConfig,
51 LogConfig,
52 ProviderConfig,
53 QuotaConfig,
54)
55from lexigram.ai.llm.security.core import (
56 OutputFilter,
57 SecureLLMClient,
58 SecurePromptTemplate,
59 create_assistant_template,
60 create_data_extraction_template,
61)
62from lexigram.ai.llm.selection.core import (
63 ModelCapabilities,
64 ModelSelector,
65 SelectionCriteria,
66 SelectionStrategy,
67 create_balanced_selector,
68 create_cost_optimized_selector,
69 create_quality_optimized_selector,
70)
71from lexigram.ai.llm.structured.exceptions import (
72 ParseError,
73 SchemaValidationError,
74 StructuredOutputError,
75)
76from lexigram.ai.llm.structured.extractor import JSONExtractor
77from lexigram.ai.llm.structured.formatter import ResponseFormatter
78from lexigram.ai.llm.structured.parser import StructuredOutputParser
79from lexigram.ai.llm.structured.utils import (
80 complete_with_json,
81 complete_with_schema,
82 create_json_mode_messages,
83)
84from lexigram.ai.llm.types import (
85 ChatMessage,
86 Completion,
87 FunctionCall,
88 LLMError,
89 Role,
90 StreamChunk,
91 TokenUsage,
92 ToolCall,
93)
94from lexigram.contracts.ai.multimodal import (
95 ContentPart,
96 ImageBase64Part,
97 ImageUrlPart,
98 MessageContent,
99 TextPart,
100)
102_LAZY_IMPORTS: dict[str, str] = {
103 "normalize_thinking_text": "lexigram.ai.llm.thinking",
104 # Events
105 "LLMCompletionEvent": "lexigram.ai.llm.events",
106 # Hooks
107 "LLMProviderRegisteredHook": "lexigram.ai.llm.hooks",
108 "LLMRequestSentHook": "lexigram.ai.llm.hooks",
109 "LLMResponseReceivedHook": "lexigram.ai.llm.hooks",
110 # Types
111 "AnthropicClient": "lexigram.ai.llm.clients.anthropic",
112 "APIPricingSource": "lexigram.ai.llm.pricing",
113 "CacheEntry": "lexigram.ai.llm.caching.core",
114 "CacheStats": "lexigram.ai.llm.caching.core",
115 "ChatMessage": "lexigram.ai.llm.types",
116 "ContentPart": "lexigram.contracts.ai.multimodal",
117 # Config
118 "ClientConfig": "lexigram.ai.llm.config",
119 "CohereClient": "lexigram.ai.llm.clients.cohere",
120 "Completion": "lexigram.ai.llm.types",
121 "ConversationConfig": "lexigram.ai.llm.conversation.manager",
122 "ConversationManager": "lexigram.ai.llm.conversation.manager",
123 "ConversationStats": "lexigram.ai.llm.conversation.manager",
124 "CostEstimate": "lexigram.ai.llm.pricing.tokens",
125 "FunctionCall": "lexigram.ai.llm.types",
126 "GenerationDefaults": "lexigram.ai.llm.routing.config",
127 "GroqClient": "lexigram.ai.llm.clients.groq",
128 "ImageBase64Part": "lexigram.contracts.ai.multimodal",
129 "ImageUrlPart": "lexigram.contracts.ai.multimodal",
130 "InstructorExtractor": "lexigram.ai.llm.extraction.extractor",
131 "JSONExtractor": "lexigram.ai.llm.structured.extractor",
132 "JSONFilePricingSource": "lexigram.ai.llm.pricing",
133 "LLMCache": "lexigram.ai.llm.caching.core",
134 "LLMCacheProtocol": "lexigram.ai.llm.protocols",
135 "LLMConfig": "lexigram.ai.llm.routing.config",
136 "LogConfig": "lexigram.ai.llm.routing.config",
137 "LLMError": "lexigram.ai.llm.types",
138 "LLMAuthenticationError": "lexigram.ai.llm.exceptions",
139 "LLMContentFilterError": "lexigram.ai.llm.exceptions",
140 "LLMModelNotFoundError": "lexigram.ai.llm.exceptions",
141 "ModelRevisionMismatchError": "lexigram.ai.llm.exceptions",
142 "LLMQuotaExceededError": "lexigram.ai.llm.exceptions",
143 "LLMRateLimitError": "lexigram.ai.llm.exceptions",
144 "InvalidRequestError": "lexigram.ai.llm.exceptions",
145 "ModelNotFoundError": "lexigram.ai.llm.exceptions",
146 "ProviderConnectionError": "lexigram.ai.llm.exceptions",
147 "StreamError": "lexigram.ai.llm.exceptions",
148 "TokenLimitError": "lexigram.ai.llm.exceptions",
149 "ExtractionError": "lexigram.ai.llm.exceptions",
150 "ExtractionParseError": "lexigram.ai.llm.exceptions",
151 "ExtractionValidationError": "lexigram.ai.llm.exceptions",
152 "ExtractionMaxRetriesError": "lexigram.ai.llm.exceptions",
153 "MessageContent": "lexigram.contracts.ai.multimodal",
154 "MistralClient": "lexigram.ai.llm.clients.mistral",
155 "ModelCapabilities": "lexigram.ai.llm.selection.core",
156 "ModelPricing": "lexigram.ai.llm.pricing",
157 "ModelSelector": "lexigram.ai.llm.selection.core",
158 "OllamaClient": "lexigram.ai.llm.clients.ollama",
159 "OpenAIClient": "lexigram.ai.llm.clients.openai",
160 "OpenRouterClient": "lexigram.ai.llm.clients.openrouter",
161 "OpenRouterPricingSource": "lexigram.ai.llm.pricing",
162 "OutputFilter": "lexigram.ai.llm.security.core",
163 "ParseError": "lexigram.ai.llm.structured.exceptions",
164 "PricingConfig": "lexigram.ai.llm.config",
165 "PricingCostEstimator": "lexigram.ai.llm.pricing.estimator",
166 "PricingManager": "lexigram.ai.llm.pricing",
167 "PricingManagerBuilder": "lexigram.ai.llm.pricing",
168 "PricingSourceConfig": "lexigram.ai.llm.config",
169 "AbstractPricingSource": "lexigram.ai.llm.pricing",
170 "ProviderConfig": "lexigram.ai.llm.routing.config",
171 # Pinning
172 "ModelPinPolicy": "lexigram.ai.llm.pinning",
173 "enforce_pin_policy": "lexigram.ai.llm.pinning",
174 # Audit
175 "LLMAuditBridge": "lexigram.ai.llm.audit_bridge",
176 # Parsers
177 "ParserRegistry": "lexigram.ai.llm.parsers.registry",
178 "JSONOutputParser": "lexigram.ai.llm.parsers.json",
179 "PydanticOutputParser": "lexigram.ai.llm.parsers.pydantic",
180 "EnumOutputParser": "lexigram.ai.llm.parsers.enum",
181 "CSVOutputParser": "lexigram.ai.llm.parsers.csv",
182 "FormatFixingParser": "lexigram.ai.llm.parsers.fixing",
183 "ProviderInfo": "lexigram.ai.llm.registry.core",
184 "ProviderRegistry": "lexigram.ai.llm.registry.core",
185 "QuotaConfig": "lexigram.ai.llm.routing.config",
186 "RateLimiter": "lexigram.ai.llm.rate_limiting.core",
187 "RedisLLMCache": "lexigram.ai.llm.caching.core",
188 "ResponseFormatter": "lexigram.ai.llm.structured.formatter",
189 "Role": "lexigram.ai.llm.types",
190 "SchemaValidationError": "lexigram.ai.llm.structured.exceptions",
191 "SecureLLMClient": "lexigram.ai.llm.security.core",
192 "SecurePromptTemplate": "lexigram.ai.llm.security.core",
193 "SelectionCriteria": "lexigram.ai.llm.selection.core",
194 "SelectionStrategy": "lexigram.ai.llm.selection.core",
195 "StaticPricingSource": "lexigram.ai.llm.pricing",
196 "StreamChunk": "lexigram.ai.llm.types",
197 "StructuredOutputError": "lexigram.ai.llm.structured.exceptions",
198 "StructuredOutputParser": "lexigram.ai.llm.structured.parser",
199 "TextPart": "lexigram.contracts.ai.multimodal",
200 "TokenCount": "lexigram.ai.llm.pricing.tokens",
201 "TiktokenCounter": "lexigram.ai.llm.pricing.tokens",
202 "CharEstimateCounter": "lexigram.ai.llm.pricing.tokens",
203 "HuggingFaceCounter": "lexigram.ai.llm.pricing.tokens",
204 "MistralCounter": "lexigram.ai.llm.pricing.tokens",
205 "TokenCounterRegistry": "lexigram.ai.llm.pricing.registry",
206 "TokenUsage": "lexigram.ai.llm.types",
207 "ToolCall": "lexigram.ai.llm.types",
208 "complete_with_json": "lexigram.ai.llm.structured.utils",
209 "complete_with_schema": "lexigram.ai.llm.structured.utils",
210 "create_assistant_template": "lexigram.ai.llm.security.core",
211 "create_balanced_selector": "lexigram.ai.llm.selection.core",
212 "create_cost_optimized_selector": "lexigram.ai.llm.selection.core",
213 "create_data_extraction_template": "lexigram.ai.llm.security.core",
214 "create_json_mode_messages": "lexigram.ai.llm.structured.utils",
215 "create_quality_optimized_selector": "lexigram.ai.llm.selection.core",
216 "create_token_counter": "lexigram.ai.llm.pricing.tokens",
217 # DI
218 "LLMModule": "lexigram.ai.llm.module",
219 "LLMProvider": "lexigram.ai.llm.di.provider",
220 "LLMRoutingProvider": "lexigram.ai.llm.di.routing_provider",
221 # Runnable composition
222 "RunnableBranch": "lexigram.ai.llm.runnable",
223 "RunnableLambda": "lexigram.ai.llm.runnable",
224 "RunnableMixin": "lexigram.ai.llm.runnable",
225 "RunnableParallel": "lexigram.ai.llm.runnable",
226 "RunnablePassthrough": "lexigram.ai.llm.runnable",
227 "RunnableSequence": "lexigram.ai.llm.runnable",
228}
231def __getattr__(name: str) -> Any:
232 if name in _LAZY_IMPORTS:
233 import importlib as _importlib
235 module = _importlib.import_module(_LAZY_IMPORTS[name])
236 value = getattr(module, name)
237 globals()[name] = value
238 return value
239 raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
242def __dir__() -> list[str]:
243 return sorted(set(__all__) | set(_LAZY_IMPORTS.keys()))
246__all__ = list(_LAZY_IMPORTS.keys())