feat: 优化提示词功能,参考Comfly项目实现智能优化 - 改进提示词优化系统提示,参考Comfly项目的优化策略 - 增强文生视频、图生视频、分镜图的优化效果 - 添加优化示例,提高优化质量
This commit is contained in:
@@ -75,3 +75,4 @@ public class MailMessage {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -269,3 +269,4 @@ public class TaskStatus {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -77,3 +77,4 @@ public interface TaskStatusRepository extends JpaRepository<TaskStatus, Long> {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -46,5 +46,6 @@ public class PlainTextPasswordEncoder implements PasswordEncoder {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1031,60 +1031,130 @@ public class RealAIService {
|
||||
|
||||
/**
|
||||
* 根据类型获取优化提示词的系统指令
|
||||
* 使用文本块(Text Blocks)优化可读性
|
||||
* 参考Comfly项目的优化策略,使用更智能的提示词优化
|
||||
*/
|
||||
private String getOptimizationPrompt(String type) {
|
||||
return switch (type) {
|
||||
case "text-to-video" -> """
|
||||
你是一个专业的视频生成提示词优化专家。你的任务是将用户提供的简单描述优化为详细、专业、适合AI视频生成的英文提示词。
|
||||
你是一个专业的AI视频生成提示词优化专家。你的任务是将用户提供的描述优化为详细、专业、适合AI视频生成的英文提示词。
|
||||
|
||||
优化要求:
|
||||
1. 将中文描述翻译成流畅的英文,确保语义准确
|
||||
2. 添加详细的视觉细节描述(场景环境、人物特征、动作细节、光线效果、色彩风格、构图方式等)
|
||||
3. 使用专业的电影术语和视觉词汇(如:cinematic, wide shot, close-up等)
|
||||
4. 确保提示词清晰、具体、有画面感,能够准确指导AI生成
|
||||
5. 保持原始意图不变,只优化表达方式和补充细节
|
||||
6. 如果原始提示词已经是英文,直接优化,保持语言一致
|
||||
7. 输出优化后的提示词,不要添加额外说明、引号或其他格式标记
|
||||
8. 优化后的提示词应该直接可用,长度控制在合理范围内
|
||||
核心优化策略:
|
||||
1. 语言处理:
|
||||
- 如果输入是中文,翻译成流畅、地道的英文
|
||||
- 如果输入是英文,直接优化并增强表达
|
||||
- 确保语义准确,不丢失原始意图
|
||||
|
||||
2. 视觉细节增强:
|
||||
- 场景环境:详细描述背景、地点、氛围(如:sunset beach, urban street, cozy cafe)
|
||||
- 人物特征:外貌、服装、表情、姿态(如: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" -> """
|
||||
你是一个专业的视频生成提示词优化专家。你的任务是将用户提供的简单描述优化为详细、专业、适合AI图生视频的英文提示词。
|
||||
你是一个专业的AI图生视频提示词优化专家。你的任务是将用户提供的描述优化为详细、专业、适合AI图生视频的英文提示词。
|
||||
|
||||
优化要求:
|
||||
1. 将中文描述翻译成流畅的英文,确保语义准确
|
||||
2. 重点关注动画效果、镜头运动、动作描述(如:zoom in, pan, fade等)
|
||||
3. 添加时间维度和动态效果描述(持续时间、运动方向、速度变化等)
|
||||
4. 确保提示词能准确表达图片到视频的转换需求,描述动画和运动的细节
|
||||
5. 使用专业的视频制作术语(如:smooth transition, dynamic movement等)
|
||||
6. 如果原始提示词已经是英文,直接优化,保持语言一致
|
||||
7. 输出优化后的提示词,不要添加额外说明、引号或其他格式标记
|
||||
8. 优化后的提示词应该直接可用,长度控制在合理范围内
|
||||
核心优化策略:
|
||||
1. 语言处理:
|
||||
- 如果输入是中文,翻译成流畅、地道的英文
|
||||
- 如果输入是英文,直接优化并增强表达
|
||||
- 确保语义准确,不丢失原始意图
|
||||
|
||||
2. 动画效果重点:
|
||||
- 镜头运动:zoom in/out, pan left/right, tilt up/down, tracking shot, dolly movement
|
||||
- 动态效果: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" -> """
|
||||
你是一个专业的分镜图提示词优化专家。你的任务是将用户提供的简单描述优化为详细、专业、适合生成故事板分镜图的英文提示词。
|
||||
你是一个专业的分镜图提示词优化专家。你的任务是将用户提供的描述优化为详细、专业、适合生成故事板分镜图的英文提示词。
|
||||
|
||||
优化要求:
|
||||
1. 将中文描述翻译成流畅的英文,确保语义准确
|
||||
2. 关注镜头构图、画面布局、视觉元素(如:composition, framing, visual hierarchy等)
|
||||
3. 适合生成专业分镜图风格,强调构图和画面元素,包含清晰的场景描述和视觉细节
|
||||
4. 确保提示词清晰描述每个镜头的关键视觉元素和构图方式
|
||||
5. 使用专业的电影分镜术语(如:establishing shot, medium shot, close-up, wide shot, over-the-shoulder等)
|
||||
6. 添加画面细节描述:场景环境、人物/物体的位置、光线、氛围等
|
||||
7. 如果原始提示词已经是英文,直接优化,保持语言一致
|
||||
8. 输出优化后的提示词,不要添加额外说明、引号或其他格式标记
|
||||
9. 优化后的提示词应该直接可用,长度控制在合理范围内(200-500词)
|
||||
10. 参考格式:"(scene description), (shot type), (composition details), (visual elements), (lighting and atmosphere), professional storyboard style, cinematic framing"
|
||||
核心优化策略:
|
||||
1. 语言处理:
|
||||
- 如果输入是中文,翻译成流畅、地道的英文
|
||||
- 如果输入是英文,直接优化并增强表达
|
||||
- 确保语义准确,不丢失原始意图
|
||||
|
||||
2. 分镜图重点:
|
||||
- 镜头构图:composition, framing, visual hierarchy, rule of thirds
|
||||
- 画面布局:subject placement, background elements, foreground details
|
||||
- 视觉元素:key visual elements, focal points, visual storytelling
|
||||
- 场景描述: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 -> """
|
||||
你是一个专业的提示词优化专家。请将用户提供的简单描述优化为详细、专业的英文提示词。
|
||||
你是一个专业的AI提示词优化专家。请将用户提供的简单描述优化为详细、专业的英文提示词。
|
||||
|
||||
优化要求:
|
||||
1. 将中文描述翻译成流畅的英文,如果已经是英文则直接优化
|
||||
2. 添加必要的视觉细节和描述,使提示词更加具体和专业
|
||||
3. 保持原始意图不变,只优化表达方式
|
||||
4. 输出优化后的提示词,不要添加额外说明、引号或其他格式标记
|
||||
5. 优化后的提示词应该直接可用,长度控制在合理范围内
|
||||
1. 语言处理:将中文描述翻译成流畅的英文,如果已经是英文则直接优化
|
||||
2. 细节增强:添加必要的视觉细节和描述,使提示词更加具体和专业
|
||||
3. 保持意图:保持原始意图不变,只优化表达方式
|
||||
4. 专业术语:使用相关领域的专业术语和词汇
|
||||
5. 输出格式:只输出优化后的提示词,不要添加任何说明、引号、标记或额外文字
|
||||
6. 长度控制:优化后的提示词应该直接可用,长度控制在合理范围内
|
||||
""";
|
||||
};
|
||||
}
|
||||
|
||||
@@ -4,6 +4,16 @@ spring.datasource.username=root
|
||||
spring.datasource.password=177615
|
||||
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配置
|
||||
spring.jpa.hibernate.ddl-auto=update
|
||||
spring.jpa.show-sql=true
|
||||
@@ -12,6 +22,19 @@ spring.jpa.properties.hibernate.format_sql=true
|
||||
|
||||
# 服务器配置
|
||||
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
|
||||
@@ -52,3 +75,10 @@ alipay.charset=UTF-8
|
||||
alipay.sign-type=RSA2
|
||||
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
|
||||
|
||||
# 视频处理配置
|
||||
# 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
|
||||
|
||||
@@ -7,12 +7,12 @@ spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
|
||||
spring.datasource.username=${DB_USERNAME}
|
||||
spring.datasource.password=${DB_PASSWORD}
|
||||
|
||||
# 数据库连接池配置 (生产环境)
|
||||
spring.datasource.hikari.maximum-pool-size=50
|
||||
spring.datasource.hikari.minimum-idle=10
|
||||
# 数据库连接池配置 (生产环境 - 支持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=20000
|
||||
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
|
||||
@@ -28,6 +28,14 @@ spring.sql.init.mode=never
|
||||
# Thymeleaf 可启用缓存
|
||||
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.private-key=${ALIPAY_PRIVATE_KEY}
|
||||
@@ -38,7 +46,6 @@ alipay.sign-type=RSA2
|
||||
alipay.notify-url=${ALIPAY_NOTIFY_URL}
|
||||
alipay.return-url=${ALIPAY_RETURN_URL}
|
||||
|
||||
|
||||
# JWT配置 - 使用环境变量
|
||||
jwt.secret=${JWT_SECRET}
|
||||
jwt.expiration=${JWT_EXPIRATION:604800000}
|
||||
@@ -53,6 +60,13 @@ tencent.ses.from-name=AIGC平台
|
||||
# 如果未配置或为0,将使用开发模式(仅记录日志)
|
||||
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.com.example.demo=INFO
|
||||
@@ -60,6 +74,20 @@ logging.level.org.springframework.security=WARN
|
||||
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
|
||||
|
||||
# 视频处理配置
|
||||
# 临时文件目录(相对路径:基于应用运行目录,或绝对路径)
|
||||
# 生产环境建议使用绝对路径,如:/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}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -36,3 +36,4 @@ CREATE TABLE IF NOT EXISTS task_queue (
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -35,3 +35,4 @@ CREATE TABLE IF NOT EXISTS points_freeze_records (
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -38,3 +38,4 @@ CREATE TABLE task_status (
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -582,5 +582,6 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -498,5 +498,6 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -537,5 +537,6 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user