Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 7 additions & 30 deletions backend/app/api/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,17 +283,6 @@ def build_graph():
try:
logger.info("=== 开始构建图谱 ===")

# 检查配置
errors = []
if not Config.ZEP_API_KEY:
errors.append(t('api.zepApiKeyMissing'))
if errors:
logger.error(f"配置错误: {errors}")
return jsonify({
"success": False,
"error": t('api.configError', details="; ".join(errors))
}), 500

# 解析请求
data = request.get_json() or {}
project_id = data.get('project_id')
Expand Down Expand Up @@ -387,8 +376,8 @@ def build_task():
)

# 创建图谱构建服务
builder = GraphBuilderService(api_key=Config.ZEP_API_KEY)
builder = GraphBuilderService()

# 分块
task_manager.update_task(
task_id,
Expand Down Expand Up @@ -572,20 +561,14 @@ def get_graph_data(graph_id: str):
获取图谱数据(节点和边)
"""
try:
if not Config.ZEP_API_KEY:
return jsonify({
"success": False,
"error": t('api.zepApiKeyMissing')
}), 500

builder = GraphBuilderService(api_key=Config.ZEP_API_KEY)
builder = GraphBuilderService()
graph_data = builder.get_graph_data(graph_id)

return jsonify({
"success": True,
"data": graph_data
})

except Exception as e:
return jsonify({
"success": False,
Expand All @@ -597,16 +580,10 @@ def get_graph_data(graph_id: str):
@graph_bp.route('/delete/<graph_id>', methods=['DELETE'])
def delete_graph(graph_id: str):
"""
删除Zep图谱
删除本地图谱
"""
try:
if not Config.ZEP_API_KEY:
return jsonify({
"success": False,
"error": t('api.zepApiKeyMissing')
}), 500

builder = GraphBuilderService(api_key=Config.ZEP_API_KEY)
builder = GraphBuilderService()
builder.delete_graph(graph_id)

return jsonify({
Expand Down
24 changes: 3 additions & 21 deletions backend/app/api/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,12 @@ def get_graph_entities(graph_id: str):
enrich: 是否获取相关边信息(默认true)
"""
try:
if not Config.ZEP_API_KEY:
return jsonify({
"success": False,
"error": t('api.zepApiKeyMissing')
}), 500

entity_types_str = request.args.get('entity_types', '')
entity_types = [t.strip() for t in entity_types_str.split(',') if t.strip()] if entity_types_str else None
enrich = request.args.get('enrich', 'true').lower() == 'true'

logger.info(f"获取图谱实体: graph_id={graph_id}, entity_types={entity_types}, enrich={enrich}")

reader = ZepEntityReader()
result = reader.filter_defined_entities(
graph_id=graph_id,
Expand All @@ -94,12 +88,6 @@ def get_graph_entities(graph_id: str):
def get_entity_detail(graph_id: str, entity_uuid: str):
"""获取单个实体的详细信息"""
try:
if not Config.ZEP_API_KEY:
return jsonify({
"success": False,
"error": t('api.zepApiKeyMissing')
}), 500

reader = ZepEntityReader()
entity = reader.get_entity_with_context(graph_id, entity_uuid)

Expand Down Expand Up @@ -127,14 +115,8 @@ def get_entity_detail(graph_id: str, entity_uuid: str):
def get_entities_by_type(graph_id: str, entity_type: str):
"""获取指定类型的所有实体"""
try:
if not Config.ZEP_API_KEY:
return jsonify({
"success": False,
"error": t('api.zepApiKeyMissing')
}), 500

enrich = request.args.get('enrich', 'true').lower() == 'true'

reader = ZepEntityReader()
entities = reader.get_entities_by_type(
graph_id=graph_id,
Expand Down
8 changes: 4 additions & 4 deletions backend/app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class Config:
LLM_BASE_URL = os.environ.get('LLM_BASE_URL', 'https://api.openai.com/v1')
LLM_MODEL_NAME = os.environ.get('LLM_MODEL_NAME', 'gpt-4o-mini')

# Zep配置
ZEP_API_KEY = os.environ.get('ZEP_API_KEY')
# 本地图谱存储目录
GRAPH_STORAGE_DIR = os.path.join(os.path.dirname(__file__), '../uploads/graphs')

# 文件上传配置
MAX_CONTENT_LENGTH = 50 * 1024 * 1024 # 50MB
Expand Down Expand Up @@ -69,7 +69,7 @@ def validate(cls):
errors = []
if not cls.LLM_API_KEY:
errors.append("LLM_API_KEY 未配置")
if not cls.ZEP_API_KEY:
errors.append("ZEP_API_KEY 未配置")
# 确保图谱存储目录存在
os.makedirs(cls.GRAPH_STORAGE_DIR, exist_ok=True)
return errors

Loading