6.1 KiB
6.1 KiB
phase, plan, type, wave, depends_on, files_modified, autonomous, requirements, must_haves
| phase | plan | type | wave | depends_on | files_modified | autonomous | requirements | must_haves | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 13 | 01 | tdd | 1 |
|
true |
|
|
目的:让 LLM 了解视频类型(知识类/故事类等)以优化分段质量,但不针对不同类型使用不同策略(统一 Prompt) 输出:VideoSegment 和 SegmentationResult Pydantic 模型,视频类型识别逻辑
<execution_context> @/home/starmen1265/.claude/get-shit-done/workflows/execute-plan.md @/home/starmen1265/.claude/get-shit-done/templates/summary.md </execution_context>
@.planning/phases/13-llm/13-CONTEXT.md @.planning/phases/13-llm/13-RESEARCH.md @.planning/ROADMAP.mdExisting Code Patterns
From kb_workflow/srt/corrector.py:
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:
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
视频类型识别:
- 从元数据推断类型(基于标题、标签、分类)
- 默认类型为"知识类"(最常见)
- 类型用于 Prompt 上下文,不改变分段策略
LLM 调用失败时:
- 返回默认 SegmentationResult(video_type="知识类", 使用规则分段)
在 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() - 验证默认类型处理
Task 1: 创建 Pydantic 模型和类型推断
kb_workflow/srt/semantic_engine.py, tests/test_semantic_engine.py
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>
- pytest tests/test_semantic_engine.py -v 全部通过
- 代码符合 PEP 8 规范
- Pydantic 模型通过类型检查
<success_criteria>
- VideoSegment 和 SegmentationResult Pydantic 模型定义完成
- _infer_video_type() 能正确推断视频类型
- _build_prompt() 包含视频类型信息
- 所有测试通过(test_video_type_detection, test_video_type_in_prompt, test_video_type_fallback) </success_criteria>