From f7dea3b190d2c4e13abe8293b982d463b986d4ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=B8=85?= <2944435683> Date: Tue, 3 Mar 2026 22:02:15 +0800 Subject: [PATCH] no message --- src/routes/other/testImage.ts | 2 +- src/utils/ai/image/owned/other.ts | 24 +++++++++++++----------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/routes/other/testImage.ts b/src/routes/other/testImage.ts index b338ac0..1438bba 100644 --- a/src/routes/other/testImage.ts +++ b/src/routes/other/testImage.ts @@ -22,7 +22,7 @@ export default router.post( prompt: "一张16:9比例的图片,完美等分为2x2四宫格布局,各区域无缝衔接:\n左上宫格:一只可爱的猫,毛发蓬松,眼睛明亮,姿态俏皮\n右上宫格:一只友善的狗,金毛犬,表情愉悦,摇着尾巴\n左下宫格:一头健壮的牛,田园背景,目光温和,皮毛光泽\n右下宫格:一匹骏马,姿态优雅,鬃毛飘逸,肌肉健美\n风格要求:四个宫格风格统一,色彩鲜艳饱和,高清画质,细节清晰锐利,专业插画风格,线条干净,统一的左上方光源,柔和阴影,和谐配色,卡通/半写实风格,宫格间用白色或浅灰细线分隔", imageBase64: [], - aspectRatio: "16:9", + aspectRatio: "9:16", size: "1K", taskClass: "测试任务", name: "测试图片生成", diff --git a/src/utils/ai/image/owned/other.ts b/src/utils/ai/image/owned/other.ts index aa00def..12005d3 100644 --- a/src/utils/ai/image/owned/other.ts +++ b/src/utils/ai/image/owned/other.ts @@ -2,6 +2,7 @@ import "../type"; import { generateImage, generateText, ModelMessage } from "ai"; import { createOpenAICompatible } from "@ai-sdk/openai-compatible"; import { createOpenAI, OpenAIProviderSettings } from "@ai-sdk/openai"; +import { createGoogleGenerativeAI } from "@ai-sdk/google"; import axios from "axios"; @@ -30,6 +31,12 @@ export default async (input: ImageConfig, config: AIConfig): Promise => const fullPrompt = input.systemPrompt ? `${input.systemPrompt}\n\n${input.prompt}` : input.prompt; const model = config.model; if (model.includes("gemini") || model.includes("nano")) { + // 对于 Gemini 模型,使用 Google provider 以支持 imageConfig 参数 + const googleProvider = createGoogleGenerativeAI({ + apiKey: apiKey, + baseURL: config.baseURL, + }); + let promptData; if (input.imageBase64 && input.imageBase64.length) { promptData = [{ role: "system", content: fullPrompt + `请直接输出图片` }]; @@ -43,21 +50,16 @@ export default async (input: ImageConfig, config: AIConfig): Promise => } else { promptData = fullPrompt + `请直接输出图片`; } - const result = await generateText({ - model: otherProvider.languageModel(model, { provider: "other" }), + model: googleProvider.languageModel(model), prompt: promptData as string | ModelMessage[], providerOptions: { - other: { - extra_body: { - image_config: { - ...(config.model == "gemini-2.5-flash-image" - ? { aspectRatio: input.aspectRatio } - : { aspect_ratio: input.aspectRatio, image_size: input.size }), - }, + google: { + imageConfig: { + ...(config.model == "gemini-2.5-flash-image" + ? { aspectRatio: input.aspectRatio } + : { aspectRatio: input.aspectRatio, imageSize: input.size }), }, - - responseModalities: ["IMAGE"], }, }, });