生图自动比例保留清晰度档位

This commit is contained in:
WuYongJie 2026-11-17 10:56:06 +08:00
parent 902ad6fc9c
commit 7094231a55
2 changed files with 27 additions and 1 deletions

View File

@ -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);

View File

@ -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"});