feat: value table + {{placeholder|d}} modifier (Issue #47)
Deploy Development / deploy (push) Successful in 48s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 15s

FEATURE #47: Wertetabelle nach KI-Analysen
- Migration 021: metadata JSONB column in ai_insights
- Backend sammelt resolved placeholders mit descriptions beim Speichern
- Frontend: Collapsible value table in InsightCard
  - Zeigt: Platzhalter | Wert | Beschreibung
  - Sortiert tabellarisch
  - Funktioniert für base + pipeline prompts

FEATURE #48: {{placeholder|d}} Modifier
- Syntax: {{weight_aktuell|d}} → "85.2 kg (Aktuelles Gewicht in kg)"
- resolve_placeholders() erkennt |d modifier
- Hängt description aus catalog an Wert
- Fein-granulare Kontrolle pro Platzhalter (nicht global)
- Optional: nur wo sinnvoll einsetzen

TECHNICAL:
- prompt_executor.py: catalog parameter durchgereicht
- execute_prompt_with_data() lädt catalog via get_placeholder_catalog()
- Catalog als _catalog in variables übergeben, in execute_prompt() extrahiert
- Base + Pipeline Prompts unterstützen |d modifier

EXAMPLE:
Template: "Gewicht: {{weight_aktuell|d}}, Alter: {{age}}"
Output:   "Gewicht: 85.2 kg (Aktuelles Gewicht in kg), Alter: 55"

version: 9.6.0 (feature)
module: prompts 2.1.0, insights 1.4.0
This commit is contained in:
Lars committed 2026-03-26 11:52:26 +01:00
1 parent c56d2b2201
commit c0a50dedcd
4 files changed
+174 -16

No files matched your search

+60 -4
View File
@@ -812,13 +812,69 @@ async def execute_unified_prompt(
if isinstance(content, dict):
content = json.dumps(content, ensure_ascii=False)
# Save to database
# Prepare metadata with resolved placeholders and descriptions
from placeholder_resolver import get_placeholder_catalog
metadata = {
'prompt_type': result['type'],
'placeholders': {}
}
# Collect all resolved placeholders from debug info
if result.get('debug'):
catalog = get_placeholder_catalog(profile_id)
if result['type'] == 'base':
# Base prompt: single set of placeholders
resolved = result['debug'].get('resolved_placeholders', {})
for key, value in resolved.items():
# Find description in catalog
desc = None
for cat_items in catalog.values():
matching = [item for item in cat_items if item['key'] == key]
if matching:
desc = matching[0].get('description', '')
break
metadata['placeholders'][key] = {
'value': value,
'description': desc or ''
}
elif result['type'] == 'pipeline':
# Pipeline: collect from all stages
stages_debug = result['debug'].get('stages', [])
for stage_debug in stages_debug:
for prompt_debug in stage_debug.get('prompts', []):
resolved = {}
# Check both direct and ref_debug
if 'resolved_placeholders' in prompt_debug:
resolved = prompt_debug['resolved_placeholders']
elif 'ref_debug' in prompt_debug and 'resolved_placeholders' in prompt_debug['ref_debug']:
resolved = prompt_debug['ref_debug']['resolved_placeholders']
for key, value in resolved.items():
if key not in metadata['placeholders']: # Avoid duplicates
# Find description in catalog
desc = None
for cat_items in catalog.values():
matching = [item for item in cat_items if item['key'] == key]
if matching:
desc = matching[0].get('description', '')
break
metadata['placeholders'][key] = {
'value': value,
'description': desc or ''
}
# Save to database with metadata
with get_db() as conn:
cur = get_cursor(conn)
cur.execute(
"""INSERT INTO ai_insights (id, profile_id, scope, content, created)
VALUES (%s, %s, %s, %s, CURRENT_TIMESTAMP)""",
(str(uuid.uuid4()), profile_id, prompt_slug, content)
"""INSERT INTO ai_insights (id, profile_id, scope, content, metadata, created)
VALUES (%s, %s, %s, %s, %s, CURRENT_TIMESTAMP)""",
(str(uuid.uuid4()), profile_id, prompt_slug, content, json.dumps(metadata))
)
conn.commit()