10 KiB
10 KiB
BowongAI 集成总结
🎯 集成概述
基于您提供的BowongAI API接口,我已经完整更新了模板管理系统,实现了图生图和图生视频功能的集成。
🔗 API接口信息
Webhook URL
https://n8n.bowongai.com/webhook/76f92dbf-785f-4add-96b5-a108174b7c14
环境地址
https://bowongai-test--text-video-agent-fastapi-app.modal.run
📋 支持的工作流
1. 图生图工作流
{
"workflow": "图生图",
"environment": "https://bowongai-test--text-video-agent-fastapi-app.modal.run",
"image_generation": {
"model": "gemini-2.5-flash-image-preview",
"prompt": "详细的提示词...",
"image_url": "输入图片URL"
}
}
2. 图生图+生视频工作流
{
"workflow": "图生图+生视频",
"environment": "https://bowongai-test--text-video-agent-fastapi-app.modal.run",
"image_generation": {
"model": "gemini-2.5-flash-image-preview",
"prompt": "详细的提示词...",
"image_url": "输入图片URL"
},
"video_generation": {
"model": "302/MiniMax-Hailuo-02",
"prompt": "do anything you want",
"duration": "6",
"aspect_ratio": "9:16"
}
}
🏗️ 技术实现
1. BowongAI基础服务类(通用服务)
// src/services/bowongai.service.ts
@Injectable()
export class BowongAIService {
private readonly webhookUrl = 'https://n8n.bowongai.com/webhook/76f92dbf-785f-4add-96b5-a108174b7c14';
private readonly environment = 'https://bowongai-test--text-video-agent-fastapi-app.modal.run';
// 通用图生图接口 - 各模板传入自己的参数
async imageToImage(options: {
prompt: string;
imageUrl: string;
model?: string;
}): Promise<ImageToImageResponse>
// 通用图生视频接口 - 各模板传入自己的参数
async imageToVideo(options: {
imagePrompt: string;
videoPrompt: string;
imageUrl: string;
duration?: number;
aspectRatio?: string;
imageModel?: string;
videoModel?: string;
}): Promise<ImageToVideoResponse>
}
2. 具体模板实现(各自定制)
换装模板(图生图)
@Injectable()
export class OutfitChangeTemplate extends ImageGenerateTemplate {
readonly metadata = {
code: 'outfit_change_v1',
name: '智能换装',
category: '换装',
creditCost: 15,
};
constructor(private readonly bowongAI: BowongAIService) {}
async execute(input, context) {
// 换装模板专用提示词
const prompt = this.buildOutfitChangePrompt(input);
return await this.bowongAI.imageToImage({
prompt,
imageUrl: input.inputImage,
model: 'gemini-2.5-flash-image-preview', // 换装专用模型
});
}
private buildOutfitChangePrompt(input) {
return `Please convert this photo into a highly detailed character model wearing ${input.clothingDescription}. Place in front of the model a delicate, colorful box featuring the printed image of the person from the photo...`;
}
}
人像增强模板(图生图)
@Injectable()
export class PortraitEnhanceTemplate extends ImageGenerateTemplate {
readonly metadata = {
code: 'portrait_enhance_v1',
name: '人像增强',
category: '人像处理',
creditCost: 12,
};
constructor(private readonly bowongAI: BowongAIService) {}
async execute(input, context) {
// 人像增强专用提示词
const prompt = this.buildPortraitPrompt(input);
return await this.bowongAI.imageToImage({
prompt,
imageUrl: input.inputImage,
model: 'gemini-2.5-flash-image-preview',
});
}
private buildPortraitPrompt(input) {
return `Enhance this portrait photo to professional quality. Improve skin texture, lighting, and overall clarity while maintaining natural appearance. ${input.enhanceLevel === 'subtle' ? 'Apply subtle enhancements' : 'Apply dramatic improvements'}...`;
}
}
动态视频模板(图生视频)
@Injectable()
export class DynamicVideoTemplate extends VideoGenerateTemplate {
readonly metadata = {
code: 'dynamic_video_v1',
name: '动态视频',
category: '视频生成',
creditCost: 45,
};
constructor(private readonly bowongAI: BowongAIService) {}
async execute(input, context) {
// 动态视频专用提示词
const imagePrompt = this.buildImagePrompt(input);
const videoPrompt = this.buildVideoPrompt(input);
return await this.bowongAI.imageToVideo({
imagePrompt,
videoPrompt,
imageUrl: input.inputImage,
duration: input.duration || 4,
aspectRatio: input.aspectRatio || '9:16',
imageModel: 'gemini-2.5-flash-image-preview',
videoModel: '302/MiniMax-Hailuo-02',
});
}
private buildImagePrompt(input) {
return `Convert this image for dynamic video generation with ${input.motionType} motion effects...`;
}
private buildVideoPrompt(input) {
return `Create ${input.motionType} animation with ${input.intensity} intensity. ${input.customPrompt || 'Natural movement'}`;
}
}
🎨 模板化提示词设计
换装模板提示词
private buildOutfitChangePrompt(input: OutfitChangeInput): string {
const styleMap = {
casual: 'casual everyday wear',
formal: 'formal business attire',
vintage: 'vintage retro style',
modern: 'modern contemporary fashion',
elegant: 'elegant sophisticated style'
};
const styleText = styleMap[input.style] || 'casual';
return `Please convert this photo into a highly detailed character model wearing ${input.clothingDescription}.
Style: ${styleText}.
Place in front of the model a delicate, colorful box featuring the printed image of the person from the photo.
Behind the box, show a computer screen actively displaying the modeling process.
Set the entire scene in a bright, stylish indoor environment.
Ensure the lighting is crisp and luminous, highlighting both the model and its packaging.`;
}
人像增强模板提示词
private buildPortraitPrompt(input: PortraitEnhanceInput): string {
const enhancementLevels = {
subtle: 'Apply subtle professional enhancements',
moderate: 'Apply moderate quality improvements',
dramatic: 'Apply dramatic professional transformation'
};
const enhancement = enhancementLevels[input.enhanceLevel] || 'moderate';
return `${enhancement} to this portrait photo.
Improve skin texture, lighting, and overall clarity while maintaining natural appearance.
Focus on professional photography quality with ${input.lightingStyle || 'natural'} lighting.
Preserve the person's unique features and expressions.`;
}
动态视频模板提示词
private buildVideoPrompt(input: DynamicVideoInput): string {
const motionTypes = {
gentle: 'gentle subtle movements',
dynamic: 'dynamic energetic motion',
cinematic: 'cinematic smooth transitions',
artistic: 'artistic creative effects'
};
const motion = motionTypes[input.motionType] || 'gentle';
return `Create ${motion} with ${input.intensity || 'medium'} intensity.
${input.customPrompt || 'Natural lifelike movement'}.
Maintain character consistency throughout the animation.`;
}
💰 模板积分消耗
图生图模板
- 换装模板: 15积分
- 人像增强: 12积分
- 风格转换: 18积分
- 背景替换: 20积分
图生视频模板
- 动态视频: 45积分
- 角色动画: 50积分
- 场景视频: 55积分
- 特效视频: 60积分
🔧 环境配置
# BowongAI 配置
BOWONGAI_WEBHOOK_URL=https://n8n.bowongai.com/webhook/76f92dbf-785f-4add-96b5-a108174b7c14
BOWONGAI_ENVIRONMENT=https://bowongai-test--text-video-agent-fastapi-app.modal.run
📱 前端调用示例
图生图调用
const response = await fetch('/api/templates/outfit_change_v1/execute', {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
inputImage: 'https://cdn.roasmax.cn/upload/e9066bf20fb546b09ece65d6fbcf2dd3.png',
clothingDescription: '红色连衣裙',
style: 'elegant'
})
});
图生视频调用
const response = await fetch('/api/templates/image_to_video_v1/execute', {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
inputImage: 'https://cdn.roasmax.cn/upload/e9066bf20fb546b09ece65d6fbcf2dd3.png',
videoPrompt: '让角色动起来',
duration: 6,
resolution: '9:16'
})
});
✅ 基础服务架构优势
🏗️ 分层设计
- BowongAI基础服务层: 提供通用的API调用能力
- 模板业务层: 各模板实现自己的业务逻辑和提示词
- 参数定制层: 每个模板可以传入不同的参数配置
🎯 模板独立性
- ✅ 每个模板有独立的提示词逻辑
- ✅ 每个模板有独立的参数验证
- ✅ 每个模板有独立的积分消耗
- ✅ 每个模板可以选择不同的AI模型
📊 当前实现状态
- ✅ BowongAI基础服务实现
- ✅ 换装模板(图生图)- 15积分
- ✅ 图生视频模板 - 50积分
- ✅ 人像增强模板 - 12积分
- ✅ 模板工厂和模块配置
- ✅ 环境配置和前端示例
🚀 扩展新模板步骤
- 继承对应的抽象类
- 实现execute方法,调用BowongAI基础服务
- 定义模板专用的提示词构建逻辑
- 配置模板特定的参数和积分
- 在工厂类中注册新模板
示例:添加风格转换模板
@Injectable()
export class StyleTransferTemplate extends ImageGenerateTemplate {
async execute(input, context) {
const prompt = this.buildStylePrompt(input); // 风格转换专用提示词
return await this.bowongAI.imageToImage({
prompt,
imageUrl: input.inputImage,
model: 'gemini-2.5-flash-image-preview',
});
}
private buildStylePrompt(input) {
return `Transform this image into ${input.targetStyle} style...`;
}
}
现在BowongAI作为基础服务,支持各种模板的个性化定制!🎉