fix openai image reference home paths
This commit is contained in:
@@ -977,7 +977,7 @@ class OpenAIImageGenerationClient(ImageGenerationProvider):
|
|||||||
handles: list[Any] = []
|
handles: list[Any] = []
|
||||||
try:
|
try:
|
||||||
for path in reference_images:
|
for path in reference_images:
|
||||||
p = Path(path)
|
p = Path(path).expanduser()
|
||||||
raw = p.read_bytes()
|
raw = p.read_bytes()
|
||||||
mime = detect_image_mime(raw)
|
mime = detect_image_mime(raw)
|
||||||
if mime is None:
|
if mime is None:
|
||||||
|
|||||||
@@ -822,6 +822,34 @@ async def test_openai_reference_images_use_edits_endpoint(tmp_path: Path) -> Non
|
|||||||
assert call["files"][0][1][1].closed is True
|
assert call["files"][0][1][1].closed is True
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_openai_reference_images_expand_user_paths(
|
||||||
|
tmp_path: Path,
|
||||||
|
monkeypatch: pytest.MonkeyPatch,
|
||||||
|
) -> None:
|
||||||
|
ref = tmp_path / "ref.png"
|
||||||
|
ref.write_bytes(PNG_BYTES)
|
||||||
|
monkeypatch.setenv("HOME", str(tmp_path))
|
||||||
|
fake = FakeClient(FakeResponse({"data": [{"b64_json": RAW_B64}]}))
|
||||||
|
client = OpenAIImageGenerationClient(
|
||||||
|
api_key="sk-openai-test",
|
||||||
|
client=fake, # type: ignore[arg-type]
|
||||||
|
)
|
||||||
|
|
||||||
|
await client.generate(
|
||||||
|
prompt="use a home-relative reference",
|
||||||
|
model="gpt-image-1",
|
||||||
|
reference_images=["~/ref.png"],
|
||||||
|
)
|
||||||
|
|
||||||
|
call = fake.calls[0]
|
||||||
|
assert call["url"] == "https://api.openai.com/v1/images/edits"
|
||||||
|
assert call["files"][0][0] == "image[]"
|
||||||
|
assert call["files"][0][1][0] == "ref.png"
|
||||||
|
assert call["files"][0][1][2] == "image/png"
|
||||||
|
assert call["files"][0][1][1].closed is True
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_openai_reference_images_send_multiple_multipart_files(
|
async def test_openai_reference_images_send_multiple_multipart_files(
|
||||||
tmp_path: Path,
|
tmp_path: Path,
|
||||||
|
|||||||
Reference in New Issue
Block a user