From f980cfb036f5ce310f2719a156ee5e6b47590c7d Mon Sep 17 00:00:00 2001 From: WuYongJie <549727955@qq.com> Date: Mon, 16 Nov 2026 13:29:04 +0800 Subject: [PATCH] fix: keep 4K image dimensions consistent with resolution --- lib/ai/providers/vip98k.ts | 2 +- tests/routes/vip98k-model-expansion.test.ts | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/ai/providers/vip98k.ts b/lib/ai/providers/vip98k.ts index 1f0d7a697..266e8e33c 100644 --- a/lib/ai/providers/vip98k.ts +++ b/lib/ai/providers/vip98k.ts @@ -1763,7 +1763,7 @@ export function buildTaskBody(params: Vip98kTaskParams, invocation: Vip98kInvoca const [rw, rh] = selectedRatio.split(":").map(Number); const matching = pixels.filter(size => Math.abs(size.width / size.height - rw / rh) < 0.025); if (!matching.length) throw Error("当前模型不支持所选图片比例"); - const area = resolution === "4K" ? 2880 ** 2 : resolution === "2K" ? 2048 ** 2 : 1024 ** 2; + const area = resolution === "4K" ? 4096 ** 2 : resolution === "2K" ? 2048 ** 2 : 1024 ** 2; matching.sort((a, b) => Math.abs(a.width * a.height - area) - Math.abs(b.width * b.height - area)); body.size = matching[0].size; } diff --git a/tests/routes/vip98k-model-expansion.test.ts b/tests/routes/vip98k-model-expansion.test.ts index 132748595..18c380b65 100644 --- a/tests/routes/vip98k-model-expansion.test.ts +++ b/tests/routes/vip98k-model-expansion.test.ts @@ -51,6 +51,19 @@ test("pixel-only image contracts use a supported size in the requested tier", () const result = buildTaskBody(params,invocation({size:{enum:["1024x1024","1280x720","2048x1152","3840x2160"]}},{size:"1024x1024"})); expect(result.body.size).toBe("2048x1152"); }); + +test("square image dimensions agree with the requested resolution tier", () => { + const contract=invocation({size:{enum:["auto","1024x1024","2048x2048","4096x4096"]},resolution:{enum:["1K","2K","4K"]},aspect_ratio:{enum:["1:1"]}},{size:"1024x1024",resolution:"1K"}); + for(const [imageSize,size] of [["1K","1024x1024"],["2K","2048x2048"],["4K","4096x4096"]]) { + const result=buildTaskBody({...params,modelId:"nano-banana-2",imageParams:{imageSize,aspectRatio:"1:1"}},contract); + expect(result.body).toMatchObject({size,resolution:imageSize,aspect_ratio:"1:1"}); + } +}); + +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"}); +}); test("OpenAI image size fields receive pixel dimensions instead of a resolution label", () => { const result = buildTaskBody({...params,modelId:"gpt-image-2"},invocation({size:{type:["string","null"]}})); expect(result.body.size).toMatch(/^\d+x\d+$/); -- 2.47.2