pipeline-app/docs/model-selection-integration.md
yumoqing 8408570ed7 feat: add multi-model cost estimation and selection after storyboard
- Add cost_estimator.py: supports Wan 2.2, Wan 2.7, Vidu 2.0 pricing
- Add model_selector.py: creates human_task for customer model selection
- Update ktv_adapter.py: add model_selecting step, modify scene_video_generating to use selected model
- Add integration guide: docs/model-selection-integration.md
2026-06-25 18:51:29 +08:00

110 lines
3.3 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 模型选择功能集成指南
## 功能概述
在分镜生成storyboard_generating后插入模型选择步骤允许客户根据费用预估选择视频生成模型。
## 已完成的代码修改
### 1. 新增模块
- `app/cost_estimator.py` - 多模型费用预估Wan 2.2, Wan 2.7, Vidu 2.0
- `app/model_selector.py` - 模型选择交互处理器
### 2. 修改模块
- `app/ktv_adapter.py` - 添加 model_selecting handler修改 scene_video_generating 支持多模型
## 产线定义更新步骤
### 步骤 1: 插入 model_selecting 步骤
在数据库的 `pipeline_steps` 表中,在 `storyboard_generating` (step_order=13) 之后插入新步骤:
```sql
-- 查找当前 storyboard_generating 的 step_order
SELECT step_order FROM pipeline_steps
WHERE pipeline_id = 'ktv_pipeline' AND step_name = 'storyboard_generating';
-- 假设结果是 13需要将后续步骤的 step_order +1
UPDATE pipeline_steps
SET step_order = step_order + 1
WHERE pipeline_id = 'ktv_pipeline' AND step_order > 13;
-- 插入 model_selecting 步骤
INSERT INTO pipeline_steps (
pipeline_id, step_name, step_type, step_order,
description, handler_function, step_config
) VALUES (
'ktv_pipeline',
'model_selecting',
'interactive',
14,
'客户根据费用预估选择视频生成模型',
'handle_model_selecting',
'{"deps": ["storyboard_generating"], "timeout_hours": 24}'
);
-- 更新 scene_video_generating 的依赖
UPDATE pipeline_steps
SET step_config = JSON_SET(
step_config,
'$.deps',
JSON_ARRAY('model_selecting', 'character_image_generating')
)
WHERE pipeline_id = 'ktv_pipeline' AND step_name = 'scene_video_generating';
```
### 步骤 2: 验证步骤顺序
```sql
SELECT step_name, step_order, step_type
FROM pipeline_steps
WHERE pipeline_id = 'ktv_pipeline'
ORDER BY step_order;
```
预期结果:
```
1 - audio_preparing
2 - demucs_separating
3 - lyric_calibrating
...
13 - storyboard_generating
14 - model_selecting <-- 新增
15 - scene_video_generating <-- 更新依赖
16 - scene_video_evaluating
...
```
## 费用预估模型配置
当前支持的模型(在 `cost_estimator.py` 中定义):
| 模型 | 质量评分 | 生成速度 | 价格/帧 | 特点 |
|------|---------|---------|---------|------|
| Wan 2.2 | 7.5/10 | fast | $0.002 | 本地GPU性价比高 |
| Wan 2.7 | 8.5/10 | medium | $0.003 | 本地GPU质量更好 |
| Vidu 2.0 | 9.0/10 | slow | $0.008 | 云端API最高质量 |
## 工作流程
1. **分镜生成完成** → 计算总帧数和时长
2. **生成费用预估** → 为每个模型计算成本
3. **创建 human_task** → 显示选项给客户
4. **客户选择模型** → 通过前端界面选择
5. **任务继续执行** → scene_video_generating 使用选中的模型
## 注意事项
1. **Vidu 2.0 暂未实现** - 当前选择 Vidu 2.0 会降级到 Wan 2.2,需要后续集成 Vidu API
2. **超时设置** - model_selecting 步骤默认 24 小时超时,可在 step_config 中调整
3. **默认选择** - 如果客户未选择,默认使用 Wan 2.2(最便宜选项)
## 验证清单
- [ ] 数据库步骤已更新
- [ ] 代码已提交 (commit: model-selection)
- [ ] 测试产线执行到 storyboard_generating
- [ ] 验证 human_task 创建成功
- [ ] 验证客户选择后任务继续执行
- [ ] 验证 scene_video_generating 使用了正确的模型