Coverage for /home/admin/Documents/AI/applications/lexigram-dev/lexigram/experimental/ai/lexigram-ai-prompt/src/lexigram/ai/prompt/__init__.py: 40%
15 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"""lexigram-ai-prompt — Prompt management for the Lexigram AI framework.
3Public API
4----------
5Templates
6~~~~~~~~~
7.. autosummary::
9 StringPromptTemplate
10 ChatPromptTemplate
11 FewShotPromptTemplate
12 InMemoryExampleSelector
13 PartialPromptTemplate
14 AbstractPromptTemplate
16Variables
17~~~~~~~~~
18.. autosummary::
20 PromptVariable
21 PromptContext
23Rendering
24~~~~~~~~~
25.. autosummary::
27 PromptRenderer
28 RenderFormat
29 InputSanitizer
31Composition
32~~~~~~~~~~~
33.. autosummary::
35 PromptPipeline
36 ConditionalPrompt
38Registry
39~~~~~~~~
40.. autosummary::
42 PromptRegistry
43 VersionedPromptStore
45Configuration & DI
46~~~~~~~~~~~~~~~~~~
47.. autosummary::
49 PromptConfig
50 PromptModule
51 PromptProvider
53Exceptions
54~~~~~~~~~~
55.. autosummary::
57 PromptError
58 PromptRenderError
59 PromptValidationError
60 PromptNotFoundError
61 PromptVersionError
62 PromptConfigError
63"""
65from __future__ import annotations
67from typing import TYPE_CHECKING
69if TYPE_CHECKING:
70 from lexigram.ai.prompt.composition.conditional import ConditionalPrompt
71 from lexigram.ai.prompt.composition.pipeline import PromptPipeline
72 from lexigram.ai.prompt.config import PromptConfig
73 from lexigram.ai.prompt.decorators import prompt_template
74 from lexigram.ai.prompt.di.provider import PromptProvider
75 from lexigram.ai.prompt.exceptions import (
76 PromptConfigError,
77 PromptError,
78 PromptNotFoundError,
79 PromptRenderError,
80 PromptValidationError,
81 PromptVersionError,
82 )
83 from lexigram.ai.prompt.hooks import (
84 PromptInputSanitizedHook,
85 PromptRenderedHook,
86 PromptTemplateResolvedHook,
87 )
88 from lexigram.ai.prompt.module import PromptModule
89 from lexigram.ai.prompt.protocols import (
90 PromptOptimizerProtocol,
91 PromptRendererProtocol,
92 )
93 from lexigram.ai.prompt.registry.registry import PromptRegistry
94 from lexigram.ai.prompt.registry.versioned import VersionedPromptStore
95 from lexigram.ai.prompt.rendering.engine import PromptRenderer, RenderFormat
96 from lexigram.ai.prompt.rendering.sanitizer import InputSanitizer
97 from lexigram.ai.prompt.template.base import AbstractPromptTemplate
98 from lexigram.ai.prompt.template.chat import ChatPromptTemplate
99 from lexigram.ai.prompt.template.few_shot import (
100 FewShotPromptTemplate,
101 InMemoryExampleSelector,
102 )
103 from lexigram.ai.prompt.template.partial import PartialPromptTemplate
104 from lexigram.ai.prompt.template.string import StringPromptTemplate
105 from lexigram.ai.prompt.variables.types import PromptContext, PromptVariable
107_LAZY_IMPORTS: dict[str, tuple[str, str]] = {
108 "AbstractPromptTemplate": (
109 "lexigram.ai.prompt.template.base",
110 "AbstractPromptTemplate",
111 ),
112 "CacheAwarePromptAssembler": (
113 "lexigram.ai.prompt.assembly",
114 "CacheAwarePromptAssembler",
115 ),
116 "ChatPromptTemplate": ("lexigram.ai.prompt.template.chat", "ChatPromptTemplate"),
117 "ConditionalPrompt": (
118 "lexigram.ai.prompt.composition.conditional",
119 "ConditionalPrompt",
120 ),
121 "FewShotPromptTemplate": (
122 "lexigram.ai.prompt.template.few_shot",
123 "FewShotPromptTemplate",
124 ),
125 "InMemoryExampleSelector": (
126 "lexigram.ai.prompt.template.few_shot",
127 "InMemoryExampleSelector",
128 ),
129 "InputSanitizer": ("lexigram.ai.prompt.rendering.sanitizer", "InputSanitizer"),
130 "PartialPromptTemplate": (
131 "lexigram.ai.prompt.template.partial",
132 "PartialPromptTemplate",
133 ),
134 "PromptConfig": ("lexigram.ai.prompt.config", "PromptConfig"),
135 "PromptConfigError": ("lexigram.ai.prompt.exceptions", "PromptConfigError"),
136 "PromptContext": ("lexigram.ai.prompt.variables.types", "PromptContext"),
137 "PromptError": ("lexigram.ai.prompt.exceptions", "PromptError"),
138 "PromptInputSanitizedHook": (
139 "lexigram.ai.prompt.hooks",
140 "PromptInputSanitizedHook",
141 ),
142 "PromptModule": ("lexigram.ai.prompt.module", "PromptModule"),
143 "PromptNotFoundError": ("lexigram.ai.prompt.exceptions", "PromptNotFoundError"),
144 "PromptPipeline": ("lexigram.ai.prompt.composition.pipeline", "PromptPipeline"),
145 "PromptProvider": ("lexigram.ai.prompt.di.provider", "PromptProvider"),
146 "PromptRegistry": ("lexigram.ai.prompt.registry.registry", "PromptRegistry"),
147 "PromptRenderError": ("lexigram.ai.prompt.exceptions", "PromptRenderError"),
148 "PromptRenderedHook": ("lexigram.ai.prompt.hooks", "PromptRenderedHook"),
149 "PromptRenderer": ("lexigram.ai.prompt.rendering.engine", "PromptRenderer"),
150 "PromptTemplateResolvedHook": (
151 "lexigram.ai.prompt.hooks",
152 "PromptTemplateResolvedHook",
153 ),
154 "PromptValidationError": ("lexigram.ai.prompt.exceptions", "PromptValidationError"),
155 "PromptVariable": ("lexigram.ai.prompt.variables.types", "PromptVariable"),
156 "PromptVersionError": ("lexigram.ai.prompt.exceptions", "PromptVersionError"),
157 "ProviderCacheStrategyRegistry": (
158 "lexigram.ai.prompt.assembly",
159 "ProviderCacheStrategyRegistry",
160 ),
161 "prompt_template": ("lexigram.ai.prompt.decorators", "prompt_template"),
162 "RenderFormat": ("lexigram.ai.prompt.rendering.engine", "RenderFormat"),
163 "StringPromptTemplate": (
164 "lexigram.ai.prompt.template.string",
165 "StringPromptTemplate",
166 ),
167 "VersionedPromptStore": (
168 "lexigram.ai.prompt.registry.versioned",
169 "VersionedPromptStore",
170 ),
171 # Internal protocols
172 "PromptAssemblerProtocol": (
173 "lexigram.ai.prompt.protocols",
174 "PromptAssemblerProtocol",
175 ),
176 "PromptCompressorProtocol": (
177 "lexigram.ai.prompt.protocols",
178 "PromptCompressorProtocol",
179 ),
180 "PromptOptimizerProtocol": (
181 "lexigram.ai.prompt.protocols",
182 "PromptOptimizerProtocol",
183 ),
184 "PromptRegistryProtocol": (
185 "lexigram.ai.prompt.protocols",
186 "PromptRegistryProtocol",
187 ),
188 "PromptRendererProtocol": (
189 "lexigram.ai.prompt.protocols",
190 "PromptRendererProtocol",
191 ),
192 "PromptTemplateProtocol": (
193 "lexigram.ai.prompt.protocols",
194 "PromptTemplateProtocol",
195 ),
196 "PromptRenderedEvent": ("lexigram.ai.prompt.events", "PromptRenderedEvent"),
197}
199__all__ = list(_LAZY_IMPORTS)
202def __getattr__(name: str) -> object:
203 """Lazy-load public symbols on first access."""
204 if name in _LAZY_IMPORTS:
205 import importlib
207 module_path, attr = _LAZY_IMPORTS[name]
208 mod = importlib.import_module(module_path)
209 value = getattr(mod, attr)
210 globals()[name] = value
211 return value
212 raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
215def __dir__() -> list[str]:
216 """Expose lazy-loaded names for tab completion and dir()."""
217 return list(_LAZY_IMPORTS)