feat: support multiple reference images with model-aware API mapping
All checks were successful
Continuous Integration / Build Package (push) Successful in 31s
Continuous Integration / Lint, Check & Test (push) Successful in 49s

Replace singular reference_image field with reference_images list to
support an arbitrary number of reference images. Map them to the correct
BFL API parameter names based on model family:
- flux-2-*: input_image, input_image_2, ..., input_image_8
- flux-kontext-*: input_image, input_image_2, ..., input_image_4
- flux 1.x: image_prompt (single)

BREAKING CHANGE: reference_image config field renamed to reference_images (list).
This commit is contained in:
Konstantin Fickel 2026-02-14 17:19:54 +01:00
parent b69c38ac13
commit d565329e16
Signed by: kfickel
GPG key ID: A793722F9933C1A5
8 changed files with 112 additions and 23 deletions

View file

@ -120,13 +120,13 @@ class TestImageProvider:
assert inputs["width"] == 1920
assert inputs["height"] == 480
async def test_image_with_reference_image(
async def test_image_with_reference_image_flux1(
self, project_dir: Path, image_bytes: bytes
) -> None:
ref_path = project_dir / "ref.png"
_ = ref_path.write_bytes(b"reference image data")
target_config = TargetConfig(prompt="Like this", reference_image="ref.png")
target_config = TargetConfig(prompt="Like this", reference_images=["ref.png"])
bfl_result, mock_http = _make_bfl_mocks(image_bytes)
with (
@ -142,7 +142,7 @@ class TestImageProvider:
target_name="out.png",
target_config=target_config,
resolved_prompt="Like this",
resolved_model="flux-kontext-pro",
resolved_model="flux-pro-1.1",
project_dir=project_dir,
)
@ -151,6 +151,71 @@ class TestImageProvider:
assert "image_prompt" in inputs
assert inputs["image_prompt"] == encode_image_b64(ref_path)
async def test_image_with_reference_images_flux2(
self, project_dir: Path, image_bytes: bytes
) -> None:
ref1 = project_dir / "ref1.png"
ref2 = project_dir / "ref2.png"
_ = ref1.write_bytes(b"ref1 data")
_ = ref2.write_bytes(b"ref2 data")
target_config = TargetConfig(
prompt="Combine", reference_images=["ref1.png", "ref2.png"]
)
bfl_result, mock_http = _make_bfl_mocks(image_bytes)
with (
patch("bulkgen.providers.image.BFLClient") as mock_cls,
patch("bulkgen.providers.image.httpx.AsyncClient") as mock_http_cls,
):
mock_generate = AsyncMock(return_value=bfl_result)
mock_cls.return_value.generate = mock_generate
mock_http_cls.return_value = mock_http
provider = ImageProvider(api_key="test-key")
await provider.generate(
target_name="out.png",
target_config=target_config,
resolved_prompt="Combine",
resolved_model="flux-2-pro",
project_dir=project_dir,
)
call_args = mock_generate.call_args
inputs = call_args[0][1]
assert inputs["input_image"] == encode_image_b64(ref1)
assert inputs["input_image_2"] == encode_image_b64(ref2)
async def test_image_with_reference_image_kontext(
self, project_dir: Path, image_bytes: bytes
) -> None:
ref_path = project_dir / "ref.png"
_ = ref_path.write_bytes(b"reference image data")
target_config = TargetConfig(prompt="Edit", reference_images=["ref.png"])
bfl_result, mock_http = _make_bfl_mocks(image_bytes)
with (
patch("bulkgen.providers.image.BFLClient") as mock_cls,
patch("bulkgen.providers.image.httpx.AsyncClient") as mock_http_cls,
):
mock_generate = AsyncMock(return_value=bfl_result)
mock_cls.return_value.generate = mock_generate
mock_http_cls.return_value = mock_http
provider = ImageProvider(api_key="test-key")
await provider.generate(
target_name="out.png",
target_config=target_config,
resolved_prompt="Edit",
resolved_model="flux-kontext-pro",
project_dir=project_dir,
)
call_args = mock_generate.call_args
inputs = call_args[0][1]
assert inputs["input_image"] == encode_image_b64(ref_path)
async def test_image_no_sample_url_raises(self, project_dir: Path) -> None:
target_config = TargetConfig(prompt="x")