fix: auto-fix code issues (cron)
- 修复重复导入/字段 - 修复异常处理 - 修复PEP8格式问题 - 添加类型注解
This commit is contained in:
@@ -4,7 +4,6 @@ InsightFlow Knowledge Reasoning - Phase 5
|
||||
知识推理与问答增强模块
|
||||
"""
|
||||
|
||||
import json
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
@@ -83,7 +82,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:
|
||||
"""
|
||||
增强问答 - 结合图谱推理的问答
|
||||
@@ -140,7 +139,7 @@ class KnowledgeReasoner:
|
||||
return {"type": "factual", "entities": [], "intent": "general", "complexity": "simple"}
|
||||
|
||||
async def _causal_reasoning(
|
||||
self, query: str, project_context: dict, graph_data: dict
|
||||
self, query: str, project_context: dict, graph_data: dict,
|
||||
) -> ReasoningResult:
|
||||
"""因果推理 - 分析原因和影响"""
|
||||
|
||||
@@ -201,7 +200,7 @@ class KnowledgeReasoner:
|
||||
)
|
||||
|
||||
async def _comparative_reasoning(
|
||||
self, query: str, project_context: dict, graph_data: dict
|
||||
self, query: str, project_context: dict, graph_data: dict,
|
||||
) -> ReasoningResult:
|
||||
"""对比推理 - 比较实体间的异同"""
|
||||
|
||||
@@ -255,7 +254,7 @@ class KnowledgeReasoner:
|
||||
)
|
||||
|
||||
async def _temporal_reasoning(
|
||||
self, query: str, project_context: dict, graph_data: dict
|
||||
self, query: str, project_context: dict, graph_data: dict,
|
||||
) -> ReasoningResult:
|
||||
"""时序推理 - 分析时间线和演变"""
|
||||
|
||||
@@ -309,7 +308,7 @@ class KnowledgeReasoner:
|
||||
)
|
||||
|
||||
async def _associative_reasoning(
|
||||
self, query: str, project_context: dict, graph_data: dict
|
||||
self, query: str, project_context: dict, graph_data: dict,
|
||||
) -> ReasoningResult:
|
||||
"""关联推理 - 发现实体间的隐含关联"""
|
||||
|
||||
@@ -363,7 +362,7 @@ class KnowledgeReasoner:
|
||||
)
|
||||
|
||||
def find_inference_paths(
|
||||
self, start_entity: str, end_entity: str, graph_data: dict, max_depth: int = 3
|
||||
self, start_entity: str, end_entity: str, graph_data: dict, max_depth: int = 3,
|
||||
) -> list[InferencePath]:
|
||||
"""
|
||||
发现两个实体之间的推理路径
|
||||
@@ -384,7 +383,7 @@ class KnowledgeReasoner:
|
||||
adj[src].append({"target": tgt, "relation": r.get("type", "related"), "data": r})
|
||||
# 无向图也添加反向
|
||||
adj[tgt].append(
|
||||
{"target": src, "relation": r.get("type", "related"), "data": r, "reverse": True}
|
||||
{"target": src, "relation": r.get("type", "related"), "data": r, "reverse": True},
|
||||
)
|
||||
|
||||
# BFS 搜索路径
|
||||
@@ -405,7 +404,7 @@ class KnowledgeReasoner:
|
||||
end_entity=end_entity,
|
||||
path=path,
|
||||
strength=self._calculate_path_strength(path),
|
||||
)
|
||||
),
|
||||
)
|
||||
continue
|
||||
|
||||
@@ -420,7 +419,7 @@ class KnowledgeReasoner:
|
||||
"entity": next_entity,
|
||||
"relation": neighbor["relation"],
|
||||
"relation_data": neighbor.get("data", {}),
|
||||
}
|
||||
},
|
||||
]
|
||||
queue.append((next_entity, new_path))
|
||||
|
||||
@@ -450,7 +449,7 @@ class KnowledgeReasoner:
|
||||
return length_factor * confidence_factor
|
||||
|
||||
async def summarize_project(
|
||||
self, project_context: dict, graph_data: dict, summary_type: str = "comprehensive"
|
||||
self, project_context: dict, graph_data: dict, summary_type: str = "comprehensive",
|
||||
) -> dict:
|
||||
"""
|
||||
项目智能总结
|
||||
|
||||
Reference in New Issue
Block a user