This commit is contained in:
team3
2026-07-10 15:43:11 +02:00
commit 0a41166cca
72 changed files with 7772 additions and 0 deletions

29
backend/prompts.py Normal file
View File

@@ -0,0 +1,29 @@
"""Template-Lader: templates/<Name>.md, Platzhalter {name}, Datei-Hash je Call
(Ledger — uncommittete Prompt-Änderungen bleiben nachvollziehbar)."""
import hashlib
from functools import lru_cache
from config import TEMPLATES_DIR
@lru_cache(maxsize=None)
def _lade(name: str) -> tuple[str, str]:
text = (TEMPLATES_DIR / f"{name}.md").read_text(encoding="utf-8")
return text, hashlib.sha256(text.encode()).hexdigest()[:12]
def render(name: str, **werte) -> tuple[str, str]:
"""→ (prompt, template_hash). format_map, damit geschweifte Klammern in
JSON-Beispielen doppelt geschrieben werden ({{ }})."""
text, h = _lade(name)
return text.format_map(_Sicher(werte)), h
class _Sicher(dict):
def __missing__(self, key):
raise KeyError(f"Template-Platzhalter fehlt: {key}")
def cache_leeren() -> None:
_lade.cache_clear()