feat(kb-workflow): 添加严格失败判断逻辑
- kb-deep-analyzer: 新增判断逻辑,只有AI真正完成分析才算成功 - 失败条件: summary以'共'开头、topics为空、full_analysis为None - kb-workflow: 明确深度分析失败则整个流程失败 - 禁止降级处理或使用模板'假装成功'
This commit is contained in:
@@ -444,7 +444,7 @@ class DeepAnalyzer:
|
||||
result = self._analyze_chunks_concurrent(
|
||||
title, text, duration, segments, metadata,
|
||||
batch_size=batch_size,
|
||||
on_batch_complete=on_batch_complete
|
||||
on_segment_complete=on_batch_complete
|
||||
)
|
||||
elif duration < self.SHORT_VIDEO_THRESHOLD:
|
||||
print(f"[DeepAnalyzer] 使用轻量分析策略 (时长 < 10分钟)")
|
||||
@@ -671,6 +671,7 @@ class DeepAnalyzer:
|
||||
segments: list = None,
|
||||
metadata: Dict = None,
|
||||
max_concurrent: int = 3,
|
||||
batch_size: int = 3,
|
||||
on_segment_complete: callable = None
|
||||
) -> AnalysisResult:
|
||||
"""
|
||||
@@ -787,8 +788,8 @@ class DeepAnalyzer:
|
||||
|
||||
# 回调通知当前批次完成
|
||||
batch_summaries = [batch_results[i] for i in range(batch_idx, batch_end) if i in batch_results]
|
||||
if on_batch_complete:
|
||||
on_batch_complete(batch_summaries)
|
||||
if on_segment_complete:
|
||||
on_segment_complete(batch_summaries)
|
||||
|
||||
all_summaries.extend(batch_summaries)
|
||||
|
||||
@@ -1627,6 +1628,32 @@ def main():
|
||||
f.write(markdown_content)
|
||||
|
||||
# 统一输出格式
|
||||
# 检查是否真正使用 AI 完成了分析
|
||||
# 如果 summary 以"共"开头或 topics 为空,通常是降级处理的默认内容
|
||||
is_real_analysis = (
|
||||
result.summary and
|
||||
not result.summary.startswith("共") and
|
||||
len(result.main_topics) > 0 and
|
||||
len(result.key_insights) > 0 and
|
||||
result.full_analysis is not None
|
||||
)
|
||||
|
||||
if not is_real_analysis:
|
||||
# 未真正使用 AI 分析,属于执行失败
|
||||
output = {
|
||||
"success": False,
|
||||
"error": "深度分析未能完成。可能是 AI 调用失败或返回内容不完整。",
|
||||
"message": "执行失败:未使用正确的 AI 完整分析字幕内容",
|
||||
"stats": {
|
||||
"summary_length": len(result.summary) if result.summary else 0,
|
||||
"topics_count": len(result.main_topics),
|
||||
"insights_count": len(result.key_insights),
|
||||
"is_real_analysis": False
|
||||
}
|
||||
}
|
||||
print(json.dumps(output, ensure_ascii=False, indent=2))
|
||||
sys.exit(1)
|
||||
|
||||
output = {
|
||||
"success": True,
|
||||
"filename": Path(args.output).name,
|
||||
|
||||
@@ -100,6 +100,16 @@ echo "✅ 环境变量检查通过"
|
||||
2. 退出,不执行后续步骤
|
||||
3. 等待用户配置好环境变量后重新执行
|
||||
|
||||
## ⚠️ 严格失败处理原则
|
||||
|
||||
> **深度分析步骤必须成功,否则整个流程失败**
|
||||
|
||||
在执行工作流时,必须遵守以下原则:
|
||||
1. **深度分析不可跳过**:kb-deep-analyzer 是必须成功执行的步骤
|
||||
2. **失败即终止**:如果深度分析返回 `success: false`,必须立即停止并汇报失败
|
||||
3. **禁止降级处理**:不能使用预设模板或简单摘要来"假装成功"
|
||||
4. **每次执行都要使用 AI**:必须有真实的 AI API 调用记录
|
||||
|
||||
### 步骤 2: 链接解析
|
||||
|
||||
1. 获取目录路径:
|
||||
@@ -199,7 +209,12 @@ python3 kb_workflow.py --analyzed
|
||||
python3 /path/to/deep_analyzer.py --metadata [meta_path] --content [content_path] --output [analyzed_dir]/[filename].md
|
||||
```
|
||||
|
||||
6. 解析输出 JSON,获取分析结果
|
||||
6. 解析输出 JSON,检查 `success` 字段:
|
||||
|
||||
> ⚠️ **深度分析失败 = 整个流程失败**
|
||||
> - 如果 `success = true`:继续步骤 7(归档)
|
||||
> - 如果 `success = false`:**立即终止流程**,向用户汇报失败原因
|
||||
> - **严禁**继续执行后续步骤或使用降级内容"假装成功"
|
||||
|
||||
### 步骤 7: 归档
|
||||
|
||||
@@ -227,7 +242,7 @@ python3 kb_workflow.py --archive-file "[分析报告文件路径]"
|
||||
| 4 | kb-bilibili-content | `--id "BVxxx" --type subtitle-download` | `{p}_{id}.srt` | 如果没有字幕是正常的 |
|
||||
| 4 | kb-bilibili-content | `--id "BVxxx" --type video` | `{p}_{id}.mp4` | 如果需要下载视频 |
|
||||
| 5 | kb-whisper | `--input xxx.mp4 --model base` | `{p}_{id}.json`, `{p}_{id}.txt` | 仅当没有官方字幕时执行 |
|
||||
| 6 | kb-deep-analyzer | `--metadata x.meta.json --content x.json --output x.md` | `{p}_{id}.md` | |
|
||||
| 6 | kb-deep-analyzer | `--metadata x.meta.json --content x.json --output x.md` | `{p}_{id}.md` | **必须成功,否则整个流程失败** |
|
||||
|
||||
## 条件分支逻辑
|
||||
|
||||
@@ -244,8 +259,21 @@ python3 kb_workflow.py --archive-file "[分析报告文件路径]"
|
||||
└─────────────────────────────────────┘
|
||||
↓
|
||||
步骤6: 深度分析
|
||||
↓
|
||||
┌─────────────────────────────────────┐
|
||||
│ kb-deep-analyzer 执行结果 │
|
||||
├─────────────────────────────────────┤
|
||||
│ success = true → 步骤7(归档) │
|
||||
│ success = false → ❌ 整个流程失败 │
|
||||
└─────────────────────────────────────┘
|
||||
```
|
||||
|
||||
> ⚠️ **重要:深度分析失败则整个流程失败**
|
||||
> - 深度分析必须使用正确的 AI 模型(glm-4.7)完整分析字幕内容
|
||||
> - 如果 `kb-deep-analyzer` 返回 `success: false`,**必须汇报失败**,不能继续执行后续步骤
|
||||
> - 不能使用预设模板或降级内容来"假装成功"
|
||||
> - 失败时必须向用户报告具体的错误原因
|
||||
|
||||
> ⚠️ **重要**:没有找到官方字幕是**正常的**!很多视频没有自动生成的字幕。
|
||||
> - 如果 `has_subtitle = false`,继续执行 Whisper 步骤
|
||||
> - 如果 `has_subtitle = true`,跳过 Whisper 步骤,直接使用官方字幕
|
||||
|
||||
Reference in New Issue
Block a user