Merge branch 'fork/hzexe/local/images-edits-json-compat'
Browse files- api/ai.py +48 -12
- test/test_v1_images_edits_json.py +130 -0
- utils/helper.py +75 -0
api/ai.py
CHANGED
|
@@ -5,6 +5,7 @@ from fastapi.concurrency import run_in_threadpool
|
|
| 5 |
from pydantic import BaseModel, ConfigDict, Field
|
| 6 |
|
| 7 |
from api.support import require_identity, resolve_image_base_url
|
|
|
|
| 8 |
from services.content_filter import check_request, request_text
|
| 9 |
from services.log_service import LoggedCall
|
| 10 |
from services.protocol import (
|
|
@@ -27,6 +28,36 @@ class ImageGenerationRequest(BaseModel):
|
|
| 27 |
stream: bool | None = None
|
| 28 |
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
class ChatCompletionRequest(BaseModel):
|
| 31 |
model_config = ConfigDict(extra="allow")
|
| 32 |
model: str | None = None
|
|
@@ -92,7 +123,7 @@ def create_router() -> APIRouter:
|
|
| 92 |
authorization: str | None = Header(default=None),
|
| 93 |
image: list[UploadFile] | None = File(default=None),
|
| 94 |
image_list: list[UploadFile] | None = File(default=None, alias="image[]"),
|
| 95 |
-
prompt: str = Form(
|
| 96 |
model: str = Form(default="gpt-image-2"),
|
| 97 |
n: int = Form(default=1),
|
| 98 |
size: str | None = Form(default=None),
|
|
@@ -100,19 +131,24 @@ def create_router() -> APIRouter:
|
|
| 100 |
stream: bool | None = Form(default=None),
|
| 101 |
):
|
| 102 |
identity = require_identity(authorization)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
call = LoggedCall(identity, "/v1/images/edits", model, "图生图", request_text=prompt)
|
| 104 |
-
if n < 1 or n > 4:
|
| 105 |
-
raise HTTPException(status_code=400, detail={"error": "n must be between 1 and 4"})
|
| 106 |
await filter_or_log(call, prompt)
|
| 107 |
-
uploads = [*(image or []), *(image_list or [])]
|
| 108 |
-
if not uploads:
|
| 109 |
-
raise HTTPException(status_code=400, detail={"error": "image file is required"})
|
| 110 |
-
images: list[tuple[bytes, str, str]] = []
|
| 111 |
-
for upload in uploads:
|
| 112 |
-
image_data = await upload.read()
|
| 113 |
-
if not image_data:
|
| 114 |
-
raise HTTPException(status_code=400, detail={"error": "image file is empty"})
|
| 115 |
-
images.append((image_data, upload.filename or "image.png", upload.content_type or "image/png"))
|
| 116 |
payload = {
|
| 117 |
"prompt": prompt,
|
| 118 |
"images": images,
|
|
|
|
| 5 |
from pydantic import BaseModel, ConfigDict, Field
|
| 6 |
|
| 7 |
from api.support import require_identity, resolve_image_base_url
|
| 8 |
+
from utils.helper import normalize_json_edit_images, parse_image_count
|
| 9 |
from services.content_filter import check_request, request_text
|
| 10 |
from services.log_service import LoggedCall
|
| 11 |
from services.protocol import (
|
|
|
|
| 28 |
stream: bool | None = None
|
| 29 |
|
| 30 |
|
| 31 |
+
class ImageEditJsonRequest(BaseModel):
|
| 32 |
+
model_config = ConfigDict(extra="allow")
|
| 33 |
+
prompt: str = Field(..., min_length=1)
|
| 34 |
+
model: str | None = None
|
| 35 |
+
n: object = 1
|
| 36 |
+
size: str | None = None
|
| 37 |
+
response_format: str | None = None
|
| 38 |
+
stream: bool | None = None
|
| 39 |
+
image: object | None = None
|
| 40 |
+
images: object | None = None
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def _is_json_request(request: Request) -> bool:
|
| 44 |
+
return "application/json" in request.headers.get("content-type", "").lower()
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
async def _collect_json_edit_payload(
|
| 48 |
+
request: Request,
|
| 49 |
+
) -> tuple[str, str, object, str | None, str, bool | None, list[tuple[bytes, str, str]]]:
|
| 50 |
+
try:
|
| 51 |
+
body = ImageEditJsonRequest.model_validate(await request.json())
|
| 52 |
+
except Exception as exc:
|
| 53 |
+
raise HTTPException(status_code=400, detail={"error": "invalid image edit JSON request"}) from exc
|
| 54 |
+
prompt = body.prompt
|
| 55 |
+
model = body.model or "gpt-image-2"
|
| 56 |
+
response_format = body.response_format or "b64_json"
|
| 57 |
+
images = normalize_json_edit_images(image=body.image, images=body.images)
|
| 58 |
+
return prompt, model, body.n, body.size, response_format, body.stream, images
|
| 59 |
+
|
| 60 |
+
|
| 61 |
class ChatCompletionRequest(BaseModel):
|
| 62 |
model_config = ConfigDict(extra="allow")
|
| 63 |
model: str | None = None
|
|
|
|
| 123 |
authorization: str | None = Header(default=None),
|
| 124 |
image: list[UploadFile] | None = File(default=None),
|
| 125 |
image_list: list[UploadFile] | None = File(default=None, alias="image[]"),
|
| 126 |
+
prompt: str | None = Form(default=None),
|
| 127 |
model: str = Form(default="gpt-image-2"),
|
| 128 |
n: int = Form(default=1),
|
| 129 |
size: str | None = Form(default=None),
|
|
|
|
| 131 |
stream: bool | None = Form(default=None),
|
| 132 |
):
|
| 133 |
identity = require_identity(authorization)
|
| 134 |
+
if _is_json_request(request):
|
| 135 |
+
prompt, model, n, size, response_format, stream, images = await _collect_json_edit_payload(request)
|
| 136 |
+
else:
|
| 137 |
+
if not prompt:
|
| 138 |
+
raise HTTPException(status_code=422, detail={"error": "prompt is required"})
|
| 139 |
+
uploads = [*(image or []), *(image_list or [])]
|
| 140 |
+
if not uploads:
|
| 141 |
+
raise HTTPException(status_code=400, detail={"error": "image file is required"})
|
| 142 |
+
images: list[tuple[bytes, str, str]] = []
|
| 143 |
+
for upload in uploads:
|
| 144 |
+
image_data = await upload.read()
|
| 145 |
+
if not image_data:
|
| 146 |
+
raise HTTPException(status_code=400, detail={"error": "image file is empty"})
|
| 147 |
+
images.append((image_data, upload.filename or "image.png", upload.content_type or "image/png"))
|
| 148 |
+
|
| 149 |
+
n = parse_image_count(n)
|
| 150 |
call = LoggedCall(identity, "/v1/images/edits", model, "图生图", request_text=prompt)
|
|
|
|
|
|
|
| 151 |
await filter_or_log(call, prompt)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
payload = {
|
| 153 |
"prompt": prompt,
|
| 154 |
"images": images,
|
test/test_v1_images_edits_json.py
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import base64
|
| 4 |
+
import os
|
| 5 |
+
import unittest
|
| 6 |
+
from unittest import mock
|
| 7 |
+
|
| 8 |
+
os.environ.setdefault("CHATGPT2API_AUTH_KEY", "chatgpt2api")
|
| 9 |
+
|
| 10 |
+
from fastapi import FastAPI
|
| 11 |
+
from fastapi.testclient import TestClient
|
| 12 |
+
|
| 13 |
+
import api.ai as ai_module
|
| 14 |
+
|
| 15 |
+
AUTH_HEADERS = {"Authorization": "Bearer chatgpt2api"}
|
| 16 |
+
PNG_DATA_URL = "data:image/png;base64," + base64.b64encode(b"fake-png").decode("ascii")
|
| 17 |
+
JPEG_DATA_URL = "data:image/jpeg;base64," + base64.b64encode(b"fake-jpeg").decode("ascii")
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
class ImageEditsJsonApiTests(unittest.TestCase):
|
| 21 |
+
def setUp(self):
|
| 22 |
+
self.calls = []
|
| 23 |
+
|
| 24 |
+
def fake_handle(payload):
|
| 25 |
+
self.calls.append(payload)
|
| 26 |
+
return {"created": 1, "data": [{"b64_json": "ZmFrZQ=="}]}
|
| 27 |
+
|
| 28 |
+
self.handle_patcher = mock.patch.object(ai_module.openai_v1_image_edit, "handle", fake_handle)
|
| 29 |
+
self.filter_patcher = mock.patch.object(ai_module, "filter_or_log", mock.AsyncMock())
|
| 30 |
+
self.handle_patcher.start()
|
| 31 |
+
self.filter_patcher.start()
|
| 32 |
+
self.addCleanup(self.handle_patcher.stop)
|
| 33 |
+
self.addCleanup(self.filter_patcher.stop)
|
| 34 |
+
|
| 35 |
+
app = FastAPI()
|
| 36 |
+
app.include_router(ai_module.create_router())
|
| 37 |
+
self.client = TestClient(app)
|
| 38 |
+
|
| 39 |
+
def test_json_model_omitted_uses_existing_default_logic(self):
|
| 40 |
+
response = self.client.post("/v1/images/edits", headers=AUTH_HEADERS, json={"prompt": "未传 model", "image": PNG_DATA_URL})
|
| 41 |
+
self.assertEqual(response.status_code, 200, response.text)
|
| 42 |
+
self.assertEqual(self.calls[0]["model"], "gpt-image-2")
|
| 43 |
+
|
| 44 |
+
def test_json_model_is_not_overwritten_when_provided(self):
|
| 45 |
+
response = self.client.post(
|
| 46 |
+
"/v1/images/edits",
|
| 47 |
+
headers=AUTH_HEADERS,
|
| 48 |
+
json={"model": "codex-gpt-image-2", "prompt": "保留 model", "image": PNG_DATA_URL},
|
| 49 |
+
)
|
| 50 |
+
self.assertEqual(response.status_code, 200, response.text)
|
| 51 |
+
self.assertEqual(self.calls[0]["model"], "codex-gpt-image-2")
|
| 52 |
+
|
| 53 |
+
def test_image_edit_accepts_json_image_url(self):
|
| 54 |
+
response = self.client.post(
|
| 55 |
+
"/v1/images/edits",
|
| 56 |
+
headers=AUTH_HEADERS,
|
| 57 |
+
json={
|
| 58 |
+
"model": "gpt-image-2",
|
| 59 |
+
"prompt": "把图片改成夜景风格",
|
| 60 |
+
"n": 1,
|
| 61 |
+
"size": "1024x1536",
|
| 62 |
+
"response_format": "b64_json",
|
| 63 |
+
"images": [{"image_url": PNG_DATA_URL}],
|
| 64 |
+
},
|
| 65 |
+
)
|
| 66 |
+
self.assertEqual(response.status_code, 200, response.text)
|
| 67 |
+
payload = self.calls[0]
|
| 68 |
+
self.assertEqual(payload["images"], [(b"fake-png", "image_1.png", "image/png")])
|
| 69 |
+
self.assertEqual(payload["size"], "1024x1536")
|
| 70 |
+
|
| 71 |
+
def test_image_edit_accepts_json_multiple_images_and_b64_json(self):
|
| 72 |
+
response = self.client.post(
|
| 73 |
+
"/v1/images/edits",
|
| 74 |
+
headers=AUTH_HEADERS,
|
| 75 |
+
json={
|
| 76 |
+
"prompt": "把两张图合成海报",
|
| 77 |
+
"images": [
|
| 78 |
+
PNG_DATA_URL,
|
| 79 |
+
{"b64_json": base64.b64encode(b"raw-jpeg").decode("ascii"), "mime_type": "image/jpeg", "filename": "two.jpg"},
|
| 80 |
+
{"image_url": {"url": JPEG_DATA_URL}},
|
| 81 |
+
],
|
| 82 |
+
},
|
| 83 |
+
)
|
| 84 |
+
self.assertEqual(response.status_code, 200, response.text)
|
| 85 |
+
self.assertEqual(self.calls[0]["images"], [
|
| 86 |
+
(b"fake-png", "image_1.png", "image/png"),
|
| 87 |
+
(b"raw-jpeg", "two.jpg", "image/jpeg"),
|
| 88 |
+
(b"fake-jpeg", "image_3.jpg", "image/jpeg"),
|
| 89 |
+
])
|
| 90 |
+
|
| 91 |
+
def test_image_edit_keeps_original_multipart_multiple_image_logic(self):
|
| 92 |
+
response = self.client.post(
|
| 93 |
+
"/v1/images/edits",
|
| 94 |
+
headers=AUTH_HEADERS,
|
| 95 |
+
data={"prompt": "multipart 多图仍然可用", "model": "gpt-image-2", "n": "1"},
|
| 96 |
+
files=[
|
| 97 |
+
("image", ("one.png", b"one", "image/png")),
|
| 98 |
+
("image", ("two.jpg", b"two", "image/jpeg")),
|
| 99 |
+
("image[]", ("three.webp", b"three", "image/webp")),
|
| 100 |
+
],
|
| 101 |
+
)
|
| 102 |
+
self.assertEqual(response.status_code, 200, response.text)
|
| 103 |
+
self.assertEqual(self.calls[0]["images"], [
|
| 104 |
+
(b"one", "one.png", "image/png"),
|
| 105 |
+
(b"two", "two.jpg", "image/jpeg"),
|
| 106 |
+
(b"three", "three.webp", "image/webp"),
|
| 107 |
+
])
|
| 108 |
+
|
| 109 |
+
def test_image_edit_rejects_json_without_image(self):
|
| 110 |
+
response = self.client.post("/v1/images/edits", headers=AUTH_HEADERS, json={"prompt": "缺少图片"})
|
| 111 |
+
self.assertEqual(response.status_code, 400, response.text)
|
| 112 |
+
self.assertIn("image file is required", response.text)
|
| 113 |
+
|
| 114 |
+
def test_image_edit_rejects_remote_json_url(self):
|
| 115 |
+
response = self.client.post(
|
| 116 |
+
"/v1/images/edits",
|
| 117 |
+
headers=AUTH_HEADERS,
|
| 118 |
+
json={"prompt": "不允许远程拉图", "images": [{"image_url": "https://example.com/a.png"}]},
|
| 119 |
+
)
|
| 120 |
+
self.assertEqual(response.status_code, 400, response.text)
|
| 121 |
+
self.assertIn("remote image URLs are not supported", response.text)
|
| 122 |
+
|
| 123 |
+
def test_image_edit_rejects_json_n_out_of_range(self):
|
| 124 |
+
response = self.client.post("/v1/images/edits", headers=AUTH_HEADERS, json={"prompt": "n 越界", "n": 5, "image": PNG_DATA_URL})
|
| 125 |
+
self.assertEqual(response.status_code, 400, response.text)
|
| 126 |
+
self.assertFalse(self.calls)
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
if __name__ == "__main__":
|
| 130 |
+
unittest.main()
|
utils/helper.py
CHANGED
|
@@ -14,6 +14,81 @@ from utils.log import logger
|
|
| 14 |
IMAGE_MODELS = {"gpt-image-2", "codex-gpt-image-2"}
|
| 15 |
OUTPUT_DIR = Path(__file__).resolve().parent / "output"
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
def new_uuid() -> str:
|
| 19 |
return str(uuid.uuid4())
|
|
|
|
| 14 |
IMAGE_MODELS = {"gpt-image-2", "codex-gpt-image-2"}
|
| 15 |
OUTPUT_DIR = Path(__file__).resolve().parent / "output"
|
| 16 |
|
| 17 |
+
SUPPORTED_JSON_IMAGE_MIME_TYPES = {"image/png", "image/jpeg", "image/jpg", "image/webp", "image/gif"}
|
| 18 |
+
MAX_JSON_IMAGE_BYTES = 10 * 1024 * 1024
|
| 19 |
+
MAX_JSON_EDIT_IMAGES = 10
|
| 20 |
+
DATA_URL_IMAGE_RE = re.compile(r"^data:(?P<mime>[-+./\w]+);base64,(?P<data>.*)$", re.DOTALL)
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def _image_extension(mime_type: str) -> str:
|
| 24 |
+
image_type = mime_type.split("/", 1)[1].split(";", 1)[0].lower() if "/" in mime_type else "png"
|
| 25 |
+
return "jpg" if image_type == "jpeg" else image_type or "png"
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def _decode_json_image_string(value: str, index: int, filename: str | None = None, mime_type: str | None = None) -> tuple[bytes, str, str]:
|
| 29 |
+
text = value.strip()
|
| 30 |
+
if not text:
|
| 31 |
+
raise HTTPException(status_code=400, detail={"error": "image file is empty"})
|
| 32 |
+
match = DATA_URL_IMAGE_RE.match(text)
|
| 33 |
+
if match:
|
| 34 |
+
resolved_mime = (match.group("mime") or "image/png").lower()
|
| 35 |
+
encoded = match.group("data")
|
| 36 |
+
else:
|
| 37 |
+
if text.startswith(("http://", "https://")):
|
| 38 |
+
raise HTTPException(status_code=400, detail={"error": "remote image URLs are not supported"})
|
| 39 |
+
resolved_mime = (mime_type or "image/png").lower()
|
| 40 |
+
encoded = text
|
| 41 |
+
if resolved_mime == "image/jpg":
|
| 42 |
+
resolved_mime = "image/jpeg"
|
| 43 |
+
if resolved_mime not in SUPPORTED_JSON_IMAGE_MIME_TYPES:
|
| 44 |
+
raise HTTPException(status_code=400, detail={"error": "unsupported image mime type"})
|
| 45 |
+
try:
|
| 46 |
+
image_data = base64.b64decode(encoded, validate=True)
|
| 47 |
+
except Exception as exc:
|
| 48 |
+
raise HTTPException(status_code=400, detail={"error": "invalid base64 image data"}) from exc
|
| 49 |
+
if not image_data:
|
| 50 |
+
raise HTTPException(status_code=400, detail={"error": "image file is empty"})
|
| 51 |
+
if len(image_data) > MAX_JSON_IMAGE_BYTES:
|
| 52 |
+
raise HTTPException(status_code=400, detail={"error": "image file is too large"})
|
| 53 |
+
return image_data, filename or f"image_{index}.{_image_extension(resolved_mime)}", resolved_mime
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def _extract_json_image_value(item: object) -> tuple[str, str | None, str | None]:
|
| 57 |
+
if isinstance(item, str):
|
| 58 |
+
return item, None, None
|
| 59 |
+
if not isinstance(item, dict):
|
| 60 |
+
raise HTTPException(status_code=400, detail={"error": "image entry must be a base64 string or object"})
|
| 61 |
+
filename = str(item.get("filename") or item.get("file_name") or "").strip() or None
|
| 62 |
+
mime_type = str(item.get("mime_type") or item.get("mimeType") or "").strip() or None
|
| 63 |
+
value = item.get("b64_json") or item.get("base64")
|
| 64 |
+
if not value:
|
| 65 |
+
image_url = item.get("image_url") or item.get("url")
|
| 66 |
+
if isinstance(image_url, dict):
|
| 67 |
+
filename = filename or str(image_url.get("filename") or image_url.get("file_name") or "").strip() or None
|
| 68 |
+
mime_type = mime_type or str(image_url.get("mime_type") or image_url.get("mimeType") or "").strip() or None
|
| 69 |
+
value = image_url.get("url") or image_url.get("image_url")
|
| 70 |
+
else:
|
| 71 |
+
value = image_url
|
| 72 |
+
if not isinstance(value, str) or not value.strip():
|
| 73 |
+
raise HTTPException(status_code=400, detail={"error": "image entry must include image data"})
|
| 74 |
+
return value, filename, mime_type
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
def normalize_json_edit_images(image: object = None, images: object = None) -> list[tuple[bytes, str, str]]:
|
| 78 |
+
raw_images = images if images is not None else image
|
| 79 |
+
if raw_images is None:
|
| 80 |
+
raise HTTPException(status_code=400, detail={"error": "image file is required"})
|
| 81 |
+
entries = raw_images if isinstance(raw_images, list) else [raw_images]
|
| 82 |
+
if not entries:
|
| 83 |
+
raise HTTPException(status_code=400, detail={"error": "image file is required"})
|
| 84 |
+
if len(entries) > MAX_JSON_EDIT_IMAGES:
|
| 85 |
+
raise HTTPException(status_code=400, detail={"error": f"images supports up to {MAX_JSON_EDIT_IMAGES} items"})
|
| 86 |
+
normalized = []
|
| 87 |
+
for index, item in enumerate(entries, start=1):
|
| 88 |
+
value, filename, mime_type = _extract_json_image_value(item)
|
| 89 |
+
normalized.append(_decode_json_image_string(value, index, filename, mime_type))
|
| 90 |
+
return normalized
|
| 91 |
+
|
| 92 |
|
| 93 |
def new_uuid() -> str:
|
| 94 |
return str(uuid.uuid4())
|