fix(ai): route VIP98K reference edits through task API
This commit is contained in:
parent
82088274be
commit
a326cf6935
@ -108,6 +108,25 @@ function inferKind(modelId: string, config: Vip98kModelRuntimeConfig) {
|
|||||||
return "chat";
|
return "chat";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const VIP98K_OPENAI_IMAGE_ALIASES = new Set([
|
||||||
|
"nano-banana-2",
|
||||||
|
"nano-banana-pro",
|
||||||
|
"gpt-image-2-vip",
|
||||||
|
]);
|
||||||
|
|
||||||
|
function resolveVip98kReferenceModelId(modelId: string) {
|
||||||
|
switch (modelId.trim().toLowerCase()) {
|
||||||
|
case "nano-banana-2":
|
||||||
|
return "google/nano-banana-2/reference-to-image";
|
||||||
|
case "nano-banana-pro":
|
||||||
|
return "google/nano-banana-pro/edit";
|
||||||
|
case "gpt-image-2-vip":
|
||||||
|
return "openai/gpt-image-2/edit";
|
||||||
|
default:
|
||||||
|
return modelId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function delay(ms: number) {
|
function delay(ms: number) {
|
||||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||||
}
|
}
|
||||||
@ -746,10 +765,6 @@ export function createVip98k({ apiKey, baseURL }: Vip98kConfig) {
|
|||||||
const modelConfig = parseRuntimeConfig(defaultModelConfig);
|
const modelConfig = parseRuntimeConfig(defaultModelConfig);
|
||||||
const kind = inferKind(modelId, modelConfig);
|
const kind = inferKind(modelId, modelConfig);
|
||||||
|
|
||||||
if (kind === "image") {
|
|
||||||
return openAIImageProvider.chat(modelId) as any;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (kind === "chat") {
|
if (kind === "chat") {
|
||||||
return openAITextProvider.chat(modelId) as any;
|
return openAITextProvider.chat(modelId) as any;
|
||||||
}
|
}
|
||||||
@ -774,14 +789,25 @@ export function createVip98k({ apiKey, baseURL }: Vip98kConfig) {
|
|||||||
if (!activeModelId) throw new Error("VIP98K model ID is not configured");
|
if (!activeModelId) throw new Error("VIP98K model ID is not configured");
|
||||||
const activeKind = inferKind(activeModelId, runtimeConfig);
|
const activeKind = inferKind(activeModelId, runtimeConfig);
|
||||||
const { prompt, imageUrls, videoUrls } = extractPromptAndMedia(options.messages);
|
const { prompt, imageUrls, videoUrls } = extractPromptAndMedia(options.messages);
|
||||||
|
if (
|
||||||
|
activeKind === "image" &&
|
||||||
|
imageUrls.length === 0 &&
|
||||||
|
VIP98K_OPENAI_IMAGE_ALIASES.has(activeModelId.toLowerCase())
|
||||||
|
) {
|
||||||
|
return openAIImageProvider.chat(activeModelId).doGenerate(options as any);
|
||||||
|
}
|
||||||
const [publicImageUrls, publicVideoUrls] = await Promise.all([
|
const [publicImageUrls, publicVideoUrls] = await Promise.all([
|
||||||
Promise.all(imageUrls.map(ensurePublicMediaUrl)),
|
Promise.all(imageUrls.map(ensurePublicMediaUrl)),
|
||||||
Promise.all(videoUrls.map(ensurePublicMediaUrl)),
|
Promise.all(videoUrls.map(ensurePublicMediaUrl)),
|
||||||
]);
|
]);
|
||||||
|
const taskModelId =
|
||||||
|
activeKind === "image" && publicImageUrls.length > 0
|
||||||
|
? resolveVip98kReferenceModelId(activeModelId)
|
||||||
|
: activeModelId;
|
||||||
const text = await runTask({
|
const text = await runTask({
|
||||||
apiKey,
|
apiKey,
|
||||||
baseURL: rootBaseURL,
|
baseURL: rootBaseURL,
|
||||||
modelId: activeModelId,
|
modelId: taskModelId,
|
||||||
kind: activeKind,
|
kind: activeKind,
|
||||||
prompt,
|
prompt,
|
||||||
imageUrls: publicImageUrls,
|
imageUrls: publicImageUrls,
|
||||||
|
|||||||
@ -49,7 +49,11 @@ const DEFAULT_MODEL_IDS: Record<Capability, string[]> = {
|
|||||||
chat: ["gpt-5.4-mini", "gpt-5.4", "claude-sonnet-4-6"],
|
chat: ["gpt-5.4-mini", "gpt-5.4", "claude-sonnet-4-6"],
|
||||||
multimodal: ["gpt-5.4-mini", "gpt-5.4", "claude-sonnet-4-6"],
|
multimodal: ["gpt-5.4-mini", "gpt-5.4", "claude-sonnet-4-6"],
|
||||||
image: ["nano-banana-2", "nano-banana-pro", "gpt-image-2-vip"],
|
image: ["nano-banana-2", "nano-banana-pro", "gpt-image-2-vip"],
|
||||||
"multi-image-edit": ["nano-banana-2", "nano-banana-pro", "gpt-image-2-vip"],
|
"multi-image-edit": [
|
||||||
|
"google/nano-banana-2/reference-to-image",
|
||||||
|
"google/nano-banana-pro/edit",
|
||||||
|
"openai/gpt-image-2/edit",
|
||||||
|
],
|
||||||
rmbg: ["remove-background"],
|
rmbg: ["remove-background"],
|
||||||
enhance: ["enhance", "image-upscaler"],
|
enhance: ["enhance", "image-upscaler"],
|
||||||
extend: ["image-expansion"],
|
extend: ["image-expansion"],
|
||||||
@ -302,18 +306,27 @@ async function runExternalTask(params: {
|
|||||||
capability: Capability;
|
capability: Capability;
|
||||||
}) {
|
}) {
|
||||||
const imageUrl = "https://dummyimage.com/512x512/2563eb/ffffff.png&text=VIP98K";
|
const imageUrl = "https://dummyimage.com/512x512/2563eb/ffffff.png&text=VIP98K";
|
||||||
|
const secondImageUrl = "https://dummyimage.com/512x512/dc2626/ffffff.png&text=REFERENCE";
|
||||||
const body: Record<string, unknown> = {
|
const body: Record<string, unknown> = {
|
||||||
model: params.modelId,
|
model: params.modelId,
|
||||||
displayName: `provider-smoke-${params.capability}`,
|
displayName: `provider-smoke-${params.capability}`,
|
||||||
prompt: "Create a minimal test result with one simple object",
|
prompt: "Create a minimal test result with one simple object",
|
||||||
};
|
};
|
||||||
if (["rmbg", "enhance", "extend", "image-to-3d"].includes(params.capability)) {
|
if (
|
||||||
|
["multi-image-edit", "rmbg", "enhance", "extend", "image-to-3d"].includes(
|
||||||
|
params.capability,
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
const images =
|
||||||
|
params.capability === "multi-image-edit" ? [imageUrl, secondImageUrl] : [imageUrl];
|
||||||
Object.assign(body, {
|
Object.assign(body, {
|
||||||
image: imageUrl,
|
image: imageUrl,
|
||||||
imageUrl,
|
imageUrl,
|
||||||
image_url: imageUrl,
|
image_url: imageUrl,
|
||||||
images: [imageUrl],
|
images,
|
||||||
imageUrls: [imageUrl],
|
imageUrls: images,
|
||||||
|
referenceImages: images,
|
||||||
|
reference_images: images,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (params.capability === "extend") {
|
if (params.capability === "extend") {
|
||||||
@ -424,12 +437,12 @@ async function main() {
|
|||||||
modelId,
|
modelId,
|
||||||
multimodal: capability === "multimodal",
|
multimodal: capability === "multimodal",
|
||||||
});
|
});
|
||||||
} else if (capability === "image" || capability === "multi-image-edit") {
|
} else if (capability === "image") {
|
||||||
outputs = await runOpenAIImage({
|
outputs = await runOpenAIImage({
|
||||||
baseUrl,
|
baseUrl,
|
||||||
apiKey,
|
apiKey,
|
||||||
modelId,
|
modelId,
|
||||||
multiImage: capability === "multi-image-edit",
|
multiImage: false,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
outputs = await runExternalTask({ baseUrl, apiKey, modelId, capability });
|
outputs = await runExternalTask({ baseUrl, apiKey, modelId, capability });
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user