Add caption pair target routing

This commit is contained in:
2026-06-27 13:06:26 +02:00
parent 58f74e44e5
commit 616d1132ff
8 changed files with 121 additions and 25 deletions
+38
View File
@@ -188,6 +188,7 @@ def _expect_formatter_outputs(row: dict[str, Any], name: str, *, target: str = "
caption, method = caption_naturalizer.naturalize_caption(
"",
metadata_json=metadata,
target=target,
trigger=Trigger,
include_trigger=True,
)
@@ -2688,6 +2689,7 @@ def smoke_caption_format_route_policy() -> None:
source_text="",
metadata_json=_json(row),
input_hint="metadata_json",
target="single",
trigger=Trigger,
include_trigger=False,
detail_level="concise",
@@ -2702,6 +2704,7 @@ def smoke_caption_format_route_policy() -> None:
"",
metadata_json=metadata_request.metadata_json,
input_hint=metadata_request.input_hint,
target=metadata_request.target,
trigger=metadata_request.trigger,
include_trigger=metadata_request.include_trigger,
detail_level=metadata_request.detail_level,
@@ -2711,6 +2714,7 @@ def smoke_caption_format_route_policy() -> None:
_expect(typed_metadata.as_tuple() == public_metadata, "Typed caption format route should match public metadata output")
_expect(typed_metadata.branch == "metadata", "Typed caption format route changed metadata branch")
_expect(typed_metadata.input_hint == "metadata_json", "Typed caption route lost input hint")
_expect(typed_metadata.target == "single", "Typed caption route lost target normalization")
_expect(typed_metadata.detail_level == "dense", "Typed caption route lost training_dense detail override")
_expect(typed_metadata.style_policy == "drop_style_tail", "Typed caption route lost training_dense style override")
_expect(typed_metadata.include_trigger is True, "Typed caption route lost training_dense trigger override")
@@ -2719,6 +2723,7 @@ def smoke_caption_format_route_policy() -> None:
fallback_request = caption_format_route.CaptionFormatRequest(
source_text="woman, red dress, studio, coloured pencil comic illustration",
input_hint="bad_hint",
target="weird",
trigger=Trigger,
include_trigger=True,
detail_level="dense",
@@ -2732,6 +2737,7 @@ def smoke_caption_format_route_policy() -> None:
public_fallback = caption_naturalizer.naturalize_caption(
fallback_request.source_text,
input_hint=fallback_request.input_hint,
target=fallback_request.target,
trigger=fallback_request.trigger,
include_trigger=fallback_request.include_trigger,
detail_level=fallback_request.detail_level,
@@ -2741,6 +2747,7 @@ def smoke_caption_format_route_policy() -> None:
_expect(typed_fallback.as_tuple() == public_fallback, "Typed caption format route should match public fallback output")
_expect(typed_fallback.branch == "text", "Typed caption format route changed fallback branch")
_expect(typed_fallback.input_hint == "auto", "Typed caption route should normalize invalid input hint")
_expect(typed_fallback.target == "auto", "Typed caption route should normalize invalid target")
_expect(typed_fallback.include_trigger is False, "Typed caption browsing profile should disable trigger")
_expect(typed_fallback.keep_style is True, "Typed caption browsing profile should keep style terms")
_expect(not typed_fallback.caption.startswith(Trigger), "Typed caption fallback route should not prepend browsing trigger")
@@ -2898,6 +2905,34 @@ def smoke_caption_metadata_routes() -> None:
caption_naturalizer._insta_of_pair_from_row,
"metadata(insta_of_pair)",
)
deps = caption_naturalizer._caption_metadata_route_dependencies()
soft_route = caption_metadata_routes.insta_of_pair_from_row_result(
caption_naturalizer._caption_metadata_route_request(pair, "balanced", False, target="softcore"),
deps,
)
hard_route = caption_metadata_routes.insta_of_pair_from_row_result(
caption_naturalizer._caption_metadata_route_request(pair, "balanced", False, target="hardcore"),
deps,
)
_expect(soft_route is not None, "Caption pair softcore target did not match")
_expect(hard_route is not None, "Caption pair hardcore target did not match")
assert soft_route is not None
assert hard_route is not None
_expect("Softcore version:" not in soft_route.prose, "Caption softcore target should not keep combined pair labels")
_expect("Hardcore version:" not in soft_route.prose, "Caption softcore target should not include hard label")
_expect("Softcore version:" not in hard_route.prose, "Caption hardcore target should not include soft label")
_expect("Hardcore version:" not in hard_route.prose, "Caption hardcore target should not keep combined pair labels")
_expect(soft_route.prose != hard_route.prose, "Caption pair soft/hard targets should produce distinct prose")
public_hard, public_hard_method = caption_naturalizer.naturalize_caption(
"",
metadata_json=_json(pair),
input_hint="metadata_json",
target="hardcore",
trigger=Trigger,
include_trigger=False,
)
_expect(public_hard == hard_route.prose, "Public caption hardcore target drifted from typed route")
_expect("metadata(insta_of_pair)" in public_hard_method, "Public caption hardcore target lost pair method")
def smoke_sdxl_presets_policy() -> None:
@@ -5854,6 +5889,7 @@ def smoke_node_formatter_registration() -> None:
_expect("text(" in caption_method, "Caption Naturalizer method changed unexpectedly")
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("tooltip" in caption_inputs["caption_profile"][1], "Caption profile tooltip injection missing")
krea_output = krea_node().build(
@@ -5987,6 +6023,7 @@ def smoke_node_formatter_registration() -> None:
"",
metadata_json=pair_metadata,
input_hint="metadata_json",
target="hardcore",
trigger=Trigger,
include_trigger=True,
detail_level="balanced",
@@ -6001,6 +6038,7 @@ def smoke_node_formatter_registration() -> None:
"drop_style_tail",
Trigger,
True,
"hardcore",
metadata_json=pair_metadata,
)
_expect(