Consume formatter hints
This commit is contained in:
@@ -5,6 +5,7 @@ from typing import Any
|
||||
|
||||
try:
|
||||
from . import formatter_input as input_policy
|
||||
from . import category_template_metadata as template_metadata_policy
|
||||
from .krea_action_context import (
|
||||
is_close_foreplay_text as _is_close_foreplay_text,
|
||||
is_outercourse_text as _is_outercourse_text,
|
||||
@@ -35,6 +36,7 @@ try:
|
||||
from .prompt_hygiene import sanitize_negative_text, sanitize_prose_text
|
||||
except ImportError: # Allows local smoke tests with `python -c`.
|
||||
import formatter_input as input_policy
|
||||
import category_template_metadata as template_metadata_policy
|
||||
from krea_action_context import (
|
||||
is_close_foreplay_text as _is_close_foreplay_text,
|
||||
is_outercourse_text as _is_outercourse_text,
|
||||
@@ -102,6 +104,25 @@ def _paragraph(parts: list[str]) -> str:
|
||||
return " ".join(part for part in (_sentence(part) for part in parts) if part)
|
||||
|
||||
|
||||
def _formatter_hint_parts(*rows: dict[str, Any]) -> list[str]:
|
||||
hints: list[str] = []
|
||||
for row in rows:
|
||||
if not isinstance(row, dict):
|
||||
continue
|
||||
for hint in template_metadata_policy.formatter_hints_for_route(row, "krea"):
|
||||
hint = _clean(hint).strip(" .")
|
||||
if hint and hint not in hints:
|
||||
hints.append(hint)
|
||||
return hints
|
||||
|
||||
|
||||
def _append_formatter_hints(prompt: str, *rows: dict[str, Any]) -> str:
|
||||
hints = _formatter_hint_parts(*rows)
|
||||
if not hints:
|
||||
return prompt
|
||||
return _paragraph([prompt, *hints])
|
||||
|
||||
|
||||
def _with_indefinite_article(text: str) -> str:
|
||||
text = _clean(text)
|
||||
if not text or text.lower().startswith(("a ", "an ")):
|
||||
@@ -715,6 +736,10 @@ def format_krea2_prompt(
|
||||
|
||||
if row and row.get("mode") == "Insta/OF":
|
||||
soft_prompt, soft_negative, hard_prompt, hard_negative = _insta_pair_to_krea(row, detail_level, style_mode)
|
||||
soft_row = row.get("softcore_row") if isinstance(row.get("softcore_row"), dict) else {}
|
||||
hard_row = row.get("hardcore_row") if isinstance(row.get("hardcore_row"), dict) else {}
|
||||
soft_prompt = _append_formatter_hints(soft_prompt, row, soft_row)
|
||||
hard_prompt = _append_formatter_hints(hard_prompt, row, hard_row)
|
||||
if extra_positive.strip():
|
||||
soft_prompt = f"{soft_prompt.rstrip()} {extra_positive.strip()}"
|
||||
hard_prompt = f"{hard_prompt.rstrip()} {extra_positive.strip()}"
|
||||
@@ -735,6 +760,7 @@ def format_krea2_prompt(
|
||||
|
||||
if row:
|
||||
prompt, kind = _normal_row_to_krea(row, detail_level, style_mode)
|
||||
prompt = _append_formatter_hints(prompt, row)
|
||||
extracted_negative = _clean(row.get("negative_prompt"))
|
||||
method = f"{method}:krea2({kind})"
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user