feat: Enhance placeholder system with AI context support
- Introduced `build_ai_placeholder_caption` function in `placeholder_registry.py` to generate AI context captions based on placeholder metadata. - Updated `resolve_placeholders` in `placeholder_resolver.py` to support modifiers for AI context, allowing for enhanced descriptions when placeholders are resolved. - Modified `get_placeholder_catalog` to include AI captions in the output, improving the metadata available for placeholders. - Adjusted `export_placeholder_values` to include AI captions in the exported data, enhancing the information provided to users. These changes improve the flexibility and functionality of the placeholder system, enabling richer context generation for dynamic content.
This commit is contained in:
1 parent
41bf593d4c
commit
baeddd7c13
5 files changed
+146
-27
No files matched your search
@@ -258,6 +258,40 @@ class PlaceholderRegistry:
|
||||
return metadata._resolver_func(profile_id)
|
||||
|
||||
|
||||
def build_ai_placeholder_caption(metadata: PlaceholderMetadata, max_len: int = 400) -> str:
|
||||
"""
|
||||
Kurztext für KI-Kontext (z. B. Modifier |d): Bedeutung/Skala, ohne die Rohausgabe zu ersetzen.
|
||||
Nutzt business_meaning / semantic_contract; bei Scores explizite 0–100-Erläuterung.
|
||||
"""
|
||||
chunks: List[str] = []
|
||||
bm = (metadata.business_meaning or "").strip()
|
||||
sc = (metadata.semantic_contract or "").strip()
|
||||
desc = (metadata.description or "").strip()
|
||||
|
||||
if bm:
|
||||
chunks.append(bm)
|
||||
elif sc:
|
||||
chunks.append(sc if len(sc) <= max_len else sc[: max_len - 1] + "…")
|
||||
elif desc:
|
||||
chunks.append(desc)
|
||||
|
||||
if metadata.placeholder_type == PlaceholderType.SCORE:
|
||||
chunks.append("Skala 0–100: höher = im Modell günstiger / besser abgestimmt.")
|
||||
|
||||
unit = (metadata.unit or "").strip()
|
||||
if unit and metadata.placeholder_type != PlaceholderType.SCORE:
|
||||
blob = " ".join(chunks).lower()
|
||||
u_low = unit.lower()
|
||||
if u_low not in blob and u_low.replace(" ", "") not in blob.replace(" ", ""):
|
||||
if u_low not in ("score (0-100)", "0-100", "0–100", "dimensionless"):
|
||||
chunks.append(f"Technischer Bezug: {unit}.")
|
||||
|
||||
out = " ".join(c for c in chunks if c).strip()
|
||||
if len(out) > max_len + 120:
|
||||
out = out[: max_len + 60] + "…"
|
||||
return out or desc or metadata.key
|
||||
|
||||
|
||||
# Global registry instance
|
||||
_global_registry = PlaceholderRegistry()
|
||||
|
||||
|
||||
Reference in new issue
Block a user