Commit Graph

11 Commits

Author SHA1 Message Date
starmen1265 a1076dfcb4 feat(semantic): 添加广告植入内容识别功能
PR Test / lint (pull_request) Successful in 1s
在LLM语义分段Prompt中添加广告识别要求:

【分段要求】新增:
- 第7条:要求识别UP主广告植入内容
- 明确常见的电商平台推广关键词(转转、京东、得物、淘宝、拼多多等)
- 要求将广告内容单独分段,title设为"广告"或"推广"

【注意事项】新增:
- 添加广告识别提示,列出常见广告植入特征:
  * 突然话题转换到商品推荐
  * 电商相关词汇(回收、卖、优惠、下单等)
  * 具体品牌名称提及
  * 推销语气的风格变化
  * 与视频主题无关的内容

测试结果:
- 转转广告被正确识别为独立段落,标题为"广告"
- 广告内容不再混入正常内容段落中

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-24 00:36:20 +08:00
starmen1265 bbc8816d16 refactor(semantic): 移除语义分段降级功能,LLM失败直接报错
PR Test / lint (pull_request) Successful in 1s
主要变更:
- 移除 _segment_single_chunk() 中的降级逻辑,失败直接抛出 RuntimeError
- 移除 _segment_multiple_chunks() 中的降级逻辑,分块失败直接抛出异常
- 移除 segment() 中 AI 客户端不可用时的降级逻辑,直接报错
- _fallback_chunk() 方法已弃用,调用时直接抛出异常
- VideoSegment 标题长度限制从 15 字增加到 30 字
- 将 ValidationError 从不可恢复错误改为可恢复错误,允许重试
- 更新相关 docstring,将 fallback_segmenter 标记为已弃用

现在 LLM 语义分段失败时会抛出明确的 RuntimeError 异常,
包含失败原因(HTTP 错误、JSON 解析错误等)。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-24 00:20:28 +08:00
starmen1265 1eacc23c99 fix(14-04): correct Segment constructor parameter
Change Segment(index=1, ...) to Segment(id=1, ...) to match
the actual Segment class definition in parser.py.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-23 22:43:10 +08:00
starmen1265 faff7903a4 feat(14-04): 实现长文本分块处理方法
- 添加 _split_into_chunks() 方法,按句子边界分割长文本(5000字符阈值)
- 添加 _merge_segment_results() 方法,合并分块结果并修正索引
- 添加 _segment_single_chunk() 方法,处理单个文本块
- 添加 _segment_multiple_chunks() 方法,处理多个文本块(分块)
- 添加 _fallback_chunk() 方法,用于单个分块失败时的降级处理
- 修改 segment() 方法,添加分块判断逻辑(len(content) > 5000)

遵守用户决策:
- 分块阈值: 5000 字符
- 按句子边界分割(。!?\n)
- 直接拼接各分块结果
- start_index/end_index 相对于原文

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-23 22:40:31 +08:00
starmen1265 87a1740cd3 feat(14-05): integrate cache into UnifiedSegmentationStrategy
- Add cache parameter to UnifiedSegmentationStrategy.__init__()
- Add cache logic to segment() method (check before LLM, save after)
- Pass cache parameter through SemanticSegmentationEngine.__init__()
- Implement missing chunking methods (_segment_single_chunk, _segment_multiple_chunks, etc.)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-23 22:40:24 +08:00
starmen1265 5c32cfdf69 test(14-01): 实现 LLM 调用的可恢复错误检测和重试逻辑
- 添加 _is_recoverable_error() 静态方法判断错误类型
- 可恢复错误: ConnectionError, Timeout, HTTPError (429/500/502/503/504)
- 不可恢复错误: 其他 HTTPError (4xx), ValidationError
- 重试逻辑: 仅对可恢复错误重试 1 次,立即重试(无延迟)
- 改进日志记录: 重试用 info 级别,降级用 warning 级别
- 降级时记录具体错误类型和消息

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-23 22:38:28 +08:00
starmen1265 ef4a660faa feat(13-07): integrate SemanticSegmentationEngine into SRTProcessor
- 添加 enable_semantic_segmentation 参数到 SRTProcessor.__init__
- 启用时使用 SemanticSegmentationEngine,禁用时使用 SemanticSegmenter
- AI 不可用时自动降级到规则分段
- 更新 _generate_markdown() 支持带标题的 VideoSegment 输出
- 调整步骤顺序:先加载元数据,再进行语义分段
- 更新 UnifiedSegmentationStrategy.segment() 返回 List[VideoSegment]
- 添加代理方法到 SemanticSegmentationEngine 以保持向后兼容
- 创建全面的集成测试(9 个测试用例)
- 更新现有语义引擎测试以适配新 API

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-22 00:32:14 +08:00
starmen1265 0d8ed1f22f feat(13-06): implement extensible strategy architecture for segmentation
- Define SegmentationStrategy Protocol interface (Plan 13-06)
- Implement UnifiedSegmentationStrategy with unified approach for all video types
- Update SemanticSegmentationEngine to use strategy pattern
- Add comprehensive tests for strategy extensibility (STRAT-01, STRAT-02, STRAT-03)

Key changes:
- SegmentationStrategy Protocol defines the strategy interface
- UnifiedSegmentationStrategy implements unified approach (per user decision)
- SemanticSegmentationEngine now uses strategy injection pattern
- Tests verify strategy protocol, unified strategy, custom strategy injection, and extensibility

The architecture supports future extension (e.g., knowledge-type specific strategies)
while Phase 13 uses the unified strategy approach.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-22 00:29:54 +08:00
starmen1265 759503f48a feat(13-05): 实现中文句边界检测指令
更新 SEGMENTATION_PROMPT,增强句边界检测:
- 列举所有中文句末标点(。?!……)
- 强调「自然停顿处」和「语义停顿」
- 说明「不仅依赖标点符号」

添加测试验证句边界检测效果:
- test_chinese_sentence_boundary_punctuations
- test_prompt_emphasizes_semantic_pause
- test_prompt_not_only_punctuation
- test_sentence_boundary_in_segmentation

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-22 00:25:40 +08:00
starmen1265 00319f523f feat(13-01): implement video type detection and Pydantic models
- 创建 SemanticSegmentationEngine 类
- 实现 VideoSegment 和 SegmentationResult Pydantic 模型
  - VideoSegment: title(可选), content(必填), start_index, end_index
  - SegmentationResult: video_type, segments[], actual_segment_count
  - 添加标题长度验证器(5-15字)
- 实现 _infer_video_type() 方法
  - 从元数据推断视频类型(知识类/故事类/访谈类/新闻类/vlog)
  - 支持从 title, category, tags 推断
  - 默认类型为"知识类"
- 实现 _build_prompt() 方法
  - 包含视频类型信息
  - 包含完整的分段要求(数量控制、句边界保护、标题生成等)
  - 包含 JSON 输出格式规范
- 添加 extract_json_from_llm_response() 工具函数
- 添加 AIClientProtocol 协议定义
- 添加 deferred-items.md 记录超出范围的测试

所有计划 13-01 测试通过(10个测试)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-22 00:25:21 +08:00
starmen1265 8c2b3e079a feat(13-04): 实现主题标题生成功能
实现 VideoSegment.title 字段和验证,Prompt 中的标题生成指令。

功能:
- VideoSegment.title: Optional[str] 字段
- @field_validator 验证标题长度(不超过 15 字)
- SEGMENTATION_PROMPT 包含标题生成指令
- LLM 自主判断是否需要标题(主题/章节有标题,论点/观点无标题)
- 测试验证标题生成和省略

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-22 00:24:58 +08:00