Consume formatter hints

This commit is contained in:
2026-06-27 02:17:04 +02:00
parent dfdfff953b
commit 7d112c0f98
7 changed files with 145 additions and 5 deletions
+24 -2
View File
@@ -5,11 +5,13 @@ from typing import Any
try:
from . import caption_policy
from . import category_template_metadata as template_metadata_policy
from . import formatter_input as input_policy
from . import krea_cast as cast_policy
from .prompt_hygiene import sanitize_prose_text
except ImportError: # Allows local smoke tests with `python -c`.
import caption_policy
import category_template_metadata as template_metadata_policy
import formatter_input as input_policy
import krea_cast as cast_policy
from prompt_hygiene import sanitize_prose_text
@@ -67,6 +69,24 @@ def _join_sentences(parts: list[str]) -> str:
return " ".join(part for part in (_sentence(part) for part in parts) if part)
def _formatter_hint_parts(row: dict[str, Any]) -> list[str]:
hints: list[str] = []
if not isinstance(row, dict):
return hints
for hint in template_metadata_policy.formatter_hints_for_route(row, "caption"):
hint = _clean_text(hint).strip(" .")
if hint and hint not in hints:
hints.append(hint)
return hints
def _append_formatter_hints(prose: str, row: dict[str, Any]) -> str:
hints = _formatter_hint_parts(row)
if not hints:
return prose
return _join_sentences([prose, *hints])
def _human_join(parts: list[str]) -> str:
parts = [part for part in (_clean_text(part) for part in parts) if part]
if len(parts) <= 1:
@@ -538,8 +558,10 @@ def _metadata_to_prose(row: dict[str, Any], detail_level: str, keep_style: bool)
):
result = builder(row, detail_level, keep_style)
if result:
return result
return _text_to_prose(_clean_text(row.get("caption") or row.get("prompt")), detail_level, keep_style)
prose, method = result
return _append_formatter_hints(prose, row), method
prose, method = _text_to_prose(_clean_text(row.get("caption") or row.get("prompt")), detail_level, keep_style)
return _append_formatter_hints(prose, row), method
def _prompt_to_prose(text: str, detail_level: str, keep_style: bool) -> tuple[str, str] | None: