feat(14-05): integrate cache into SRTProcessor
- Add enable_cache parameter to SRTProcessor.__init__() - Create SemanticCache instance when semantic segmentation is enabled - Pass cache to UnifiedSegmentationStrategy through SemanticSegmentationEngine - Add logging for cache status (enabled/disabled) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -49,7 +49,8 @@ class SRTProcessor(BaseProcessor):
|
||||
self,
|
||||
state_manager: Optional[WorkflowStateManager] = None,
|
||||
enable_correction: bool = True,
|
||||
enable_semantic_segmentation: bool = False
|
||||
enable_semantic_segmentation: bool = False,
|
||||
enable_cache: bool = True
|
||||
):
|
||||
"""初始化 SRT 处理器
|
||||
|
||||
@@ -57,6 +58,7 @@ class SRTProcessor(BaseProcessor):
|
||||
state_manager: 状态管理器
|
||||
enable_correction: 是否启用 ASR 纠错(默认 True)
|
||||
enable_semantic_segmentation: 是否启用 LLM 语义分段(默认 False)
|
||||
enable_cache: 是否启用缓存(默认 True,仅在启用语义分段时有效)
|
||||
"""
|
||||
super().__init__(state_manager)
|
||||
self.enable_correction = enable_correction
|
||||
@@ -74,10 +76,19 @@ class SRTProcessor(BaseProcessor):
|
||||
# 创建 AI 客户端
|
||||
ai_client = SimpleAIClient()
|
||||
if ai_client.api_key:
|
||||
# 创建统一策略,传入 AI 客户端
|
||||
strategy = UnifiedSegmentationStrategy(ai_client=ai_client)
|
||||
# 初始化缓存
|
||||
cache = None
|
||||
if enable_cache:
|
||||
from kb_workflow.srt.cache import SemanticCache
|
||||
cache = SemanticCache()
|
||||
|
||||
# 创建统一策略,传入 AI 客户端和缓存
|
||||
strategy = UnifiedSegmentationStrategy(
|
||||
ai_client=ai_client,
|
||||
cache=cache
|
||||
)
|
||||
self.segmenter = SemanticSegmentationEngine(strategy=strategy)
|
||||
logger.info("Semantic segmentation enabled")
|
||||
logger.info(f"Semantic segmentation enabled (cache={'enabled' if cache else 'disabled'})")
|
||||
else:
|
||||
logger.info("AI API key not configured, using rule-based segmenter")
|
||||
self.segmenter = SemanticSegmenter()
|
||||
|
||||
Reference in New Issue
Block a user