From 547c9ddd8438d184bd3bcb827127ffb94f1df431 Mon Sep 17 00:00:00 2001 From: iomgaa Date: Tue, 7 Jul 2026 01:41:50 -0400 Subject: [PATCH] =?UTF-8?q?feat(tree):=20TreeConfig=20=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=20dataclass?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.6 (1M context) --- app/tree/config.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 app/tree/config.py diff --git a/app/tree/config.py b/app/tree/config.py new file mode 100644 index 0000000..b43dac6 --- /dev/null +++ b/app/tree/config.py @@ -0,0 +1,42 @@ +"""建树模块配置。""" + +from __future__ import annotations + +from dataclasses import dataclass + + +@dataclass(frozen=True) +class TreeConfig: + """建树配置参数,字段对齐 config/default.yaml 的 tree: 段。 + + 参数: + l1_segment_duration: L1 段时长(秒)。 + l2_clip_duration: L2 clip 时长(秒)。 + l3_fps: L3 帧提取频率(帧/秒)。 + l2_representative_frames: L2 VLM 描述用的代表帧数。 + cache_dir: 树索引缓存目录。 + concurrency: asyncio Semaphore 上限。 + subtitle_inject: 建树时是否注入 SRT 字幕。 + srt_window_sec: 字幕匹配时间窗口(前后各 N 秒)。 + """ + + l1_segment_duration: float = 600.0 + l2_clip_duration: float = 60.0 + l3_fps: float = 0.5 + l2_representative_frames: int = 6 + cache_dir: str = "cache/trees" + concurrency: int = 16 + subtitle_inject: bool = True + srt_window_sec: float = 5.0 + + @classmethod + def from_dict(cls, d: dict) -> TreeConfig: + """从 YAML 解析后的 dict 构造,忽略未知字段。 + + 参数: + d: 配置字典。 + + 返回: + TreeConfig 实例。 + """ + return cls(**{k: v for k, v in d.items() if k in cls.__dataclass_fields__})