Accept OpenAI multipart image edits

This commit is contained in:
Mikei386
2026-09-21 11:35:52 +02:00
parent 9509d8ce29
commit a65affe30a
2 changed files with 94 additions and 10 deletions
+40
View File
@@ -24,6 +24,7 @@ from router_support import ( # noqa: E402
load_profile_registry,
)
from ai_profile_router import ( # noqa: E402
Handler,
STATE,
_cap_chat_generation,
_context_matches,
@@ -141,6 +142,45 @@ class ChatImageInputTests(unittest.TestCase):
self.assertEqual(request, normalized)
class ImageEditMultipartTests(unittest.TestCase):
def test_openai_image_array_upload_keeps_all_references(self) -> None:
boundary = "OpenClawImageBoundary"
parts = [
(
f"--{boundary}\r\n"
'Content-Disposition: form-data; name="model"\r\n\r\n'
"Qwen-Image-2.1-int8\r\n"
).encode(),
(
f"--{boundary}\r\n"
'Content-Disposition: form-data; name="prompt"\r\n\r\n'
"Nur die Farbe ändern\r\n"
).encode(),
(
f"--{boundary}\r\n"
'Content-Disposition: form-data; name="image[]"; filename="a.png"\r\n'
"Content-Type: image/png\r\n\r\n"
).encode() + b"PNG-A\r\n",
(
f"--{boundary}\r\n"
'Content-Disposition: form-data; name="image[]"; filename="b.png"\r\n'
"Content-Type: image/png\r\n\r\n"
).encode() + b"PNG-B\r\n",
f"--{boundary}--\r\n".encode(),
]
handler = object.__new__(Handler)
files, fields = handler._parse_multipart_parts(
b"".join(parts), f"multipart/form-data; boundary={boundary}")
self.assertEqual(fields["model"], "Qwen-Image-2.1-int8")
self.assertEqual(fields["prompt"], "Nur die Farbe ändern")
self.assertEqual(
files,
[("image[]", "a.png", b"PNG-A"),
("image[]", "b.png", b"PNG-B")],
)
class LlamaCppReasoningTests(unittest.TestCase):
def test_disabled_values_really_disable_thinking(self) -> None:
for effort in (None, "none", "off", "disabled", False):