Extract Krea normal row formatter route

This commit is contained in:
2026-06-27 11:20:50 +02:00
parent 5ec17df1a4
commit 09fc31f078
5 changed files with 259 additions and 77 deletions
+64
View File
@@ -44,6 +44,7 @@ import index_switch_policy # noqa: E402
import krea_cast # noqa: E402
import krea_configured_cast_formatter # noqa: E402
import krea_formatter # noqa: E402
import krea_normal_formatter # noqa: E402
import krea_pair_formatter # noqa: E402
import location_config # noqa: E402
import loop_nodes # noqa: E402
@@ -184,6 +185,20 @@ def _expect_formatter_outputs(row: dict[str, Any], name: str, *, target: str = "
_expect_trigger_once(f"{name}.caption", caption, Trigger)
def _expect_krea_normal_route_parity(row: dict[str, Any], name: str, method: str) -> None:
typed_route = krea_normal_formatter.format_normal_row_result(
krea_formatter._krea_normal_row_request_from_row(row, "balanced", "preserve"),
krea_formatter._krea_normal_row_dependencies(),
)
legacy_route = krea_formatter._normal_row_to_krea(row, "balanced", "preserve")
_expect(
typed_route.as_tuple() == legacy_route,
f"{name} typed Krea normal formatter route should match legacy wrapper output",
)
_expect(typed_route.method == method, f"{name} typed Krea normal formatter method changed")
_expect_text(f"{name}.typed_krea_prompt", typed_route.prompt, 20)
def _character_cast(*, pov_man: bool = False) -> str:
cast = pb.build_character_slot_json(
subject_type="woman",
@@ -583,6 +598,54 @@ def smoke_config_route_location_theme() -> None:
_expect_formatter_outputs(row, "config_route_location_theme", target="single")
def smoke_krea_normal_row_routes() -> None:
single = {
"subject_type": "woman",
"primary_subject": "woman",
"age_band": "25-year-old adult",
"body_phrase": "slim figure",
"skin": "fair skin",
"hair": "long blonde hair",
"eyes": "blue eyes",
"item": "silk dress",
"pose": "standing beside a window",
"scene_text": "quiet studio with warm daylight",
"expression": "soft smile",
"composition": "vertical centered portrait",
"camera_directive": "Camera: eye-level medium shot",
"style": "realistic creator-shot photography",
}
_expect_krea_normal_route_parity(single, "krea_normal_single", "metadata(single)")
couple = {
"subject_type": "couple",
"primary_subject": "a woman and a man",
"subject_phrase": "woman and man",
"age": "25-year-old adult and 40-year-old adult",
"body": "slim and average builds",
"item": "Partner A wears black dress; Partner B wears dark shirt",
"pose": "standing close together",
"scene_text": "private lounge with soft lamps",
"expression": "shared confident gaze",
"composition": "two-person editorial frame",
"camera_directive": "Camera: front view, medium shot",
"style": "realistic social photo",
}
_expect_krea_normal_route_parity(couple, "krea_normal_couple", "metadata(couple)")
generic = {
"subject_type": "location",
"primary_subject": "adult editorial scene",
"item": "polished lounge styling",
"scene_text": "hotel hallway with warm wall sconces",
"expression": "quiet atmosphere",
"composition": "wide establishing frame",
"camera_directive": "Camera: wide shot",
"style": "clean photographic realism",
}
_expect_krea_normal_route_parity(generic, "krea_normal_generic", "metadata(generic)")
def smoke_location_config_policy() -> None:
_expect(pb.LOCATION_POOL_PRESETS is location_config.LOCATION_POOL_PRESETS, "Prompt builder location presets are not delegated")
_expect(pb.COMPOSITION_POOL_PRESETS is location_config.COMPOSITION_POOL_PRESETS, "Prompt builder composition presets are not delegated")
@@ -5004,6 +5067,7 @@ SMOKE_CASES: list[tuple[str, Callable[[], None]]] = [
("camera_scene_single", smoke_camera_scene_single),
("row_camera_policy", smoke_row_camera_policy),
("config_route_location_theme", smoke_config_route_location_theme),
("krea_normal_row_routes", smoke_krea_normal_row_routes),
("location_config_policy", smoke_location_config_policy),
("row_location_policy", smoke_row_location_policy),
("row_expression_policy", smoke_row_expression_policy),