固定一档的生图线路独立传递所选比例

This commit is contained in:
WuYongJie 2026-11-17 13:58:17 +08:00
parent 83091c0457
commit 020637f13d
2 changed files with 20 additions and 10 deletions

View File

@ -1788,19 +1788,27 @@ export function buildTaskBody(params: Vip98kTaskParams, invocation: Vip98kInvoca
(schema?.const === "auto" || (Array.isArray(schema?.enum) && schema.enum.includes("auto"))); (schema?.const === "auto" || (Array.isArray(schema?.enum) && schema.enum.includes("auto")));
}); });
const selectedRatio = aspectRatio || "1:1"; const selectedRatio = aspectRatio || "1:1";
const configuredSizes =
params.modelConfig.imageGenConfig?.supportedImageSizes ??
params.modelConfig.capabilities?.supportedImageSizes;
const fixedOneK =
resolution === "1K" &&
Array.isArray(configuredSizes) &&
configuredSizes.length === 1 &&
configuredSizes[0] === "1K";
if (!aspectRatio && automaticRatioField && hasNativeResolution && sizes?.includes(resolution)) { if (!aspectRatio && automaticRatioField && hasNativeResolution && sizes?.includes(resolution)) {
body[automaticRatioField] = "auto"; body[automaticRatioField] = "auto";
body.size = resolution; body.size = resolution;
} else if (ratios.includes(selectedRatio) && !(hasSeparateAspectRatio && pixels.length)) { } else if (hasSeparateAspectRatio && fixedOneK && sizes?.includes("auto") && ratios.includes(selectedRatio)) {
// Some routes express the ratio through size alone. Routes with a // A fixed-tier route can use its explicit ratio without a second geometry
// separate ratio and pixel presets can require both fields. // constraint. Its published pixel presets may round the nominal ratio.
body.size = "auto";
} else if (ratios.includes(selectedRatio)) {
body.size = selectedRatio; body.size = selectedRatio;
} else if (sizes?.includes(resolution) && hasNativeAspectRatio) body.size = resolution; } else if (sizes?.includes(resolution) && hasNativeAspectRatio) body.size = resolution;
else if (pixels.length && (resolution || aspectRatio)) { else if (pixels.length && (resolution || aspectRatio)) {
const [rw, rh] = selectedRatio.split(":").map(Number); const [rw, rh] = selectedRatio.split(":").map(Number);
const matching = pixels.filter( const matching = pixels.filter(size => Math.abs(size.width / size.height - rw / rh) < 0.025);
({ width, height }) => Math.abs((width * rh) / (height * rw) - 1) < 0.02,
);
if (!matching.length && sizes?.includes("auto") && hasNativeAspectRatio && hasNativeResolution) { if (!matching.length && sizes?.includes("auto") && hasNativeAspectRatio && hasNativeResolution) {
body.size = "auto"; body.size = "auto";
} else { } else {

View File

@ -56,7 +56,7 @@ test("mixed size enums retain ratio aliases when size is the ratio field", () =>
expect(body).toMatchObject({ size: "16:9", resolution: "2K" }); expect(body).toMatchObject({ size: "16:9", resolution: "2K" });
}); });
test("GPT Image 2.6 uses the published pixel preset with the requested ratio", () => { test("GPT Image 2.6 sends the selected ratio without a competing pixel size", () => {
const presets = [ const presets = [
["9:16", "941x1672"], ["9:16", "941x1672"],
["21:9", "1920x832"], ["21:9", "1920x832"],
@ -65,19 +65,21 @@ test("GPT Image 2.6 uses the published pixel preset with the requested ratio", (
]; ];
const ratios = presets.map(([ratio]) => ratio); const ratios = presets.map(([ratio]) => ratio);
const contract = invocation({ const contract = invocation({
size: { enum: [...ratios, ...presets.map(([, size]) => size)] }, size: { enum: ["auto", ...ratios, ...presets.map(([, size]) => size)] },
aspect_ratio: { enum: ratios }, aspect_ratio: { enum: ratios },
image: { type: "array", items: { type: "string" } }, image: { type: "array", items: { type: "string" } },
quality: { enum: ["auto"] }, quality: { enum: ["auto"] },
}, { size: "1024x1024", image: [], quality: "auto" }); }, { size: "1024x1024", image: [], quality: "auto" });
const references = ["https://example.com/one.png"]; const references = ["https://example.com/one.png"];
for (const [aspectRatio, size] of presets) { for (const aspectRatio of ratios) {
const { body } = buildTaskBody({ const { body } = buildTaskBody({
...params, modelId: "gpt-image-2.6", imageUrls: references, ...params, modelId: "gpt-image-2.6", imageUrls: references,
modelConfig: { imageGenConfig: { supportedImageSizes: ["1K"] } },
imageParams: { aspectRatio, imageSize: "1K" }, imageParams: { aspectRatio, imageSize: "1K" },
}, contract); }, contract);
expect(body).toMatchObject({ size, aspect_ratio: aspectRatio, image: references, quality: "auto" }); expect(body).toMatchObject({ size: "auto", aspect_ratio: aspectRatio, image: references, quality: "auto" });
expect(body).not.toHaveProperty("resolution");
} }
}); });