fix(baoyu-imagine): tighten Replicate schema validation and fallback handling

This commit is contained in:
justnodejs 2026-04-11 16:15:01 +08:00
parent 7b3214e27a
commit 0ec35bf930
2 changed files with 25 additions and 4 deletions

View File

@ -162,6 +162,7 @@ test("Replicate input builder maps Wan models to their native schema", () => {
size: "2K", size: "2K",
num_outputs: 2, num_outputs: 2,
images: ["data:image/png;base64,AAAA"], images: ["data:image/png;base64,AAAA"],
thinking_mode: false,
}, },
); );
@ -214,6 +215,16 @@ test("Replicate validation catches unsupported Seedream and Wan argument combina
/Seedream on Replicate requires --size to be one of 2K, 3K/, /Seedream on Replicate requires --size to be one of 2K, 3K/,
); );
assert.throws(
() => validateArgs("bytedance/seedream-4.5", makeArgs({ referenceImages: Array.from({ length: 15 }, () => "ref.png") })),
/supports at most 14 reference images/,
);
assert.throws(
() => validateArgs("bytedance/seedream-5-lite", makeArgs({ referenceImages: Array.from({ length: 10 }, () => "ref.png"), n: 10 })),
/allows at most 15 total images per request/,
);
assert.throws( assert.throws(
() => validateArgs("google/nano-banana-2", makeArgs({ n: 2 })), () => validateArgs("google/nano-banana-2", makeArgs({ n: 2 })),
/Nano Banana models on Replicate do not support --n yet/, /Nano Banana models on Replicate do not support --n yet/,

View File

@ -196,10 +196,8 @@ function buildWanInput(prompt: string, model: string, args: CliArgs, referenceIm
} }
// thinking_mode only applies to pure text-to-image. // thinking_mode only applies to pure text-to-image.
// image_set_mode is not exposed by the current CLI, so no extra check is needed here yet. // image_set_mode is not exposed by the current CLI, so switch only on input-image presence for now.
if (referenceImages.length === 0) { input.thinking_mode = referenceImages.length === 0;
input.thinking_mode = true;
}
return input; return input;
} }
@ -216,6 +214,8 @@ export function validateArgs(model: string, args: CliArgs): void {
} }
if (isSeedreamModel(model)) { if (isSeedreamModel(model)) {
const referenceCount = args.referenceImages.length;
if (args.size) { if (args.size) {
const normalizedSize = normalizePresetSize(args.size); const normalizedSize = normalizePresetSize(args.size);
if (!getAllowedSeedreamSizes(model).has(normalizedSize)) { if (!getAllowedSeedreamSizes(model).has(normalizedSize)) {
@ -225,9 +225,19 @@ export function validateArgs(model: string, args: CliArgs): void {
} }
} }
if (referenceCount > 14) {
throw new Error("Seedream on Replicate supports at most 14 reference images per request.");
}
if (args.n < 1 || args.n > 15) { if (args.n < 1 || args.n > 15) {
throw new Error("Seedream on Replicate supports --n values from 1 to 15."); throw new Error("Seedream on Replicate supports --n values from 1 to 15.");
} }
if (referenceCount + args.n > 15) {
throw new Error(
`Seedream on Replicate allows at most 15 total images per request (reference images + generated images). Received ${referenceCount} reference images and --n ${args.n}.`
);
}
} }
if (isWanModel(model)) { if (isWanModel(model)) {