From c34886b362b6d644da55d6995dc8ad6a675d9349 Mon Sep 17 00:00:00 2001 From: Ethanfel Date: Sat, 27 Jun 2026 14:04:00 +0200 Subject: [PATCH] Use route-owned formatter style choices --- caption_policy.py | 4 ++++ krea_format_route.py | 15 ++++++++++++++- node_formatter.py | 10 ++++++---- tools/prompt_smoke.py | 7 +++++++ 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/caption_policy.py b/caption_policy.py index 2becb69..042a7a4 100644 --- a/caption_policy.py +++ b/caption_policy.py @@ -81,6 +81,10 @@ def normalize_style_policy(value: str) -> str: return value if value in STYLE_POLICIES else "drop_style_tail" +def style_policy_choices() -> list[str]: + return list(STYLE_POLICIES) + + def caption_profile_choices() -> list[str]: return list(CAPTION_PROFILES) diff --git a/krea_format_route.py b/krea_format_route.py index bb6a22c..65d9f43 100644 --- a/krea_format_route.py +++ b/krea_format_route.py @@ -11,6 +11,19 @@ except ImportError: # pragma: no cover - plain-script smoke tests import formatter_target as target_policy +STYLE_MODES = ("preserve", "photographic", "minimal") +DEFAULT_STYLE_MODE = "preserve" + + +def style_mode_choices() -> list[str]: + return list(STYLE_MODES) + + +def normalize_style_mode(value: Any) -> str: + mode = str(value or "").strip().lower().replace("-", "_").replace(" ", "_") + return mode if mode in STYLE_MODES else DEFAULT_STYLE_MODE + + @dataclass(frozen=True) class KreaFormatRequest: source_text: str @@ -51,7 +64,7 @@ class KreaFormatDependencies: def format_krea2_prompt_result(request: KreaFormatRequest, deps: KreaFormatDependencies) -> KreaFormatRoute: detail_level = detail_policy.normalize_detail_level(request.detail_level) - style_mode = request.style_mode if request.style_mode in ("preserve", "photographic", "minimal") else "preserve" + style_mode = normalize_style_mode(request.style_mode) target = target_policy.normalize_target(request.target) row, method = deps.row_from_inputs(request.source_text, request.metadata_json, request.input_hint) diff --git a/node_formatter.py b/node_formatter.py index 8d4a240..de955c9 100644 --- a/node_formatter.py +++ b/node_formatter.py @@ -2,10 +2,11 @@ from __future__ import annotations try: from .caption_naturalizer import naturalize_caption - from .caption_policy import caption_profile_choices + from .caption_policy import caption_profile_choices, style_policy_choices from .formatter_detail import detail_level_choices from .formatter_input import INPUT_HINT_CAPTION_OR_PROMPT, INPUT_HINT_PROMPT, input_hint_choices from .formatter_target import target_choices + from .krea_format_route import style_mode_choices from .krea_formatter import format_krea2_prompt from .sdxl_formatter import ( format_sdxl_prompt, @@ -15,10 +16,11 @@ try: ) except ImportError: # Allows local smoke tests from the repository root. from caption_naturalizer import naturalize_caption - from caption_policy import caption_profile_choices + from caption_policy import caption_profile_choices, style_policy_choices from formatter_detail import detail_level_choices from formatter_input import INPUT_HINT_CAPTION_OR_PROMPT, INPUT_HINT_PROMPT, input_hint_choices from formatter_target import target_choices + from krea_format_route import style_mode_choices from krea_formatter import format_krea2_prompt from sdxl_formatter import ( format_sdxl_prompt, @@ -37,7 +39,7 @@ class SxCPCaptionNaturalizer: "input_hint": (input_hint_choices(text_hint=INPUT_HINT_CAPTION_OR_PROMPT), {"default": "auto"}), "caption_profile": (caption_profile_choices(), {"default": "manual_controls"}), "detail_level": (detail_level_choices(), {"default": "balanced"}), - "style_policy": (["drop_style_tail", "keep_style_terms"], {"default": "drop_style_tail"}), + "style_policy": (style_policy_choices(), {"default": "drop_style_tail"}), "trigger": ("STRING", {"default": "sxcppnl7"}), "include_trigger": ("BOOLEAN", {"default": True}), "target": (target_choices(), {"default": "auto"}), @@ -89,7 +91,7 @@ class SxCPKrea2Formatter: "input_hint": (input_hint_choices(text_hint=INPUT_HINT_PROMPT), {"default": "auto"}), "target": (target_choices(), {"default": "auto"}), "detail_level": (detail_level_choices(), {"default": "balanced"}), - "style_mode": (["preserve", "photographic", "minimal"], {"default": "preserve"}), + "style_mode": (style_mode_choices(), {"default": "preserve"}), "preserve_trigger": ("BOOLEAN", {"default": False}), }, "optional": { diff --git a/tools/prompt_smoke.py b/tools/prompt_smoke.py index f1af5c0..7147adc 100644 --- a/tools/prompt_smoke.py +++ b/tools/prompt_smoke.py @@ -2989,6 +2989,9 @@ def smoke_krea_format_route_policy() -> None: _expect(typed_fallback.target == "auto", "Typed Krea format route should normalize invalid target") _expect(typed_fallback.detail_level == "balanced", "Typed Krea format route should normalize invalid detail level") _expect(typed_fallback.style_mode == "preserve", "Typed Krea format route should normalize invalid style mode") + _expect(krea_format_route.style_mode_choices() == ["preserve", "photographic", "minimal"], "Krea style mode choices changed") + _expect(krea_format_route.normalize_style_mode("photographic") == "photographic", "Krea style mode lost photographic") + _expect(krea_format_route.normalize_style_mode("bad") == "preserve", "Krea style mode invalid fallback changed") _expect("blur" in typed_fallback.output.get("negative_prompt", ""), "Typed Krea fallback route lost Avoid negative") @@ -3035,6 +3038,8 @@ def smoke_caption_policy() -> None: "Caption naturalizer action labels should delegate to caption_policy", ) _expect(caption_policy.normalize_detail_level("bad") == "balanced", "Caption invalid detail fallback changed") + _expect(caption_policy.normalize_style_policy("bad") == "drop_style_tail", "Caption invalid style fallback changed") + _expect(caption_policy.style_policy_choices() == ["drop_style_tail", "keep_style_terms"], "Caption style policy choices changed") _expect(caption_policy.keep_style_terms("keep_style_terms") is True, "Caption style policy keep flag changed") _expect(caption_policy.detail_allows("concise") is False, "Caption concise detail gate changed") _expect(caption_policy.detail_allows("dense", dense_only=True) is True, "Caption dense-only gate changed") @@ -6309,9 +6314,11 @@ def smoke_node_formatter_registration() -> None: _expect("target" in caption_inputs, "Caption Naturalizer lost target input") _expect(caption_inputs["target"][0] == formatter_target.target_choices(), "Caption Naturalizer target choices drifted") _expect(caption_inputs["detail_level"][0] == formatter_detail.detail_level_choices(), "Caption Naturalizer detail choices drifted") + _expect(caption_inputs["style_policy"][0] == caption_policy.style_policy_choices(), "Caption Naturalizer style choices drifted") _expect("tooltip" in caption_inputs["caption_profile"][1], "Caption profile tooltip injection missing") _expect(krea_inputs["target"][0] == formatter_target.target_choices(), "Krea2 Formatter target choices drifted") _expect(krea_inputs["detail_level"][0] == formatter_detail.detail_level_choices(), "Krea2 Formatter detail choices drifted") + _expect(krea_inputs["style_mode"][0] == krea_format_route.style_mode_choices(), "Krea2 Formatter style choices drifted") krea_output = krea_node().build( "sxcppnl7 A woman standing by a window",