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

6.1 KiB
Raw Blame History

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
kb_workflow/srt/semantic_engine.py
tests/test_semantic_engine.py
tests/conftest.py
true
VIDEO-01
VIDEO-02
VIDEO-03
truths artifacts key_links
系统能识别视频类型(知识类/故事类/访谈类/新闻类/vlog 等)
视频类型用于 Prompt 上下文,但不改变分段策略
类型识别失败时使用默认类型,不影响分段功能
path provides min_lines exports
kb_workflow/srt/semantic_engine.py SemanticSegmentationEngine 类和 Pydantic 模型 200
VideoSegment
SegmentationResult
SemanticSegmentationEngine
path provides min_lines
tests/test_semantic_engine.py 视频类型识别测试 50
path provides contains
tests/conftest.py 共享测试 fixtures mock_ai_client, sample_segments
from to via pattern
SemanticSegmentationEngine._build_prompt SegmentationResult.video_type Prompt 中包含视频类型信息 video_type.*prompt
from to via pattern
tests/test_semantic_engine.py kb_workflow/srt/semantic_engine.py 单元测试验证类型识别 test.*video.*type
实现视频类型识别功能,用于 Prompt 上下文

目的:让 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.md

Existing 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
视频类型识别 kb_workflow/srt/semantic_engine.py, tests/test_semantic_engine.py 定义 Pydantic 模型验证 LLM 输出: - VideoSegment: title (可选), content, start_index, end_index - SegmentationResult: video_type, segments[], actual_segment_count
视频类型识别:
- 从元数据推断类型(基于标题、标签、分类)
- 默认类型为"知识类"(最常见)
- 类型用于 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>

  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>
After completion, create `.planning/phases/13-llm/13-01-SUMMARY.md`