Принимать входное изображение edits под именем поля image[] (совместимость с LiteLLM)

This commit is contained in:
Shaman
2026-10-06 03:28:11 +00:00
parent 0c5c0b423b
commit 6214cc77a8
+8
View File
@@ -152,6 +152,14 @@ def _parse_json_body(raw: bytes, model_cls):
async def _parse_multipart(request: Request):
form = await request.form()
upload = form.get("image")
if upload is None or not hasattr(upload, "read"):
# Clients following OpenAI's newer image API (e.g. LiteLLM) send the file
# under "image[]"; also accept other common field names.
for _key in ("image[]", "image[0]", "file", "input_file"):
_alt = form.get(_key)
if _alt is not None and hasattr(_alt, "read"):
upload = _alt
break
# duck-typing: FastAPI 0.142+ ships its own UploadFile class, forms yield starlette's
if upload is None or not hasattr(upload, "read"):
raise InvalidRequest("field 'image' (file) is required")