feat: Refine placeholder resolution with enhanced modifiers support
- Updated `resolve_placeholders` in `prompt_executor.py` to support combined modifiers for placeholders, allowing for more flexible output formats. - Enhanced `build_ai_placeholder_caption` in `placeholder_registry.py` to clarify the generation of AI context captions, focusing on descriptions and explanations. - Introduced new helper functions in `placeholder_resolver.py` to streamline the retrieval of descriptions and explanations for placeholders. - Modified tests to cover new functionality, ensuring accurate behavior for combined modifiers and improved placeholder resolution. These changes enhance the usability and clarity of placeholder outputs, providing users with richer contextual information.
This commit is contained in:
1 parent
a9a414b956
commit
4868e44882
5 files changed
+151
-91
No files matched your search
@@ -260,27 +260,24 @@ class PlaceholderRegistry:
|
||||
|
||||
def build_ai_placeholder_caption(metadata: PlaceholderMetadata, max_len: int = 400) -> str:
|
||||
"""
|
||||
Text für |d und Exportfeld ai_caption: zuerst **was** der Platzhalter misst (description),
|
||||
dann **Einordnung** (business_meaning oder gekürzter semantic_contract).
|
||||
So ist klar, worauf sich der konkrete Wert bezieht — nicht nur eine „Meta-Bedeutung“.
|
||||
Kurzerklärung / Einordnung für {{key|x}} und Exportfeld ``ai_caption`` (ohne Wert, ohne Einheit).
|
||||
|
||||
Inhalt: business_meaning oder gekürzter semantic_contract; bei SCORE-Zeilen die 0–100-Skala.
|
||||
Nicht enthalten: description (die nur bei {{key|d}} angehängt wird) und keine „Technischer Bezug: …“-Zeile.
|
||||
"""
|
||||
desc = (metadata.description or "").strip()
|
||||
bm = (metadata.business_meaning or "").strip()
|
||||
sc = (metadata.semantic_contract or "").strip()
|
||||
|
||||
chunks: List[str] = []
|
||||
if desc:
|
||||
chunks.append(desc)
|
||||
|
||||
interpret = bm
|
||||
if not interpret and sc:
|
||||
interpret = sc if len(sc) <= max_len else sc[: max_len - 1] + "…"
|
||||
|
||||
if interpret:
|
||||
blob = " ".join(chunks).lower()
|
||||
il = interpret.lower()
|
||||
# Keine Dublette: gleicher Text oder lange Description bereits in der Interpretation
|
||||
redundant = il in blob or (
|
||||
redundant = bool(
|
||||
desc
|
||||
and len(desc) >= 10
|
||||
and desc.lower() in il
|
||||
@@ -291,27 +288,10 @@ def build_ai_placeholder_caption(metadata: PlaceholderMetadata, max_len: int = 4
|
||||
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()
|
||||
# Einheit oft schon in description („… in g (30d)“, „Kalorien“) — nicht doppeln
|
||||
compact_blob = blob.replace(" ", "").replace("/", "")
|
||||
compact_u = u_low.replace(" ", "").replace("/", "")
|
||||
unit_redundant = compact_u in compact_blob or (
|
||||
"g/day" in u_low and ("g/" in blob or "gramm" in blob or " protein" in blob or " fett" in blob or " kh" in blob)
|
||||
) or ("kcal" in u_low and ("kcal" in blob or "kalorien" in blob))
|
||||
|
||||
if (
|
||||
not unit_redundant
|
||||
and 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
|
||||
return out
|
||||
|
||||
|
||||
# Global registry instance
|
||||
|
||||
Reference in new issue
Block a user