feat: 优化提示词功能,参考Comfly项目实现智能优化 - 改进提示词优化系统提示,参考Comfly项目的优化策略 - 增强文生视频、图生视频、分镜图的优化效果 - 添加优化示例,提高优化质量

This commit is contained in:
AIGC Developer
2025-11-08 09:17:34 +08:00
parent 1e71ae6a26
commit 0b4fd32c59
45 changed files with 214 additions and 44 deletions

View File

@@ -219,3 +219,4 @@ ngrok http 8080

View File

@@ -114,3 +114,4 @@

View File

@@ -280,3 +280,4 @@ if (result.success) {

View File

@@ -207,3 +207,4 @@ git remote -v
git branch git branch
``` ```

View File

@@ -233,3 +233,4 @@ A: IJPay 是对原生 SDK 的封装,提供了更简洁的 API。底层实现

View File

@@ -300,3 +300,4 @@ grep "img2vid_abc123def456" logs/application.log

View File

@@ -6,3 +6,4 @@

View File

@@ -301,3 +301,4 @@ public TaskQueue addTextToVideoTask(String username, String taskId) {

View File

@@ -44,5 +44,6 @@ public class PasswordChecker {

View File

@@ -6,3 +6,4 @@

View File

@@ -6,3 +6,4 @@

View File

@@ -6,3 +6,4 @@

View File

@@ -6,3 +6,4 @@

View File

@@ -292,3 +292,4 @@ ResourceNotFound.TemplateNotFound

View File

@@ -310,3 +310,4 @@ const startPolling = (taskId) => {

View File

@@ -6,3 +6,4 @@

View File

@@ -96,3 +96,4 @@
**✅ 所有事务都能正常关闭,没有发现连接泄漏风险** **✅ 所有事务都能正常关闭,没有发现连接泄漏风险**

View File

@@ -92,3 +92,4 @@
**✅ 所有实际使用的事务配置都是正确的,不会导致连接泄漏** **✅ 所有实际使用的事务配置都是正确的,不会导致连接泄漏**

View File

@@ -180,3 +180,4 @@ const updateWork = async (workId, updateData) => {

View File

@@ -4,3 +4,4 @@
ALTER TABLE users ADD COLUMN bio TEXT COMMENT '个人简介'; ALTER TABLE users ADD COLUMN bio TEXT COMMENT '个人简介';

View File

@@ -61,3 +61,4 @@ WHERE tq.task_id = 'img2vid_1957126e9dbd46e2';
-- 查询结果 -- 查询结果
SELECT '任务已取消' as result; SELECT '任务已取消' as result;

View File

@@ -21,3 +21,4 @@ SELECT '删除完成' as result;
SELECT COUNT(*) as remaining_task_queue FROM task_queue WHERE task_id IN ('sb_025db8e9d03846d6', 'sb_ced9291de75d444d', 'sb_60698935a2cd4289'); SELECT COUNT(*) as remaining_task_queue FROM task_queue WHERE task_id IN ('sb_025db8e9d03846d6', 'sb_ced9291de75d444d', 'sb_60698935a2cd4289');
SELECT COUNT(*) as remaining_storyboard_tasks FROM storyboard_video_tasks WHERE task_id IN ('sb_025db8e9d03846d6', 'sb_ced9291de75d444d', 'sb_60698935a2cd4289'); SELECT COUNT(*) as remaining_storyboard_tasks FROM storyboard_video_tasks WHERE task_id IN ('sb_025db8e9d03846d6', 'sb_ced9291de75d444d', 'sb_60698935a2cd4289');

View File

@@ -4,3 +4,4 @@
ALTER TABLE storyboard_video_tasks ALTER TABLE storyboard_video_tasks
MODIFY COLUMN result_url TEXT COMMENT '分镜图URL可能是多个URL拼接'; MODIFY COLUMN result_url TEXT COMMENT '分镜图URL可能是多个URL拼接';

View File

@@ -444,5 +444,6 @@ MIT License

View File

@@ -40,5 +40,6 @@ console.log('App.vue 加载成功')

View File

@@ -18,3 +18,4 @@ export const processExpiredRecords = () => {
} }

View File

@@ -103,5 +103,6 @@

View File

@@ -75,3 +75,4 @@ public class MailMessage {

View File

@@ -269,3 +269,4 @@ public class TaskStatus {

View File

@@ -77,3 +77,4 @@ public interface TaskStatusRepository extends JpaRepository<TaskStatus, Long> {

View File

@@ -46,5 +46,6 @@ public class PlainTextPasswordEncoder implements PasswordEncoder {

View File

@@ -1031,60 +1031,130 @@ public class RealAIService {
/** /**
* 根据类型获取优化提示词的系统指令 * 根据类型获取优化提示词的系统指令
* 使用文本块Text Blocks优化可读性 * 参考Comfly项目的优化策略使用更智能的提示词优化
*/ */
private String getOptimizationPrompt(String type) { private String getOptimizationPrompt(String type) {
return switch (type) { return switch (type) {
case "text-to-video" -> """ case "text-to-video" -> """
你是一个专业的视频生成提示词优化专家。你的任务是将用户提供的简单描述优化为详细、专业、适合AI视频生成的英文提示词。 你是一个专业的AI视频生成提示词优化专家。你的任务是将用户提供的描述优化为详细、专业、适合AI视频生成的英文提示词。
优化要求 核心优化策略
1. 将中文描述翻译成流畅的英文,确保语义准确 1. 语言处理:
2. 添加详细的视觉细节描述(场景环境、人物特征、动作细节、光线效果、色彩风格、构图方式等) - 如果输入是中文,翻译成流畅、地道的英文
3. 使用专业的电影术语和视觉词汇cinematic, wide shot, close-up等 - 如果输入是英文,直接优化并增强表达
4. 确保提示词清晰、具体、有画面感能够准确指导AI生成 - 确保语义准确,不丢失原始意图
5. 保持原始意图不变,只优化表达方式和补充细节
6. 如果原始提示词已经是英文,直接优化,保持语言一致 2. 视觉细节增强:
7. 输出优化后的提示词,不要添加额外说明、引号或其他格式标记 - 场景环境详细描述背景、地点、氛围sunset beach, urban street, cozy cafe
8. 优化后的提示词应该直接可用,长度控制在合理范围内 - 人物特征外貌、服装、表情、姿态young woman with long hair, wearing casual clothes
- 动作细节具体动作、运动轨迹、速度walking slowly, running gracefully, dancing elegantly
- 光线效果光照方向、强度、色温soft golden hour light, dramatic shadows, natural daylight
- 色彩风格色调、饱和度、风格vibrant colors, muted tones, cinematic color grading
- 构图方式镜头类型、角度、景深wide establishing shot, close-up, shallow depth of field
3. 专业术语使用:
- 电影术语cinematic, wide shot, medium shot, close-up, extreme close-up, tracking shot, dolly shot
- 镜头运动zoom in/out, pan left/right, tilt up/down, crane shot, aerial view
- 视觉效果slow motion, time-lapse, smooth transition, dynamic movement
4. 时间维度:
- 明确视频时长和节奏
- 描述动作的持续时间和变化
- 添加时间相关的视觉元素day to night transition
5. 输出要求:
- 只输出优化后的提示词,不要添加任何说明、引号、标记或额外文字
- 提示词应该直接可用长度控制在150-300词之间
- 保持专业、清晰、有画面感
- 确保每个细节都有助于AI准确理解并生成视频
示例优化:
输入:"一个女孩在海边跑步"
输出:"A young woman running gracefully along a pristine beach at golden hour, soft warm sunlight casting long shadows on the sand, gentle ocean waves in the background, cinematic wide shot with shallow depth of field, vibrant colors, smooth camera movement following the subject, professional video quality"
"""; """;
case "image-to-video" -> """ case "image-to-video" -> """
你是一个专业的视频生成提示词优化专家。你的任务是将用户提供的简单描述优化为详细、专业、适合AI图生视频的英文提示词。 你是一个专业的AI图生视频提示词优化专家。你的任务是将用户提供的描述优化为详细、专业、适合AI图生视频的英文提示词。
优化要求 核心优化策略
1. 将中文描述翻译成流畅的英文,确保语义准确 1. 语言处理:
2. 重点关注动画效果、镜头运动、动作描述zoom in, pan, fade等 - 如果输入是中文,翻译成流畅、地道的英文
3. 添加时间维度和动态效果描述(持续时间、运动方向、速度变化等) - 如果输入是英文,直接优化并增强表达
4. 确保提示词能准确表达图片到视频的转换需求,描述动画和运动的细节 - 确保语义准确,不丢失原始意图
5. 使用专业的视频制作术语smooth transition, dynamic movement等
6. 如果原始提示词已经是英文,直接优化,保持语言一致 2. 动画效果重点:
7. 输出优化后的提示词,不要添加额外说明、引号或其他格式标记 - 镜头运动zoom in/out, pan left/right, tilt up/down, tracking shot, dolly movement
8. 优化后的提示词应该直接可用,长度控制在合理范围内 - 动态效果smooth transition, dynamic movement, fluid motion, natural flow
- 时间变化slow motion, time-lapse, gradual change, progressive movement
- 运动方向left to right, top to bottom, forward, backward, circular motion
3. 转换需求:
- 描述从静态图片到动态视频的转换方式
- 明确哪些元素需要动起来(人物、物体、背景等)
- 描述运动的速度、节奏和变化
- 添加时间维度和动态效果描述
4. 专业术语使用:
- 视频制作术语smooth transition, dynamic movement, fluid animation, cinematic motion
- 镜头运动zoom, pan, tilt, track, dolly, crane, aerial
- 视觉效果fade in/out, cross dissolve, wipe, morph
5. 输出要求:
- 只输出优化后的提示词,不要添加任何说明、引号、标记或额外文字
- 提示词应该直接可用长度控制在100-250词之间
- 重点突出动画和运动效果
- 确保能准确表达图片到视频的转换需求
示例优化:
输入:"让图片中的人物动起来"
输出:"Smooth and natural movement of the person in the image, gentle walking motion with fluid body movement, subtle camera pan following the subject, natural lighting and shadows, seamless animation transition from static to dynamic, professional video quality, smooth motion blur"
"""; """;
case "storyboard" -> """ case "storyboard" -> """
你是一个专业的分镜图提示词优化专家。你的任务是将用户提供的简单描述优化为详细、专业、适合生成故事板分镜图的英文提示词。 你是一个专业的分镜图提示词优化专家。你的任务是将用户提供的描述优化为详细、专业、适合生成故事板分镜图的英文提示词。
优化要求 核心优化策略
1. 将中文描述翻译成流畅的英文,确保语义准确 1. 语言处理:
2. 关注镜头构图、画面布局、视觉元素composition, framing, visual hierarchy等 - 如果输入是中文,翻译成流畅、地道的英文
3. 适合生成专业分镜图风格,强调构图和画面元素,包含清晰的场景描述和视觉细节 - 如果输入是英文,直接优化并增强表达
4. 确保提示词清晰描述每个镜头的关键视觉元素和构图方式 - 确保语义准确,不丢失原始意图
5. 使用专业的电影分镜术语establishing shot, medium shot, close-up, wide shot, over-the-shoulder等
6. 添加画面细节描述:场景环境、人物/物体的位置、光线、氛围等 2. 分镜图重点:
7. 如果原始提示词已经是英文,直接优化,保持语言一致 - 镜头构图composition, framing, visual hierarchy, rule of thirds
8. 输出优化后的提示词,不要添加额外说明、引号或其他格式标记 - 画面布局subject placement, background elements, foreground details
9. 优化后的提示词应该直接可用长度控制在合理范围内200-500词 - 视觉元素key visual elements, focal points, visual storytelling
10. 参考格式:"(scene description), (shot type), (composition details), (visual elements), (lighting and atmosphere), professional storyboard style, cinematic framing" - 场景描述environment, setting, atmosphere, mood
3. 专业分镜术语:
- 镜头类型establishing shot, wide shot, medium shot, close-up, extreme close-up, over-the-shoulder shot
- 构图方式rule of thirds, center composition, leading lines, symmetry, asymmetry
- 视角eye level, high angle, low angle, bird's eye view, worm's eye view
- 景深shallow depth of field, deep focus, bokeh effect
4. 画面细节:
- 场景环境:详细描述背景、地点、氛围
- 人物/物体位置:明确主体和背景的位置关系
- 光线:光照方向、强度、色温、阴影
- 氛围:情绪、风格、色调
5. 输出要求:
- 只输出优化后的提示词,不要添加任何说明、引号、标记或额外文字
- 提示词应该直接可用长度控制在200-500词之间
- 适合生成专业分镜图风格
- 强调构图和画面元素,包含清晰的场景描述和视觉细节
示例优化:
输入:"一个咖啡的广告"
输出:"Professional storyboard style, establishing shot of a modern coffee shop interior, warm ambient lighting, medium shot of a barista preparing coffee, close-up of coffee beans being ground, steam rising from espresso machine, shallow depth of field, cinematic framing, rule of thirds composition, vibrant colors, professional commercial photography style, detailed visual storytelling, coffee cup in foreground, blurred background, natural daylight through windows"
"""; """;
default -> """ default -> """
你是一个专业的提示词优化专家。请将用户提供的简单描述优化为详细、专业的英文提示词。 你是一个专业的AI提示词优化专家。请将用户提供的简单描述优化为详细、专业的英文提示词。
优化要求: 优化要求:
1. 将中文描述翻译成流畅的英文,如果已经是英文则直接优化 1. 语言处理:将中文描述翻译成流畅的英文,如果已经是英文则直接优化
2. 添加必要的视觉细节和描述,使提示词更加具体和专业 2. 细节增强:添加必要的视觉细节和描述,使提示词更加具体和专业
3. 保持原始意图不变,只优化表达方式 3. 保持意图:保持原始意图不变,只优化表达方式
4. 输出优化后的提示词,不要添加额外说明、引号或其他格式标记 4. 专业术语:使用相关领域的专业术语和词汇
5. 优化后的提示词应该直接可用,长度控制在合理范围内 5. 输出格式:只输出优化后的提示词,不要添加任何说明、引号、标记或额外文字
6. 长度控制:优化后的提示词应该直接可用,长度控制在合理范围内
"""; """;
}; };
} }

View File

@@ -4,6 +4,16 @@ spring.datasource.username=root
spring.datasource.password=177615 spring.datasource.password=177615
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
# 数据库连接池配置(开发环境 - 支持50人并发
spring.datasource.hikari.maximum-pool-size=30
spring.datasource.hikari.minimum-idle=5
spring.datasource.hikari.idle-timeout=300000
spring.datasource.hikari.max-lifetime=1200000
spring.datasource.hikari.connection-timeout=30000
spring.datasource.hikari.leak-detection-threshold=60000
spring.datasource.hikari.validation-timeout=3000
spring.datasource.hikari.connection-test-query=SELECT 1
# JPA配置 # JPA配置
spring.jpa.hibernate.ddl-auto=update spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true spring.jpa.show-sql=true
@@ -12,6 +22,19 @@ spring.jpa.properties.hibernate.format_sql=true
# 服务器配置 # 服务器配置
server.port=8080 server.port=8080
# Tomcat 最大POST大小扩大请求体大小以支持大图片Base64编码
server.tomcat.max-http-post-size=600MB
# Tomcat线程池配置支持50人并发
server.tomcat.threads.max=150
server.tomcat.threads.min-spare=20
server.tomcat.max-connections=500
server.tomcat.accept-count=100
server.tomcat.connection-timeout=20000
# 文件上传配置扩大请求体大小以支持大图片Base64编码
spring.servlet.multipart.max-file-size=500MB
spring.servlet.multipart.max-request-size=600MB
spring.servlet.multipart.enabled=true
# 日志配置 # 日志配置
logging.level.com.example.demo=DEBUG logging.level.com.example.demo=DEBUG
@@ -52,3 +75,10 @@ alipay.charset=UTF-8
alipay.sign-type=RSA2 alipay.sign-type=RSA2
alipay.notify-url=https://curtly-aphorismatic-ginger.ngrok-free.dev/api/payments/alipay/notify alipay.notify-url=https://curtly-aphorismatic-ginger.ngrok-free.dev/api/payments/alipay/notify
alipay.return-url=https://curtly-aphorismatic-ginger.ngrok-free.dev/api/payments/alipay/return alipay.return-url=https://curtly-aphorismatic-ginger.ngrok-free.dev/api/payments/alipay/return
# 视频处理配置
# FFmpeg路径如果FFmpeg不在PATH中请指定完整路径
# 已通过winget安装使用完整路径使用正斜杠避免转义问题
app.ffmpeg.path=C:/Users/UI/AppData/Local/Microsoft/WinGet/Packages/Gyan.FFmpeg_Microsoft.Winget.Source_8wekyb3d8bbwe/ffmpeg-8.0-full_build/bin/ffmpeg.exe
# 临时文件目录
app.temp.dir=./temp

View File

@@ -7,12 +7,12 @@ spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
spring.datasource.username=${DB_USERNAME} spring.datasource.username=${DB_USERNAME}
spring.datasource.password=${DB_PASSWORD} spring.datasource.password=${DB_PASSWORD}
# 数据库连接池配置 (生产环境) # 数据库连接池配置 (生产环境 - 支持50人并发)
spring.datasource.hikari.maximum-pool-size=50 spring.datasource.hikari.maximum-pool-size=30
spring.datasource.hikari.minimum-idle=10 spring.datasource.hikari.minimum-idle=5
spring.datasource.hikari.idle-timeout=300000 spring.datasource.hikari.idle-timeout=300000
spring.datasource.hikari.max-lifetime=1200000 spring.datasource.hikari.max-lifetime=1200000
spring.datasource.hikari.connection-timeout=20000 spring.datasource.hikari.connection-timeout=30000
spring.datasource.hikari.leak-detection-threshold=60000 spring.datasource.hikari.leak-detection-threshold=60000
spring.datasource.hikari.validation-timeout=3000 spring.datasource.hikari.validation-timeout=3000
spring.datasource.hikari.connection-test-query=SELECT 1 spring.datasource.hikari.connection-test-query=SELECT 1
@@ -28,6 +28,14 @@ spring.sql.init.mode=never
# Thymeleaf 可启用缓存 # Thymeleaf 可启用缓存
spring.thymeleaf.cache=true spring.thymeleaf.cache=true
# AI API配置 (生产环境)
# 文生视频、图生视频、分镜视频都使用Comfly API
ai.api.base-url=${AI_API_BASE_URL:https://ai.comfly.chat}
ai.api.key=${AI_API_KEY}
# 文生图使用Comfly API
ai.image.api.base-url=${AI_IMAGE_API_BASE_URL:https://ai.comfly.chat}
ai.image.api.key=${AI_IMAGE_API_KEY}
# 支付宝配置 (生产环境) # 支付宝配置 (生产环境)
alipay.app-id=${ALIPAY_APP_ID} alipay.app-id=${ALIPAY_APP_ID}
alipay.private-key=${ALIPAY_PRIVATE_KEY} alipay.private-key=${ALIPAY_PRIVATE_KEY}
@@ -38,7 +46,6 @@ alipay.sign-type=RSA2
alipay.notify-url=${ALIPAY_NOTIFY_URL} alipay.notify-url=${ALIPAY_NOTIFY_URL}
alipay.return-url=${ALIPAY_RETURN_URL} alipay.return-url=${ALIPAY_RETURN_URL}
# JWT配置 - 使用环境变量 # JWT配置 - 使用环境变量
jwt.secret=${JWT_SECRET} jwt.secret=${JWT_SECRET}
jwt.expiration=${JWT_EXPIRATION:604800000} jwt.expiration=${JWT_EXPIRATION:604800000}
@@ -53,6 +60,13 @@ tencent.ses.from-name=AIGC平台
# 如果未配置或为0将使用开发模式仅记录日志 # 如果未配置或为0将使用开发模式仅记录日志
tencent.ses.template-id=${TENCENT_SES_TEMPLATE_ID} tencent.ses.template-id=${TENCENT_SES_TEMPLATE_ID}
# Tomcat线程池配置 (生产环境 - 支持50人并发)
server.tomcat.threads.max=150
server.tomcat.threads.min-spare=20
server.tomcat.max-connections=500
server.tomcat.accept-count=100
server.tomcat.connection-timeout=20000
# 生产环境日志配置 # 生产环境日志配置
logging.level.root=INFO logging.level.root=INFO
logging.level.com.example.demo=INFO logging.level.com.example.demo=INFO
@@ -60,6 +74,20 @@ logging.level.org.springframework.security=WARN
logging.file.name=${LOG_FILE_PATH:./logs/application.log} logging.file.name=${LOG_FILE_PATH:./logs/application.log}
logging.pattern.file=%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n logging.pattern.file=%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n
# 视频处理配置
# 临时文件目录(相对路径:基于应用运行目录,或绝对路径)
# 生产环境建议使用绝对路径,如:/app/temp 或 C:\app\temp
app.temp.dir=${TEMP_DIR:./temp}
# FFmpeg路径如果FFmpeg在PATH中使用 "ffmpeg",否则使用完整路径)
# 生产环境建议使用完整路径,如:/usr/bin/ffmpeg 或 C:\ffmpeg\bin\ffmpeg.exe
app.ffmpeg.path=${FFMPEG_PATH:ffmpeg}
# 文件上传配置
# 上传文件保存目录(相对路径:基于应用运行目录,或绝对路径)
# 生产环境建议使用绝对路径,如:/app/uploads 或 C:\app\uploads
# 注意:确保应用有读写权限
app.upload.path=${UPLOAD_PATH:./uploads}

View File

@@ -36,3 +36,4 @@ CREATE TABLE IF NOT EXISTS task_queue (

View File

@@ -35,3 +35,4 @@ CREATE TABLE IF NOT EXISTS points_freeze_records (

View File

@@ -38,3 +38,4 @@ CREATE TABLE task_status (

View File

@@ -582,5 +582,6 @@

View File

@@ -498,5 +498,6 @@

View File

@@ -537,5 +537,6 @@

View File

@@ -39,3 +39,4 @@ pause > nul

View File

@@ -66,3 +66,4 @@ public class TestApiConnection {

View File

@@ -25,3 +25,4 @@ except Exception as e:

View File

@@ -33,3 +33,4 @@ else:

View File

@@ -69,3 +69,4 @@ if __name__ == "__main__":