fix: pass all reference images to OpenAI images.edit endpoint
All checks were successful
Continuous Integration / Build Package (push) Successful in 29s
Continuous Integration / Lint, Check & Test (push) Successful in 46s

This commit is contained in:
Konstantin Fickel 2026-02-15 15:06:58 +01:00
parent 61f30a8bb1
commit 3bfad87dce
Signed by: kfickel
GPG key ID: A793722F9933C1A5
2 changed files with 99 additions and 9 deletions

View file

@ -185,25 +185,25 @@ async def _generate_edit(
project_dir: Path,
size: _SIZE | None,
) -> ImagesResponse:
"""Generate an image using a reference image via the edits endpoint.
"""Generate an image using reference images via the edits endpoint.
gpt-image-* models return b64 by default and reject ``response_format``,
so we only pass it for DALL-E models.
gpt-image-* models accept up to 16 images and return b64 by default
(they reject ``response_format``). DALL-E 2 accepts only one image.
"""
ref_path = project_dir / reference_images[0]
image_bytes = ref_path.read_bytes()
images = [(project_dir / name).read_bytes() for name in reference_images]
image: bytes | list[bytes] = images[0] if len(images) == 1 else images
if model.startswith("gpt-image-"):
if size is not None:
return await client.images.edit(
image=image_bytes,
image=image,
prompt=prompt,
model=model,
n=1,
size=size, # pyright: ignore[reportArgumentType]
)
return await client.images.edit(
image=image_bytes,
image=image,
prompt=prompt,
model=model,
n=1,
@ -211,7 +211,7 @@ async def _generate_edit(
if size is not None:
return await client.images.edit(
image=image_bytes,
image=image,
prompt=prompt,
model=model,
n=1,
@ -219,7 +219,7 @@ async def _generate_edit(
size=size, # pyright: ignore[reportArgumentType]
)
return await client.images.edit(
image=image_bytes,
image=image,
prompt=prompt,
model=model,
n=1,