增加2.5模型调用

This commit is contained in:
andy committed 2026-09-23 15:10:13 +08:00
1 parent 3f29ba716a
commit be655b6569
32 files changed
+1075 -56

No files matched your search

+68 -3
View File
@@ -1,5 +1,6 @@
import type { EnabledImageCapability, GenerationStatus } from "@/lib/types";
import { imageDimensionsForEngine } from "@/lib/image-size-presets";
import { isImageModel } from "@/lib/image-models";
export type ImageCreationEngine = "jimeng" | "evolink" | "bailian";
@@ -79,17 +80,36 @@ export function buildEvolinkImagePayload(
): Record<string, unknown> {
const prompt = String(input.prompt || "").trim();
const imageUrls = asStringArray(input.imageUrls);
const nested = asRecord(input.settings) || {};
const requestedModel = input.model;
if (requestedModel !== undefined && !isImageModel(requestedModel) && requestedModel !== settings.model) {
throw new Error("Unsupported EvoLink image model.");
}
const model = requestedModel || settings.model;
const image25 = model === "gpt-image-2.5-flare" || model === "gpt-image-2.5-sunburst";
if (image25) validateImage25Input(input, nested, imageUrls);
const payload: Record<string, unknown> = {
model: settings.model,
model,
prompt,
n: 1
};
if (!payload.prompt) throw new Error("Prompt is required for image generation.");
const quality = cleanOptional(typeof input.quality === "string" ? input.quality : undefined) || settings.quality;
const rawQuality = input.quality ?? nested.quality;
const requestedQuality = cleanOptional(typeof rawQuality === "string" ? rawQuality : undefined)?.toLowerCase();
if (image25 && rawQuality !== undefined && (!requestedQuality || !validQuality(requestedQuality))) {
throw new Error("Unsupported EvoLink image quality.");
}
const quality = requestedQuality || cleanOptional(settings.quality)?.toLowerCase() || (image25 ? "medium" : undefined);
if (image25 && !validQuality(quality)) throw new Error("Unsupported EvoLink image quality.");
if (quality) payload.quality = quality;
payload.resolution = EVOLINK_PLATFORM_RESOLUTION;
assignSize(payload, input);
assignSize(payload, {
size: input.size ?? nested.size,
width: input.width ?? nested.width,
height: input.height ?? nested.height
});
if (image25 && payload.size === undefined) payload.size = "1:1";
if (imageUrls.length) payload.image_urls = imageUrls;
return payload;
@@ -152,6 +172,49 @@ function cleanOptional(value: string | undefined): string | undefined {
return normalized || undefined;
}
function validQuality(value: unknown): value is "low" | "medium" | "high" {
return value === "low" || value === "medium" || value === "high";
}
function validateImage25Input(input: Record<string, unknown>, nested: Record<string, unknown>, imageUrls: string[]) {
if (imageUrls.length > 16) throw new Error("EvoLink Image 2.5 supports at most 16 reference images.");
for (const resolution of [input.resolution, nested.resolution]) {
if (resolution !== undefined && (typeof resolution !== "string" || resolution.trim().toUpperCase() !== "1K")) {
throw new Error("EvoLink Image 2.5 resolution must be 1K.");
}
}
for (const key of ["n", "imageCount"]) {
for (const value of [input[key], nested[key]]) {
if (value !== undefined && !isOne(value)) throw new Error(`EvoLink Image 2.5 ${key} must be 1.`);
}
}
if (input.force_single === false || nested.force_single === false) throw new Error("EvoLink Image 2.5 requires force_single.");
for (const size of [input.size, nested.size]) {
if (size !== undefined && (typeof size !== "string" || !supportedImage25Sizes.has(size.trim()))) {
throw new Error("EvoLink Image 2.5 size must be a supported 1K aspect ratio or A4 size.");
}
}
const width = input.width ?? nested.width;
const height = input.height ?? nested.height;
if ((width === undefined) !== (height === undefined)) throw new Error("EvoLink Image 2.5 requires both width and height.");
if (width !== undefined) {
const w = asPositiveInteger(width);
const h = asPositiveInteger(height);
if (!w || !h || w > 8192 || h > 8192) throw new Error("Invalid EvoLink Image 2.5 dimensions.");
const mapped = imageDimensionsForEngine({ width: w, height: h }, "evolink");
const ratio = ratioFromDimensions(mapped.width, mapped.height);
const a4 = (mapped.width === 848 && mapped.height === 1200) || (mapped.width === 1200 && mapped.height === 848);
const pixels = w * h;
const custom = w % 16 === 0 && h % 16 === 0 && pixels >= 655360 && pixels <= 1048576 && Math.max(w, h) / Math.min(w, h) <= 3;
if (!ratio && !a4 && !custom) throw new Error("EvoLink Image 2.5 custom dimensions exceed the supported 1K size.");
}
}
function isOne(value: unknown): boolean {
return (typeof value === "number" && Number.isFinite(value) || typeof value === "string" && value.trim() !== "")
&& Number(value) === 1;
}
function assignSize(payload: Record<string, unknown>, input: Record<string, unknown>) {
if (typeof input.size === "string" && input.size.trim()) {
payload.size = input.size.trim();
@@ -170,6 +233,7 @@ function asStringArray(value: unknown): string[] {
}
function asPositiveInteger(value: unknown): number | undefined {
if (typeof value !== "number" && (typeof value !== "string" || value.trim() === "")) return undefined;
const parsed = Number(value);
if (!Number.isInteger(parsed) || parsed <= 0) return undefined;
return parsed;
@@ -209,6 +273,7 @@ const supportedRatios = new Set([
"9:21",
"21:9"
]);
const supportedImage25Sizes = new Set([...supportedRatios, "848x1200", "1200x848"]);
function asRecord(value: unknown): Record<string, unknown> | undefined {
return typeof value === "object" && value !== null && !Array.isArray(value)