ai-chatbot/lib/ai/snapgen-image-models.ts
2026-06-24 11:35:41 +08:00

242 lines
7.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

export const SNAPGEN_IMAGE_BASE_URL = "https://api.snapgen.ai";
export const SNAPGEN_NANO_BANANA_PRO_MODEL_ID = "snapgen/nano-banana-pro";
export const SNAPGEN_NANO_BANANA_2_MODEL_ID = "snapgen/nano-banana-2";
export const SNAPGEN_GROK_IMAGE_MODEL_ID = "snapgen/grok-image";
export const SNAPGEN_META_AI_IMAGE_MODEL_ID = "snapgen/meta-ai-image";
export const SNAPGEN_GPT_IMAGE_2_MODEL_ID = "snapgen/gpt-image-2";
export interface SnapgenImageModelPreset {
modelId: string;
displayName: string;
description: string;
supportsVision: boolean;
supportsImageGen: boolean;
capabilities?: Record<string, any>;
defaultParams?: Record<string, any>;
imageGenConfig?: Record<string, any>;
sortOrder: number;
}
const SNAPGEN_COMMON_IMAGE_CONFIG = {
supportsSize: true,
supports1K: true,
supports2K: true,
supports4K: true,
supportsPromptExtend: false,
supportsNegativePrompt: false,
supportsWatermark: false,
supportsSeed: false,
creditCostPerImage: 0,
enableLoadingPlaceholder: true,
loadingColor: "blue",
};
export const SNAPGEN_STANDARD_REQUEST_ASPECT_RATIOS = ["1:1", "16:9", "9:16", "4:3", "3:4"];
export const SNAPGEN_GPT_IMAGE_2_REQUEST_ASPECT_RATIOS = [
"1:1",
"16:9",
"9:16",
"4:3",
"3:4",
"21:9",
"3:2",
"2:3",
];
const SNAPGEN_STANDARD_ASPECT_RATIOS = ["auto", ...SNAPGEN_STANDARD_REQUEST_ASPECT_RATIOS];
const SNAPGEN_GPT_IMAGE_2_ASPECT_RATIOS = [
"auto",
...SNAPGEN_GPT_IMAGE_2_REQUEST_ASPECT_RATIOS,
];
export const SNAPGEN_IMAGE_MODEL_PRESETS: SnapgenImageModelPreset[] = [
{
modelId: SNAPGEN_NANO_BANANA_PRO_MODEL_ID,
displayName: "SnapGen Nano Banana Pro",
description:
"SnapGen Gemini 3 Pro Image Preview 生图模型,面向高保真、文字渲染和复杂提示词场景。",
supportsVision: true,
supportsImageGen: true,
capabilities: {
provider: "snapgen",
kind: "image-generation",
endpoint: "nano-banana-pro",
apiFormat: "snapgen-generic-image",
officialUrl: "https://docs.snapgen.ai/resources/0.image-generation",
requiredFields: ["prompt", "model"],
optionalFields: ["aspect_ratio", "resolution", "style", "file_urls", "output_format"],
supportsMultiImageReference: true,
maxReferenceImages: 8,
},
defaultParams: {
provider: "snapgen",
endpoint: "nano-banana-pro",
apiFormat: "snapgen-generic-image",
imageSize: "2K",
aspectRatio: "1:1",
outputFormat: "png",
},
imageGenConfig: {
...SNAPGEN_COMMON_IMAGE_CONFIG,
maxImages: 1,
supportedAspectRatios: SNAPGEN_STANDARD_ASPECT_RATIOS,
supportedImageSizes: ["1K", "2K", "4K"],
},
sortOrder: 10,
},
{
modelId: SNAPGEN_NANO_BANANA_2_MODEL_ID,
displayName: "SnapGen Nano Banana 2",
description:
"SnapGen Gemini 3 Flash Image Preview 生图模型,适合快速生成和高频图片任务。",
supportsVision: true,
supportsImageGen: true,
capabilities: {
provider: "snapgen",
kind: "image-generation",
endpoint: "nano-banana-2",
apiFormat: "snapgen-generic-image",
officialUrl: "https://docs.snapgen.ai/resources/0.image-generation",
requiredFields: ["prompt", "model"],
optionalFields: ["aspect_ratio", "resolution", "style", "file_urls", "output_format"],
supportsMultiImageReference: true,
maxReferenceImages: 8,
},
defaultParams: {
provider: "snapgen",
endpoint: "nano-banana-2",
apiFormat: "snapgen-generic-image",
imageSize: "1K",
aspectRatio: "1:1",
outputFormat: "png",
},
imageGenConfig: {
...SNAPGEN_COMMON_IMAGE_CONFIG,
maxImages: 1,
supportedAspectRatios: SNAPGEN_STANDARD_ASPECT_RATIOS,
supportedImageSizes: ["1K", "2K", "4K"],
},
sortOrder: 20,
},
{
modelId: SNAPGEN_GROK_IMAGE_MODEL_ID,
displayName: "SnapGen Grok Image",
description:
"SnapGen Grok Image 生成接口,支持 SPEED / QUALITY 模式、横竖方图和最多 8 张输出。",
supportsVision: true,
supportsImageGen: true,
capabilities: {
provider: "snapgen",
kind: "image-generation",
endpoint: "/uapi/v1/imagen/grok",
apiFormat: "snapgen-grok-image",
officialUrl: "https://docs.snapgen.ai/resources/1.grok_image",
requiredFields: ["prompt"],
optionalFields: ["orientation", "num_result", "mode", "ref_history", "files"],
supportsMultiImageReference: true,
maxReferenceImages: 8,
},
defaultParams: {
provider: "snapgen",
endpoint: "/uapi/v1/imagen/grok",
apiFormat: "snapgen-grok-image",
imageSize: "1K",
aspectRatio: "1:1",
mode: "SPEED",
},
imageGenConfig: {
...SNAPGEN_COMMON_IMAGE_CONFIG,
supportsSize: false,
maxImages: 8,
supportedAspectRatios: SNAPGEN_STANDARD_ASPECT_RATIOS,
supportedQualities: ["SPEED", "QUALITY"],
},
sortOrder: 30,
},
{
modelId: SNAPGEN_META_AI_IMAGE_MODEL_ID,
displayName: "SnapGen Meta AI Image",
description:
"SnapGen Meta AI 图片生成接口,支持横图、竖图、方图和最多 4 张输出。",
supportsVision: true,
supportsImageGen: true,
capabilities: {
provider: "snapgen",
kind: "image-generation",
endpoint: "/uapi/v1/meta_ai/generate",
apiFormat: "snapgen-meta-ai-image",
officialUrl: "https://docs.snapgen.ai/resources/2.image_meta-ai",
requiredFields: ["prompt"],
optionalFields: ["orientation", "num_result", "ref_history", "files"],
supportsMultiImageReference: true,
maxReferenceImages: 8,
},
defaultParams: {
provider: "snapgen",
endpoint: "/uapi/v1/meta_ai/generate",
apiFormat: "snapgen-meta-ai-image",
imageSize: "1K",
aspectRatio: "1:1",
},
imageGenConfig: {
...SNAPGEN_COMMON_IMAGE_CONFIG,
supportsSize: false,
maxImages: 4,
supportedAspectRatios: SNAPGEN_STANDARD_ASPECT_RATIOS,
},
sortOrder: 40,
},
{
modelId: SNAPGEN_GPT_IMAGE_2_MODEL_ID,
displayName: "SnapGen GPT Image 2",
description:
"SnapGen GPT Image 2 高质量图片生成接口,支持多种比例、1K-12K 分辨率和低/中/高质量模式。",
supportsVision: true,
supportsImageGen: true,
capabilities: {
provider: "snapgen",
kind: "image-generation",
endpoint: "/uapi/v1/imagen/gpt-image-2",
apiFormat: "snapgen-gpt-image-2",
officialUrl: "https://docs.snapgen.ai/resources/3.gpt-image-2",
requiredFields: ["prompt"],
optionalFields: ["aspect_ratio", "resolution", "mode", "ref_history", "files"],
supportsMultiImageReference: true,
maxReferenceImages: 8,
},
defaultParams: {
provider: "snapgen",
endpoint: "/uapi/v1/imagen/gpt-image-2",
apiFormat: "snapgen-gpt-image-2",
imageSize: "2K",
aspectRatio: "1:1",
mode: "low",
},
imageGenConfig: {
...SNAPGEN_COMMON_IMAGE_CONFIG,
maxImages: 1,
supportedAspectRatios: SNAPGEN_GPT_IMAGE_2_ASPECT_RATIOS,
supportedImageSizes: ["1K", "2K", "4K", "8K", "10K", "12K"],
supportedQualities: ["low", "medium", "high"],
},
sortOrder: 50,
},
];
export function getSnapgenImageModelPresetById(modelId: string) {
return SNAPGEN_IMAGE_MODEL_PRESETS.find(
(preset) => preset.modelId === String(modelId || "").trim()
);
}
export function resolveSnapgenImageRuntimeModelId(modelId: string) {
const preset = getSnapgenImageModelPresetById(modelId);
const endpoint = preset?.defaultParams?.endpoint;
if (typeof endpoint === "string" && endpoint.trim()) {
return endpoint.trim();
}
return modelId;
}