refactor: integrate kb-deep-analyzer as kb_workflow.deep_analyzer package

- Move kb-deep-analyzer/deep_analyzer.py to kb_workflow/deep_analyzer/__init__.py
- Update analyze.py to import from kb_workflow.deep_analyzer directly
- Remove sys.path manipulation for external package
- DeepAnalyzer, SimpleAIClient, generate_frontmatter now available as:
  from kb_workflow.deep_analyzer import DeepAnalyzer, SimpleAIClient, generate_frontmatter

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-17 15:28:58 +08:00
parent 14b3a3c4c1
commit 9fc52ffbdd
2 changed files with 651 additions and 18 deletions
+1 -18
View File
@@ -9,7 +9,6 @@ from __future__ import annotations
import json
import logging
import os
import sys
from pathlib import Path
from typing import Optional, Dict, Any
@@ -17,12 +16,10 @@ from kb_workflow.pipeline.config import get_settings
from kb_workflow.pipeline.schemas import AnalyzeInput, AnalyzeOutput
from kb_workflow.pipeline.state import WorkflowStateManager
from kb_workflow.pipeline.processors.base import BaseProcessor
from kb_workflow.deep_analyzer import DeepAnalyzer, SimpleAIClient, generate_frontmatter
logger = logging.getLogger(__name__)
# Flag to ensure sys.path is only modified once for kb-deep-analyzer
_deep_analyzer_path_added = False
class AnalyzeProcessor(BaseProcessor):
"""Analyze 处理器 - AI 深度内容分析
@@ -199,16 +196,6 @@ class AnalyzeProcessor(BaseProcessor):
Returns:
AnalysisResult 对象
"""
# Lazy import with delayed sys.path modification for external kb-deep-analyzer
global _deep_analyzer_path_added
if not _deep_analyzer_path_added:
_kb_deep_analyzer_path = Path(__file__).parent.parent.parent.parent / "kb-deep-analyzer"
if str(_kb_deep_analyzer_path) not in sys.path:
sys.path.insert(0, str(_kb_deep_analyzer_path))
_deep_analyzer_path_added = True
from deep_analyzer import DeepAnalyzer, SimpleAIClient
# 初始化 AI 客户端
ai_client = self._create_ai_client()
@@ -224,8 +211,6 @@ class AnalyzeProcessor(BaseProcessor):
Returns:
SimpleAIClient 实例
"""
from deep_analyzer import SimpleAIClient
# 从环境变量获取配置
api_key = os.environ.get("AI_API_KEY", "")
provider = os.environ.get("AI_PROVIDER", "")
@@ -307,8 +292,6 @@ class AnalyzeProcessor(BaseProcessor):
result: AnalysisResult 对象
content_type: 内容类型
"""
from deep_analyzer import generate_frontmatter
# 标准化元数据(扁平化嵌套结构)
normalized_metadata = self._normalize_metadata(metadata)