feat: Enhance placeholder caption generation and formatting
Deploy Development / deploy (push) Successful in 54s
Build Test / pytest-backend (push) Successful in 8s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 16s

- Updated `build_ai_placeholder_caption` in `placeholder_registry.py` to improve the generation of AI context captions by prioritizing descriptions and avoiding redundancy.
- Introduced `format_value_with_d_modifier` in `placeholder_resolver.py` to format values with contextual information, enhancing the clarity of exported placeholder values.
- Modified `export_placeholder_values` in `prompts.py` to utilize the new formatting function, ensuring that exported data includes both raw values and contextual descriptions.
- Added tests for the new formatting function and updated existing tests to ensure accurate caption generation.

These changes improve the contextual relevance of placeholder data and enhance the user experience when interacting with exported values.
This commit is contained in:
Lars committed 2026-04-11 21:47:08 +02:00
1 parent baeddd7c13
commit a9a414b956
4 files changed
+91 -19

No files matched your search

@@ -6,6 +6,7 @@ from placeholder_registry import (
build_ai_placeholder_caption,
)
import placeholder_resolver as pr
from placeholder_resolver import format_value_with_d_modifier
def test_build_ai_caption_prefers_business_meaning():
@@ -22,9 +23,28 @@ def test_build_ai_caption_prefers_business_meaning():
output_type=OutputType.NUMERIC,
)
cap = build_ai_placeholder_caption(m)
assert cap.startswith("Kurzbeschreibung")
assert "Kernbedeutung" in cap
def test_build_ai_caption_description_then_meaning_like_protein_avg():
m = PlaceholderMetadata(
key="protein_avg",
category="Ernährung",
description="Durchschn. Protein in g (30d)",
resolver_module="m",
resolver_function="f",
business_meaning="Zentraler Placeholder für Muskelerhalt.",
unit="g/day",
placeholder_type=PlaceholderType.INTERPRETED,
output_type=OutputType.NUMERIC,
)
cap = build_ai_placeholder_caption(m)
assert cap.startswith("Durchschn. Protein in g (30d)")
assert "Muskelerhalt" in cap
assert "Technischer Bezug" not in cap
def test_build_ai_caption_score_adds_scale():
m = PlaceholderMetadata(
key="test_score",
@@ -54,3 +74,19 @@ def test_placeholder_token_regex_optional_modifier():
def test_get_unknown_placeholders_strips_modifier():
unk = pr.get_unknown_placeholders("{{not_a_real_key|d}}")
assert set(unk) == {"not_a_real_key"}
def test_format_value_with_d_modifier_matches_prompt_executor():
row = {
"key": "protein_avg",
"description": "Durchschn. Protein in g (30d)",
"example": "119g/Tag",
"ai_caption": "Durchschn. Protein in g (30d). Zentral für Muskelerhalt.",
}
out = format_value_with_d_modifier("119g/Tag", row)
assert out == "119g/Tag — Durchschn. Protein in g (30d). Zentral für Muskelerhalt."
def test_format_value_with_d_modifier_falls_back_to_description():
row = {"description": "Nur Beschreibung", "key": "x"}
assert format_value_with_d_modifier("42", row) == "42 — Nur Beschreibung"