This repository has been archived on 2026-08-07. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
kb-skills/.planning/phases/13-llm/13-01-PLAN.md
T

171 lines
6.1 KiB
Markdown
Raw 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.
---
phase: 13
plan: 01
type: tdd
wave: 1
depends_on: []
files_modified:
- kb_workflow/srt/semantic_engine.py
- tests/test_semantic_engine.py
- tests/conftest.py
autonomous: true
requirements:
- VIDEO-01
- VIDEO-02
- VIDEO-03
must_haves:
truths:
- "系统能识别视频类型(知识类/故事类/访谈类/新闻类/vlog 等)"
- "视频类型用于 Prompt 上下文,但不改变分段策略"
- "类型识别失败时使用默认类型,不影响分段功能"
artifacts:
- path: "kb_workflow/srt/semantic_engine.py"
provides: "SemanticSegmentationEngine 类和 Pydantic 模型"
min_lines: 200
exports: ["VideoSegment", "SegmentationResult", "SemanticSegmentationEngine"]
- path: "tests/test_semantic_engine.py"
provides: "视频类型识别测试"
min_lines: 50
- path: "tests/conftest.py"
provides: "共享测试 fixtures"
contains: "mock_ai_client, sample_segments"
key_links:
- from: "SemanticSegmentationEngine._build_prompt"
to: "SegmentationResult.video_type"
via: "Prompt 中包含视频类型信息"
pattern: "video_type.*prompt"
- from: "tests/test_semantic_engine.py"
to: "kb_workflow/srt/semantic_engine.py"
via: "单元测试验证类型识别"
pattern: "test.*video.*type"
---
<objective>
实现视频类型识别功能,用于 Prompt 上下文
目的:让 LLM 了解视频类型(知识类/故事类等)以优化分段质量,但不针对不同类型使用不同策略(统一 Prompt)
输出:VideoSegment 和 SegmentationResult Pydantic 模型,视频类型识别逻辑
</objective>
<execution_context>
@/home/starmen1265/.claude/get-shit-done/workflows/execute-plan.md
@/home/starmen1265/.claude/get-shit-done/templates/summary.md
</execution_context>
<context>
@.planning/phases/13-llm/13-CONTEXT.md
@.planning/phases/13-llm/13-RESEARCH.md
@.planning/ROADMAP.md
# Existing Code Patterns
From kb_workflow/srt/corrector.py:
```python
class ASRCorrector:
def __init__(self, ai_client: Optional[AIClientProtocol] = None):
self.ai_client = ai_client
# Lazy initialization pattern
```
From kb_workflow/deep_analyzer/__init__.py:
```python
class SimpleAIClient:
def generate(self, prompt: str, max_tokens: int = 16000, disable_reasoning: bool = None) -> str:
# Supports zhipu, openai, minimax providers
# disable_reasoning parameter for cost control
```
</context>
<feature>
<name>视频类型识别</name>
<files>kb_workflow/srt/semantic_engine.py, tests/test_semantic_engine.py</files>
<behavior>
定义 Pydantic 模型验证 LLM 输出:
- VideoSegment: title (可选), content, start_index, end_index
- SegmentationResult: video_type, segments[], actual_segment_count
视频类型识别:
- 从元数据推断类型(基于标题、标签、分类)
- 默认类型为"知识类"(最常见)
- 类型用于 Prompt 上下文,不改变分段策略
LLM 调用失败时:
- 返回默认 SegmentationResult(video_type="知识类", 使用规则分段)
</behavior>
<implementation>
在 semantic_engine.py 中:
1. 定义 VideoSegment 和 SegmentationResult Pydantic 模型
2. 实现 _infer_video_type() 方法,从元数据推断类型
3. 在 _build_prompt() 中包含视频类型信息
4. 实现 LazyAIClient 初始化模式(参考 ASRCorrector)
测试文件:
1. test_video_type_detection() - 验证类型推断
2. test_video_type_in_prompt() - 验证类型出现在 Prompt 中
3. test_video_type_fallback() - 验证默认类型处理
</implementation>
</feature>
<tasks>
<task type="auto" tdd="true">
<name>Task 1: 创建 Pydantic 模型和类型推断</name>
<files>kb_workflow/srt/semantic_engine.py, tests/test_semantic_engine.py</files>
<behavior>
RED 阶段 - 测试预期行为:
- test_video_type_detection: 从元数据正确推断视频类型
- test_video_type_in_prompt: Prompt 包含视频类型信息
- test_video_type_fallback: 元数据缺失时使用默认类型
GREEN 阶段 - 实现功能:
- 定义 VideoSegment Pydantic 模型(title 可选,content 必填)
- 定义 SegmentationResult Pydantic 模型(video_type, segments 列表)
- 实现 _infer_video_type() 从 metadata 推断类型
- 实现 _build_prompt() 包含类型信息
REFACTOR 阶段 - 优化代码:
- 提取视频类型映射常量
- 优化类型推断逻辑
</behavior>
<action>
创建 semantic_engine.py,实现:
1. VideoSegment(title: Optional[str], content: str, start_index: int, end_index: int)
2. SegmentationResult(video_type: str, segments: List[VideoSegment], actual_segment_count: int)
3. _infer_video_type(metadata: dict) -> str 方法
4. _build_prompt(content: str, metadata: dict) -> str 方法(包含类型信息)
参考 ASRCorrector 的 LazyAIClient 初始化模式,但暂时不实现完整 LLM 调用(留待后续计划)
测试覆盖类型推断的各种场景:
- 从 title 包含"教程""课程"推断为"知识类"
- 从 category 包含"影视"推断为"故事类"
- 元数据为空时返回"知识类"(默认)
</action>
<verify>
<automated>pytest tests/test_semantic_engine.py::test_video_type_detection -x</automated>
</verify>
<done>
- Pydantic 模型定义完成,包含字段验证
- _infer_video_type() 能从元数据正确推断类型
- _build_prompt() 包含视频类型上下文
- 三个测试全部通过
</done>
</task>
</tasks>
<verification>
- pytest tests/test_semantic_engine.py -v 全部通过
- 代码符合 PEP 8 规范
- Pydantic 模型通过类型检查
</verification>
<success_criteria>
1. VideoSegment 和 SegmentationResult Pydantic 模型定义完成
2. _infer_video_type() 能正确推断视频类型
3. _build_prompt() 包含视频类型信息
4. 所有测试通过(test_video_type_detection, test_video_type_in_prompt, test_video_type_fallback)
</success_criteria>
<output>
After completion, create `.planning/phases/13-llm/13-01-SUMMARY.md`
</output>