Merge 5d1cc73410
into e32a44a4cb
This commit is contained in:
commit
3c6795880f
|
@ -8,20 +8,68 @@
|
||||||
"parameters": {
|
"parameters": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"prompt": {
|
"model": {
|
||||||
"type": "string",
|
"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": {
|
"meta": {
|
||||||
"avatar": "🎉",
|
"avatar": "🎉",
|
||||||
"description": "This plugin uses Alibaba's Tongyi Wanxiang model to generate images based on text prompts.",
|
"description": "该插件利用阿里巴巴的通义万相模型,根据文本提示生成图像。",
|
||||||
"tags": ["image", "generator", "tongyi", "wanxiang", "alibaba"],
|
"tags": ["image", "generator", "tongyi", "wanxiang", "alibaba"],
|
||||||
"title": "Tongyi wanxiang Image Generator"
|
"title": "通义万相图像生成器"
|
||||||
},
|
},
|
||||||
"settings": {
|
"settings": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
|
@ -30,10 +78,10 @@
|
||||||
"ALIBABA_API_KEY": {
|
"ALIBABA_API_KEY": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"title": "Alibaba API Key",
|
"title": "Alibaba API Key",
|
||||||
"description": "The API key to use the Alibaba Tongyi Wanxiang model"
|
"description": "用于使用阿里通义万相模型的API密钥"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"version": "1",
|
"version": "1",
|
||||||
"systemRole": "This plugin uses Alibaba's Tongyi Wanxiang model to generate images based on text prompts."
|
"systemRole": "该插件利用阿里巴巴的通义万象模型,根据文本提示生成图像。"
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,7 @@ import {createErrorResponse, getPluginSettingsFromRequest, PluginErrorType} from
|
||||||
import {IImageGenerationResponse, IImageGenerationResult, IImageGenerationStatusResponse, Settings} from "@/type";
|
import {IImageGenerationResponse, IImageGenerationResult, IImageGenerationStatusResponse, Settings} from "@/type";
|
||||||
import axios from "axios";
|
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) {
|
export async function POST(req: NextRequest) {
|
||||||
try {
|
try {
|
||||||
|
@ -17,19 +16,23 @@ export async function POST(req: NextRequest) {
|
||||||
const apiKey = settings.ALIBABA_API_KEY
|
const apiKey = settings.ALIBABA_API_KEY
|
||||||
|
|
||||||
const body = await req.json();
|
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生成图片
|
// 调用阿里云的API生成图片
|
||||||
const response = await axios.post(
|
const response = await axios.post(
|
||||||
`${BASE_URL}/services/aigc/text2image/image-synthesis`,
|
`${BASE_URL}/services/aigc/text2image/image-synthesis`,
|
||||||
{
|
{
|
||||||
model: 'wanx-v1',
|
model: model,
|
||||||
input: {
|
input: input,
|
||||||
prompt: prompt
|
parameters: requestParameters,
|
||||||
},
|
|
||||||
parameters: {
|
|
||||||
n: 1,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -57,7 +60,6 @@ export async function POST(req: NextRequest) {
|
||||||
const taskId = respData.output.task_id;
|
const taskId = respData.output.task_id;
|
||||||
|
|
||||||
// 检查图片生成的状态
|
// 检查图片生成的状态
|
||||||
|
|
||||||
let statusData: IImageGenerationStatusResponse;
|
let statusData: IImageGenerationStatusResponse;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
@ -89,11 +91,12 @@ export async function POST(req: NextRequest) {
|
||||||
|
|
||||||
// 构建 Markdown 格式的响应
|
// 构建 Markdown 格式的响应
|
||||||
const markdownResponse = `
|
const markdownResponse = `
|
||||||
图片已成功生成!
|
图片:
|
||||||
|
|
||||||

|

|
||||||
|
*提示词: ${input.prompt}*
|
||||||
*提示词: ${prompt}*
|
${input.negative_prompt ? `*反向提示词: ${input.negative_prompt}*` : ''}
|
||||||
|
*模型: ${model}*
|
||||||
|
*尺寸: ${requestParameters.size}*
|
||||||
`.trim();
|
`.trim();
|
||||||
|
|
||||||
// 返回生成的图片URL
|
// 返回生成的图片URL
|
||||||
|
@ -104,4 +107,4 @@ export async function POST(req: NextRequest) {
|
||||||
message: 'Failed to generate image.'
|
message: 'Failed to generate image.'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue