fix: auto-fix code issues (cron)

- 修复重复导入/字段
- 修复异常处理
- 修复PEP8格式问题
- 添加类型注解
This commit is contained in:
OpenClaw Bot
2026-02-27 18:09:24 +08:00
parent 646b64daf7
commit 17bda3dbce
38 changed files with 1993 additions and 1972 deletions

View File

@@ -4,13 +4,13 @@ InsightFlow Knowledge Reasoning - Phase 5
知识推理与问答增强模块
"""
import os
import json
import httpx
from typing import List, Dict
import os
from dataclasses import dataclass
from enum import Enum
import httpx
KIMI_API_KEY = os.getenv("KIMI_API_KEY", "")
KIMI_BASE_URL = os.getenv("KIMI_BASE_URL", "https://api.kimi.com/coding")
@@ -32,9 +32,9 @@ class ReasoningResult:
answer: str
reasoning_type: ReasoningType
confidence: float
evidence: List[Dict] # 支撑证据
related_entities: List[str] # 相关实体
gaps: List[str] # 知识缺口
evidence: list[dict] # 支撑证据
related_entities: list[str] # 相关实体
gaps: list[str] # 知识缺口
@dataclass
@@ -43,7 +43,7 @@ class InferencePath:
start_entity: str
end_entity: str
path: List[Dict] # 路径上的节点和关系
path: list[dict] # 路径上的节点和关系
strength: float # 路径强度
@@ -71,7 +71,7 @@ class KnowledgeReasoner:
return result["choices"][0]["message"]["content"]
async def enhanced_qa(
self, query: str, project_context: Dict, graph_data: Dict, reasoning_depth: str = "medium"
self, query: str, project_context: dict, graph_data: dict, reasoning_depth: str = "medium"
) -> ReasoningResult:
"""
增强问答 - 结合图谱推理的问答
@@ -95,7 +95,7 @@ class KnowledgeReasoner:
else:
return await self._associative_reasoning(query, project_context, graph_data)
async def _analyze_question(self, query: str) -> Dict:
async def _analyze_question(self, query: str) -> dict:
"""分析问题类型和意图"""
prompt = f"""分析以下问题的类型和意图:
@@ -129,7 +129,7 @@ class KnowledgeReasoner:
return {"type": "factual", "entities": [], "intent": "general", "complexity": "simple"}
async def _causal_reasoning(self, query: str, project_context: Dict, graph_data: Dict) -> ReasoningResult:
async def _causal_reasoning(self, query: str, project_context: dict, graph_data: dict) -> ReasoningResult:
"""因果推理 - 分析原因和影响"""
# 构建因果分析提示
@@ -190,7 +190,7 @@ class KnowledgeReasoner:
gaps=["无法完成因果推理"],
)
async def _comparative_reasoning(self, query: str, project_context: Dict, graph_data: Dict) -> ReasoningResult:
async def _comparative_reasoning(self, query: str, project_context: dict, graph_data: dict) -> ReasoningResult:
"""对比推理 - 比较实体间的异同"""
prompt = f"""基于以下知识图谱进行对比分析:
@@ -244,7 +244,7 @@ class KnowledgeReasoner:
gaps=[],
)
async def _temporal_reasoning(self, query: str, project_context: Dict, graph_data: Dict) -> ReasoningResult:
async def _temporal_reasoning(self, query: str, project_context: dict, graph_data: dict) -> ReasoningResult:
"""时序推理 - 分析时间线和演变"""
prompt = f"""基于以下知识图谱进行时序分析:
@@ -298,7 +298,7 @@ class KnowledgeReasoner:
gaps=[],
)
async def _associative_reasoning(self, query: str, project_context: Dict, graph_data: Dict) -> ReasoningResult:
async def _associative_reasoning(self, query: str, project_context: dict, graph_data: dict) -> ReasoningResult:
"""关联推理 - 发现实体间的隐含关联"""
prompt = f"""基于以下知识图谱进行关联分析:
@@ -353,8 +353,8 @@ class KnowledgeReasoner:
)
def find_inference_paths(
self, start_entity: str, end_entity: str, graph_data: Dict, max_depth: int = 3
) -> List[InferencePath]:
self, start_entity: str, end_entity: str, graph_data: dict, max_depth: int = 3
) -> list[InferencePath]:
"""
发现两个实体之间的推理路径
@@ -416,7 +416,7 @@ class KnowledgeReasoner:
paths.sort(key=lambda p: p.strength, reverse=True)
return paths
def _calculate_path_strength(self, path: List[Dict]) -> float:
def _calculate_path_strength(self, path: list[dict]) -> float:
"""计算路径强度"""
if len(path) < 2:
return 0.0
@@ -438,8 +438,8 @@ class KnowledgeReasoner:
return length_factor * confidence_factor
async def summarize_project(
self, project_context: Dict, graph_data: Dict, summary_type: str = "comprehensive"
) -> Dict:
self, project_context: dict, graph_data: dict, summary_type: str = "comprehensive"
) -> dict:
"""
项目智能总结