fix: don't pass response_format to gpt-image-* models
gpt-image-* models return b64_json by default and reject the response_format parameter with a 400 error. Only pass it for DALL-E models which default to url.
This commit is contained in:
parent
d1bbd95c1c
commit
61f30a8bb1
1 changed files with 37 additions and 2 deletions
|
|
@ -145,7 +145,22 @@ async def _generate_new(
|
|||
model: str,
|
||||
size: _SIZE | None,
|
||||
) -> ImagesResponse:
|
||||
"""Generate a new image from a text prompt."""
|
||||
"""Generate a new image from a text prompt.
|
||||
|
||||
gpt-image-* models return b64 by default and reject ``response_format``,
|
||||
so we only pass it for DALL-E models.
|
||||
"""
|
||||
# gpt-image-* returns b64 by default; DALL-E defaults to url.
|
||||
if model.startswith("gpt-image-"):
|
||||
if size is not None:
|
||||
return await client.images.generate(
|
||||
prompt=prompt,
|
||||
model=model,
|
||||
n=1,
|
||||
size=size,
|
||||
)
|
||||
return await client.images.generate(prompt=prompt, model=model, n=1)
|
||||
|
||||
if size is not None:
|
||||
return await client.images.generate(
|
||||
prompt=prompt,
|
||||
|
|
@ -170,10 +185,30 @@ 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 a reference image via the edits endpoint.
|
||||
|
||||
gpt-image-* models return b64 by default and reject ``response_format``,
|
||||
so we only pass it for DALL-E models.
|
||||
"""
|
||||
ref_path = project_dir / reference_images[0]
|
||||
image_bytes = ref_path.read_bytes()
|
||||
|
||||
if model.startswith("gpt-image-"):
|
||||
if size is not None:
|
||||
return await client.images.edit(
|
||||
image=image_bytes,
|
||||
prompt=prompt,
|
||||
model=model,
|
||||
n=1,
|
||||
size=size, # pyright: ignore[reportArgumentType]
|
||||
)
|
||||
return await client.images.edit(
|
||||
image=image_bytes,
|
||||
prompt=prompt,
|
||||
model=model,
|
||||
n=1,
|
||||
)
|
||||
|
||||
if size is not None:
|
||||
return await client.images.edit(
|
||||
image=image_bytes,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue