diff --git a/public/manifest.json b/public/manifest.json index fb9824d..7644f72 100644 --- a/public/manifest.json +++ b/public/manifest.json @@ -8,20 +8,68 @@ "parameters": { "type": "object", "properties": { - "prompt": { + "model": { "type": "string", - "description": "The text prompt to generate the image from" + "description": "The model name to use for image generation", + "default": "wanx2.1-t2i-turbo", + "enum": [ + "wanx2.1-t2i-turbo", + "wanx2.1-t2i-plus", + "wanx2.0-t2i-turbo" + ] + }, + "input": { + "type": "object", + "properties": { + "prompt": { + "type": "string", + "description": "Positive prompt describing elements and visual features desired in the generated image. Supports Chinese and English, up to 800 characters" + }, + "negative_prompt": { + "type": "string", + "description": "Negative prompt describing elements you don't want in the image. Supports Chinese and English, up to 500 characters" + } + }, + "required": ["prompt"] + }, + "parameters": { + "type": "object", + "properties": { + "size": { + "type": "string", + "description": "Resolution of the output image. Width and height should be between 768 and 1440 pixels, up to 2 million pixels total", + "default": "1024*1024" + }, + "n": { + "type": "integer", + "description": "Number of images to generate, between 1 and 4", + "minimum": 1, + "maximum": 4, + "default": 1 + }, + "seed": { + "type": "integer", + "description": "Random seed to control generation randomness. Range: [0, 2147483647]", + "minimum": 0, + "maximum": 2147483647 + }, + "prompt_extend": { + "type": "boolean", + "description": "Whether to enable intelligent prompt rewriting for better results. Only affects positive prompts", + "default": true + } + } } }, - "required": ["prompt"] + "required": ["model","input"] } } ], "meta": { "avatar": "🎉", - "description": "This plugin uses Alibaba's Tongyi Wanxiang model to generate images based on text prompts.", + "description": "该插件利用阿里巴巴的通义万相模型,根据文本提示生成图像。", "tags": ["image", "generator", "tongyi", "wanxiang", "alibaba"], - "title": "Tongyi wanxiang Image Generator" + "title": "通义万相图像生成器" }, "settings": { "type": "object", @@ -30,10 +78,10 @@ "ALIBABA_API_KEY": { "type": "string", "title": "Alibaba API Key", - "description": "The API key to use the Alibaba Tongyi Wanxiang model" + "description": "用于使用阿里通义万相模型的API密钥" } } }, "version": "1", - "systemRole": "This plugin uses Alibaba's Tongyi Wanxiang model to generate images based on text prompts." -} \ No newline at end of file + "systemRole": "该插件利用阿里巴巴的通义万象模型,根据文本提示生成图像。" +} diff --git a/src/app/api/generate/route.ts b/src/app/api/generate/route.ts index 31e92b1..44934a3 100644 --- a/src/app/api/generate/route.ts +++ b/src/app/api/generate/route.ts @@ -3,8 +3,7 @@ import {createErrorResponse, getPluginSettingsFromRequest, PluginErrorType} from import {IImageGenerationResponse, IImageGenerationResult, IImageGenerationStatusResponse, Settings} from "@/type"; import axios from "axios"; -const BASE_URL = process.env.BASE_URL || 'https://api.alibabacloud.com' - +const BASE_URL = process.env.BASE_URL || 'https://dashscope.aliyuncs.com/api/v1' export async function POST(req: NextRequest) { try { @@ -17,19 +16,23 @@ export async function POST(req: NextRequest) { const apiKey = settings.ALIBABA_API_KEY const body = await req.json(); - const { prompt } = body + const { model, input, parameters } = body; + + // 设置默认参数 + const requestParameters = { + size: '1024*1024', + n: 1, + prompt_extend: true, + ...parameters + }; // 调用阿里云的API生成图片 const response = await axios.post( `${BASE_URL}/services/aigc/text2image/image-synthesis`, { - model: 'wanx-v1', - input: { - prompt: prompt - }, - parameters: { - n: 1, - }, + model: model, + input: input, + parameters: requestParameters, }, { headers: { @@ -57,7 +60,6 @@ export async function POST(req: NextRequest) { const taskId = respData.output.task_id; // 检查图片生成的状态 - let statusData: IImageGenerationStatusResponse; do { @@ -89,11 +91,12 @@ export async function POST(req: NextRequest) { // 构建 Markdown 格式的响应 const markdownResponse = ` - 图片已成功生成! - + 图片: ![Generated Image](${imageUrl}) - - *提示词: ${prompt}* + *提示词: ${input.prompt}* + ${input.negative_prompt ? `*反向提示词: ${input.negative_prompt}*` : ''} + *模型: ${model}* + *尺寸: ${requestParameters.size}* `.trim(); // 返回生成的图片URL @@ -104,4 +107,4 @@ export async function POST(req: NextRequest) { message: 'Failed to generate image.' }) } -} \ No newline at end of file +}