From 928f55d2c3bb74d7cb8e058aa75bfd852ff978ce Mon Sep 17 00:00:00 2001 From: Ethanfel Date: Sat, 27 Jun 2026 13:49:42 +0200 Subject: [PATCH] Use shared formatter target choices --- docs/prompt-architecture-improvement-plan.md | 7 ++++--- formatter_target.py | 4 ++++ node_formatter.py | 8 +++++--- tools/prompt_smoke.py | 7 +++++++ 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/docs/prompt-architecture-improvement-plan.md b/docs/prompt-architecture-improvement-plan.md index 9e5d22a..bd2d255 100644 --- a/docs/prompt-architecture-improvement-plan.md +++ b/docs/prompt-architecture-improvement-plan.md @@ -89,9 +89,10 @@ Formatter target handling now has one home: - `formatter_target.py` It owns route-neutral target normalization for `auto`, `single`, `softcore`, -and `hardcore`, including pair-side semantics. Single-output formatters select -the softcore side for pair `auto`/`single` targets, while caption pair routing -can still include both sides for combined training captions. +and `hardcore`, including node choice lists and pair-side semantics. +Single-output formatters select the softcore side for pair `auto`/`single` +targets, while caption pair routing can still include both sides for combined +training captions. Shared hardcore phrase cleanup now has one home: diff --git a/formatter_target.py b/formatter_target.py index 3705e98..e3fdf2b 100644 --- a/formatter_target.py +++ b/formatter_target.py @@ -26,6 +26,10 @@ class PairTargetPolicy: include_hardcore: bool +def target_choices() -> list[str]: + return list(FORMATTER_TARGETS) + + def normalize_target(value: Any) -> str: target = str(value or "").strip().lower().replace("-", "_").replace(" ", "_") target = _TARGET_ALIASES.get(target, target) diff --git a/node_formatter.py b/node_formatter.py index fe3b4d5..55ae88e 100644 --- a/node_formatter.py +++ b/node_formatter.py @@ -4,6 +4,7 @@ try: from .caption_naturalizer import naturalize_caption from .caption_policy import caption_profile_choices from .formatter_input import INPUT_HINT_CAPTION_OR_PROMPT, INPUT_HINT_PROMPT, input_hint_choices + from .formatter_target import target_choices from .krea_formatter import format_krea2_prompt from .sdxl_formatter import ( format_sdxl_prompt, @@ -15,6 +16,7 @@ except ImportError: # Allows local smoke tests from the repository root. from caption_naturalizer import naturalize_caption from caption_policy import caption_profile_choices from formatter_input import INPUT_HINT_CAPTION_OR_PROMPT, INPUT_HINT_PROMPT, input_hint_choices + from formatter_target import target_choices from krea_formatter import format_krea2_prompt from sdxl_formatter import ( format_sdxl_prompt, @@ -36,7 +38,7 @@ class SxCPCaptionNaturalizer: "style_policy": (["drop_style_tail", "keep_style_terms"], {"default": "drop_style_tail"}), "trigger": ("STRING", {"default": "sxcppnl7"}), "include_trigger": ("BOOLEAN", {"default": True}), - "target": (["auto", "single", "softcore", "hardcore"], {"default": "auto"}), + "target": (target_choices(), {"default": "auto"}), }, "optional": { "source_text_input": ("STRING", {"forceInput": True}), @@ -83,7 +85,7 @@ class SxCPKrea2Formatter: "required": { "source_text": ("STRING", {"default": "", "multiline": True}), "input_hint": (input_hint_choices(text_hint=INPUT_HINT_PROMPT), {"default": "auto"}), - "target": (["auto", "single", "softcore", "hardcore"], {"default": "auto"}), + "target": (target_choices(), {"default": "auto"}), "detail_level": (["balanced", "concise", "dense"], {"default": "balanced"}), "style_mode": (["preserve", "photographic", "minimal"], {"default": "preserve"}), "preserve_trigger": ("BOOLEAN", {"default": False}), @@ -155,7 +157,7 @@ class SxCPSDXLFormatter: "required": { "source_text": ("STRING", {"default": "", "multiline": True}), "input_hint": (input_hint_choices(text_hint=INPUT_HINT_PROMPT), {"default": "auto"}), - "target": (["auto", "single", "softcore", "hardcore"], {"default": "auto"}), + "target": (target_choices(), {"default": "auto"}), "formatter_profile": (sdxl_formatter_profile_choices(), {"default": "manual_controls"}), "style_preset": (sdxl_style_preset_choices(), {"default": "flat_vector_pony"}), "quality_preset": (sdxl_quality_preset_choices(), {"default": "pony_high"}), diff --git a/tools/prompt_smoke.py b/tools/prompt_smoke.py index 9d7c8b6..8896e3d 100644 --- a/tools/prompt_smoke.py +++ b/tools/prompt_smoke.py @@ -2814,6 +2814,10 @@ def smoke_formatter_input_policy() -> None: def smoke_formatter_target_policy() -> None: + _expect( + formatter_target.target_choices() == ["auto", "single", "softcore", "hardcore"], + "Formatter target choices changed", + ) _expect(formatter_target.normalize_target("single") == "single", "Formatter target lost single") _expect(formatter_target.normalize_target("Hard-Core") == "hardcore", "Formatter target alias lost hardcore") _expect(formatter_target.normalize_target("soft") == "softcore", "Formatter target alias lost softcore") @@ -6259,7 +6263,9 @@ def smoke_node_formatter_registration() -> None: caption_inputs = sxcp_nodes.NODE_CLASS_MAPPINGS["SxCPCaptionNaturalizer"].INPUT_TYPES().get("required") or {} _expect("caption_profile" in caption_inputs, "Caption Naturalizer lost caption_profile input") _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("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") krea_output = krea_node().build( "sxcppnl7 A woman standing by a window", @@ -6291,6 +6297,7 @@ def smoke_node_formatter_registration() -> None: _expect(sdxl_output[6].startswith("text("), "SDXL Formatter method changed unexpectedly") sdxl_inputs = sxcp_nodes.NODE_CLASS_MAPPINGS["SxCPSDXLFormatter"].INPUT_TYPES().get("required") or {} _expect("formatter_profile" in sdxl_inputs, "SDXL Formatter lost formatter_profile input") + _expect(sdxl_inputs["target"][0] == formatter_target.target_choices(), "SDXL Formatter target choices drifted") _expect("tooltip" in sdxl_inputs["formatter_profile"][1], "SDXL formatter_profile tooltip injection missing") pair = pb.build_insta_of_pair(