Skip to content

Your lightweight open-source personal agent.

fix openai image reference home paths

sbyinin44f7bbae507a
diff --git a/nanobot/providers/image_generation.py b/nanobot/providers/image_generation.py
index 9f38e7636..5d729e23e 100644
--- a/nanobot/providers/image_generation.py
+++ b/nanobot/providers/image_generation.py
@@ -977,7 +977,7 @@ class OpenAIImageGenerationClient(ImageGenerationProvider):
handles: list[Any] = []
try:
for path in reference_images:
- p = Path(path)
+ p = Path(path).expanduser()
raw = p.read_bytes()
mime = detect_image_mime(raw)
if mime is None:
diff --git a/tests/providers/test_image_generation.py b/tests/providers/test_image_generation.py
index 03dd171ad..fb1109e06 100644
--- a/tests/providers/test_image_generation.py
+++ b/tests/providers/test_image_generation.py
@@ -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
+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
async def test_openai_reference_images_send_multiple_multipart_files(
tmp_path: Path,