ai-chatbot/lib/db/migrations/0100_add_gpt_image25_detail_replacement.sql

101 lines
4.6 KiB
SQL

WITH preferred_provider AS (
SELECT p."id"
FROM "AiProvider" p
LEFT JOIN "AiModel" m
ON m."providerId" = p."id"
AND m."modelId" = 'gpt-image-2.5-flare'
WHERE p."type" = 'vip98k'
ORDER BY
CASE WHEN m."id" IS NOT NULL THEN 0 ELSE 1 END,
CASE WHEN p."isEnabled" THEN 0 ELSE 1 END,
p."createdAt"
LIMIT 1
)
INSERT INTO "AiModel" (
"providerId",
"modelId",
"displayName",
"description",
"supportsVision",
"supportsImageGen",
"isEnabled",
"isHidden",
"isDefault",
"sortOrder",
"capabilities",
"defaultParams",
"imageGenConfig",
"updatedAt"
)
SELECT
preferred_provider."id",
'gpt-image-2.5-flare',
'gpt-image-2.5-flare',
'VIP98K 多图编辑模型,支持 1K、2K 和 4K',
true,
true,
true,
false,
false,
103,
'{"provider":"vip98k","kind":"image","mediaType":"image","modelType":"image","outputType":"image","supportedModes":["text-to-image","image-to-image","reference-images"],"supportedImageSizes":["1K","2K","4K"],"supportedAspectRatios":["auto","1:1","4:3","3:4","16:9","9:16","3:2","2:3","4:5","5:4"],"supportsMultiImageReference":true,"maxReferenceImages":8}'::jsonb,
'{"provider":"vip98k","kind":"image","endpoint":"gpt-image-2.5-flare","apiFormat":"vip98k-external-task","taskApi":"external-task","supportedModes":["text-to-image","image-to-image","reference-images"],"imageSize":"2K","quality":"auto","aspectRatio":"auto","imageCount":1}'::jsonb,
'{"maxImages":1,"maxReferenceImages":8,"supportsSize":true,"supportsQuality":true,"supports1K":true,"supports2K":true,"supports4K":true,"supportedImageSizes":["1K","2K","4K"],"supportedAspectRatios":["auto","1:1","4:3","3:4","16:9","9:16","3:2","2:3","4:5","5:4"],"supportsPromptExtend":false,"supportsNegativePrompt":false,"supportsWatermark":false,"supportsSeed":false,"creditCostPerImage":0,"creditCostMultiplierBySize":{"1K":1,"2K":1,"4K":1},"enableLoadingPlaceholder":true,"loadingColor":"yellow"}'::jsonb,
now()
FROM preferred_provider
WHERE NOT EXISTS (
SELECT 1
FROM "AiModel" existing
WHERE existing."providerId" = preferred_provider."id"
AND existing."modelId" = 'gpt-image-2.5-flare'
);
--> statement-breakpoint
WITH preferred_provider AS (
SELECT p."id"
FROM "AiProvider" p
LEFT JOIN "AiModel" m
ON m."providerId" = p."id"
AND m."modelId" = 'gpt-image-2.5-flare'
WHERE p."type" = 'vip98k'
ORDER BY
CASE WHEN m."id" IS NOT NULL THEN 0 ELSE 1 END,
CASE WHEN p."isEnabled" THEN 0 ELSE 1 END,
p."createdAt"
LIMIT 1
)
UPDATE "AiModel" target
SET
"supportsVision" = true,
"supportsImageGen" = true,
"isEnabled" = true,
"isHidden" = false,
"capabilities" = COALESCE(target."capabilities", '{}'::jsonb) ||
'{"provider":"vip98k","kind":"image","mediaType":"image","modelType":"image","outputType":"image","supportedModes":["text-to-image","image-to-image","reference-images"],"supportedImageSizes":["1K","2K","4K"],"supportedAspectRatios":["auto","1:1","4:3","3:4","16:9","9:16","3:2","2:3","4:5","5:4"],"supportsMultiImageReference":true,"maxReferenceImages":8}'::jsonb,
"defaultParams" = COALESCE(target."defaultParams", '{}'::jsonb) ||
'{"provider":"vip98k","kind":"image","endpoint":"gpt-image-2.5-flare","apiFormat":"vip98k-external-task","taskApi":"external-task","supportedModes":["text-to-image","image-to-image","reference-images"],"imageSize":"2K","quality":"auto","aspectRatio":"auto","imageCount":1}'::jsonb,
"imageGenConfig" = COALESCE(target."imageGenConfig", '{}'::jsonb) ||
'{"maxImages":1,"maxReferenceImages":8,"supportsSize":true,"supportsQuality":true,"supports1K":true,"supports2K":true,"supports4K":true,"supportedImageSizes":["1K","2K","4K"],"supportedAspectRatios":["auto","1:1","4:3","3:4","16:9","9:16","3:2","2:3","4:5","5:4"],"supportsPromptExtend":false,"supportsNegativePrompt":false,"supportsWatermark":false,"supportsSeed":false,"creditCostPerImage":0,"creditCostMultiplierBySize":{"1K":1,"2K":1,"4K":1},"enableLoadingPlaceholder":true,"loadingColor":"yellow"}'::jsonb,
"updatedAt" = now()
FROM preferred_provider
WHERE target."providerId" = preferred_provider."id"
AND target."modelId" = 'gpt-image-2.5-flare';
--> statement-breakpoint
INSERT INTO "SystemSettings" ("key", "value", "updatedAt")
VALUES (
'detail_replacement_image_model_config',
'{"modelId":"gpt-image-2.5-flare"}'::jsonb,
now()
)
ON CONFLICT ("key") DO UPDATE
SET
"value" = EXCLUDED."value",
"updatedAt" = EXCLUDED."updatedAt";
--> statement-breakpoint
INSERT INTO "SystemSettings" ("key", "value", "updatedAt")
VALUES (
'detail_replacement_vision_model_config',
'{"modelId":"qwen3.7-plus"}'::jsonb,
now()
)
ON CONFLICT ("key") DO NOTHING;