fix: wrap image bytes in BytesIO for gpt-image edit endpoint
The OpenAI SDK's legacy multipart path only accepts dall-e-2 when raw bytes are passed. Wrapping in io.BytesIO with a name attribute routes through the newer path that supports gpt-image-* models. Also removes output_format from the edit call as that endpoint does not support it.
This commit is contained in:
parent
770f408dad
commit
d90db2933e
2 changed files with 31 additions and 14 deletions
|
|
@ -7,6 +7,7 @@ Mock-heavy tests produce many Any-typed expressions from MagicMock.
|
|||
from __future__ import annotations
|
||||
|
||||
import base64
|
||||
import io
|
||||
from pathlib import Path
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
|
|
@ -480,8 +481,10 @@ class TestOpenAIImageProvider:
|
|||
)
|
||||
|
||||
call_args = mock_client.images.edit.call_args
|
||||
# Single reference image should be passed as raw bytes
|
||||
assert call_args.kwargs["image"] == b"reference data"
|
||||
# gpt-image-* models pass a BytesIO with a name attribute
|
||||
img_arg = call_args.kwargs["image"]
|
||||
assert img_arg.read() == b"reference data"
|
||||
assert hasattr(img_arg, "name")
|
||||
|
||||
output = project_dir / "out.png"
|
||||
assert output.exists()
|
||||
|
|
@ -514,9 +517,9 @@ class TestOpenAIImageProvider:
|
|||
)
|
||||
|
||||
call_args = mock_client.images.edit.call_args
|
||||
# Multiple reference images should be passed as a list of bytes
|
||||
image_arg: list[bytes] = call_args.kwargs["image"]
|
||||
# gpt-image-* models pass a list of BytesIO with name attributes
|
||||
image_arg: list[io.BytesIO] = call_args.kwargs["image"]
|
||||
assert isinstance(image_arg, list)
|
||||
assert len(image_arg) == 2
|
||||
assert image_arg[0] == b"ref1 data"
|
||||
assert image_arg[1] == b"ref2 data"
|
||||
assert image_arg[0].read() == b"ref1 data"
|
||||
assert image_arg[1].read() == b"ref2 data"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue