no message

This commit is contained in:
小帅 2026-03-03 22:02:15 +08:00
parent 931e16bb3d
commit f7dea3b190
2 changed files with 14 additions and 12 deletions

View File

@ -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: "测试图片生成",

View File

@ -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<string> =>
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<string> =>
} 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"],
},
},
});