From 7094231a5591bce61f42f37e5f96675c52000745 Mon Sep 17 00:00:00 2001 From: WuYongJie <549727955@qq.com> Date: Tue, 17 Nov 2026 10:56:06 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=9F=E5=9B=BE=E8=87=AA=E5=8A=A8=E6=AF=94?= =?UTF-8?q?=E4=BE=8B=E4=BF=9D=E7=95=99=E6=B8=85=E6=99=B0=E5=BA=A6=E6=A1=A3?= =?UTF-8?q?=E4=BD=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/ai/providers/vip98k.ts | 10 +++++++++- tests/routes/vip98k-model-expansion.test.ts | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/ai/providers/vip98k.ts b/lib/ai/providers/vip98k.ts index cdcc62eaa..bc5b26028 100644 --- a/lib/ai/providers/vip98k.ts +++ b/lib/ai/providers/vip98k.ts @@ -1789,8 +1789,16 @@ export function buildTaskBody(params: Vip98kTaskParams, invocation: Vip98kInvoca const match = String(value).match(/^(\d+)x(\d+)$/); return match ? [{ size: value, width: Number(match[1]), height: Number(match[2]) }] : []; }) : []; + const automaticRatioField = ["aspect_ratio", "aspectRatio", "ratio"].find((key) => { + const schema = toRecord(props[key]); + return (imageParams.aspectRatio === "auto" || body[key] === "auto") && + (schema?.const === "auto" || (Array.isArray(schema?.enum) && schema.enum.includes("auto"))); + }); const selectedRatio = aspectRatio || "1:1"; - if (ratios.includes(selectedRatio)) body.size = selectedRatio; + if (!aspectRatio && automaticRatioField && hasNativeResolution && sizes?.includes(resolution)) { + body[automaticRatioField] = "auto"; + body.size = resolution; + } else if (ratios.includes(selectedRatio)) body.size = selectedRatio; else if (sizes?.includes(resolution) && hasNativeAspectRatio) body.size = resolution; else if (pixels.length && (resolution || aspectRatio)) { const [rw, rh] = selectedRatio.split(":").map(Number); diff --git a/tests/routes/vip98k-model-expansion.test.ts b/tests/routes/vip98k-model-expansion.test.ts index 23f895815..32b700fbd 100644 --- a/tests/routes/vip98k-model-expansion.test.ts +++ b/tests/routes/vip98k-model-expansion.test.ts @@ -60,6 +60,24 @@ test("square image dimensions agree with the requested resolution tier", () => { } }); +test("automatic proportions stay automatic at every published resolution with references", () => { + const contract = invocation({ + size: { enum: ["auto", "1024x1024", "2048x2048", "4096x4096", "1K", "2K", "4K"] }, + resolution: { enum: ["1K", "2K", "4K"] }, + aspect_ratio: { enum: ["auto", "1:1", "3:4", "16:9"] }, + image: { type: "array", items: { type: "string" } }, + }, { size: "1024x1024", aspect_ratio: "auto", response_format: "url" }); + const imageUrls = ["https://example.com/one.png", "https://example.com/two.png"]; + for (const imageSize of ["1K", "2K", "4K"]) { + const { body } = buildTaskBody({ + ...params, modelId: "nano-banana-2", imageUrls, imageParams: { imageSize, aspectRatio: "auto" }, + }, contract); + expect(body).toMatchObject({ + size: imageSize, resolution: imageSize, aspect_ratio: "auto", image: imageUrls, response_format: "url", + }); + } +}); + test("4K uses the largest published square size for area-based image contracts", () => { const result=buildTaskBody({...params,imageParams:{imageSize:"4K",aspectRatio:"1:1"}},invocation({size:{enum:["1024x1024","2048x2048","2880x2880"]},resolution:{enum:["1K","2K","4K"]}})); expect(result.body).toMatchObject({size:"2880x2880",resolution:"4K"});