no message
This commit is contained in:
parent
931e16bb3d
commit
f7dea3b190
@ -22,7 +22,7 @@ export default router.post(
|
|||||||
prompt:
|
prompt:
|
||||||
"一张16:9比例的图片,完美等分为2x2四宫格布局,各区域无缝衔接:\n左上宫格:一只可爱的猫,毛发蓬松,眼睛明亮,姿态俏皮\n右上宫格:一只友善的狗,金毛犬,表情愉悦,摇着尾巴\n左下宫格:一头健壮的牛,田园背景,目光温和,皮毛光泽\n右下宫格:一匹骏马,姿态优雅,鬃毛飘逸,肌肉健美\n风格要求:四个宫格风格统一,色彩鲜艳饱和,高清画质,细节清晰锐利,专业插画风格,线条干净,统一的左上方光源,柔和阴影,和谐配色,卡通/半写实风格,宫格间用白色或浅灰细线分隔",
|
"一张16:9比例的图片,完美等分为2x2四宫格布局,各区域无缝衔接:\n左上宫格:一只可爱的猫,毛发蓬松,眼睛明亮,姿态俏皮\n右上宫格:一只友善的狗,金毛犬,表情愉悦,摇着尾巴\n左下宫格:一头健壮的牛,田园背景,目光温和,皮毛光泽\n右下宫格:一匹骏马,姿态优雅,鬃毛飘逸,肌肉健美\n风格要求:四个宫格风格统一,色彩鲜艳饱和,高清画质,细节清晰锐利,专业插画风格,线条干净,统一的左上方光源,柔和阴影,和谐配色,卡通/半写实风格,宫格间用白色或浅灰细线分隔",
|
||||||
imageBase64: [],
|
imageBase64: [],
|
||||||
aspectRatio: "16:9",
|
aspectRatio: "9:16",
|
||||||
size: "1K",
|
size: "1K",
|
||||||
taskClass: "测试任务",
|
taskClass: "测试任务",
|
||||||
name: "测试图片生成",
|
name: "测试图片生成",
|
||||||
|
|||||||
@ -2,6 +2,7 @@ import "../type";
|
|||||||
import { generateImage, generateText, ModelMessage } from "ai";
|
import { generateImage, generateText, ModelMessage } from "ai";
|
||||||
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
|
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
|
||||||
import { createOpenAI, OpenAIProviderSettings } from "@ai-sdk/openai";
|
import { createOpenAI, OpenAIProviderSettings } from "@ai-sdk/openai";
|
||||||
|
import { createGoogleGenerativeAI } from "@ai-sdk/google";
|
||||||
|
|
||||||
import axios from "axios";
|
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 fullPrompt = input.systemPrompt ? `${input.systemPrompt}\n\n${input.prompt}` : input.prompt;
|
||||||
const model = config.model;
|
const model = config.model;
|
||||||
if (model.includes("gemini") || model.includes("nano")) {
|
if (model.includes("gemini") || model.includes("nano")) {
|
||||||
|
// 对于 Gemini 模型,使用 Google provider 以支持 imageConfig 参数
|
||||||
|
const googleProvider = createGoogleGenerativeAI({
|
||||||
|
apiKey: apiKey,
|
||||||
|
baseURL: config.baseURL,
|
||||||
|
});
|
||||||
|
|
||||||
let promptData;
|
let promptData;
|
||||||
if (input.imageBase64 && input.imageBase64.length) {
|
if (input.imageBase64 && input.imageBase64.length) {
|
||||||
promptData = [{ role: "system", content: fullPrompt + `请直接输出图片` }];
|
promptData = [{ role: "system", content: fullPrompt + `请直接输出图片` }];
|
||||||
@ -43,21 +50,16 @@ export default async (input: ImageConfig, config: AIConfig): Promise<string> =>
|
|||||||
} else {
|
} else {
|
||||||
promptData = fullPrompt + `请直接输出图片`;
|
promptData = fullPrompt + `请直接输出图片`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await generateText({
|
const result = await generateText({
|
||||||
model: otherProvider.languageModel(model, { provider: "other" }),
|
model: googleProvider.languageModel(model),
|
||||||
prompt: promptData as string | ModelMessage[],
|
prompt: promptData as string | ModelMessage[],
|
||||||
providerOptions: {
|
providerOptions: {
|
||||||
other: {
|
google: {
|
||||||
extra_body: {
|
imageConfig: {
|
||||||
image_config: {
|
...(config.model == "gemini-2.5-flash-image"
|
||||||
...(config.model == "gemini-2.5-flash-image"
|
? { aspectRatio: input.aspectRatio }
|
||||||
? { aspectRatio: input.aspectRatio }
|
: { aspectRatio: input.aspectRatio, imageSize: input.size }),
|
||||||
: { aspect_ratio: input.aspectRatio, image_size: input.size }),
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
|
|
||||||
responseModalities: ["IMAGE"],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user