Skip to content

Commit 1f1d68b

Browse files
authored
Merge pull request #60 from data-exp-lab/fe-rag
Fix RAG Interface
2 parents 49646e2 + 7765a2d commit 1f1d68b

File tree

3 files changed

+760
-214
lines changed

3 files changed

+760
-214
lines changed

backend/app/main.py

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,7 @@ def graphrag_setup_endpoint():
734734
provider = data.get("provider", "openai")
735735
api_keys = data.get("apiKeys", {})
736736
graph_file = data.get("graphFile", "")
737+
session_id = data.get("sessionId", "")
737738

738739
# Merge frontend API keys with config and convert to GraphRAG format
739740
graphrag_api_keys = {}
@@ -813,7 +814,7 @@ def graphrag_setup_endpoint():
813814
graphrag_progress["message"] = "Creating new database from graph data"
814815

815816
# Setup database from GEXF content with progress updates
816-
setup_result = graphrag_service.setup_database_from_gexf_with_progress(graph_file, github_token, graphrag_progress)
817+
setup_result = graphrag_service.setup_database_from_gexf_with_progress(graph_file, github_token, graphrag_progress, session_id)
817818
if not setup_result["success"]:
818819
graphrag_progress["status"] = "error"
819820
graphrag_progress["message"] = setup_result.get("error", "Setup failed")
@@ -1158,6 +1159,62 @@ def graphrag_endpoint():
11581159
}), 500
11591160

11601161

1162+
@app.route("/api/graphrag-cleanup", methods=["POST"])
1163+
def graphrag_cleanup_endpoint():
1164+
"""Clean up GraphRAG database and resources when user closes window."""
1165+
try:
1166+
data = request.get_json() or {}
1167+
session_id = data.get("sessionId", "")
1168+
1169+
# Clean up GraphRAG resources
1170+
result = graphrag_service.cleanup(session_id)
1171+
1172+
return jsonify({
1173+
"success": True,
1174+
"message": "GraphRAG cleanup completed successfully",
1175+
"details": result
1176+
})
1177+
1178+
except Exception as e:
1179+
return jsonify({
1180+
"success": False,
1181+
"error": str(e),
1182+
"message": "An error occurred during GraphRAG cleanup"
1183+
}), 500
1184+
1185+
1186+
@app.route("/api/graphrag-check-changes", methods=["POST"])
1187+
def graphrag_check_changes_endpoint():
1188+
"""Check if GraphRAG database needs to be rebuilt due to graph changes."""
1189+
try:
1190+
data = request.get_json() or {}
1191+
gexf_content = data.get("gexfContent", "")
1192+
1193+
if not gexf_content:
1194+
return jsonify({
1195+
"success": False,
1196+
"error": "No GEXF content provided",
1197+
"message": "Please provide GEXF content to check for changes"
1198+
}), 400
1199+
1200+
# Check if database should be rebuilt
1201+
result = graphrag_service.should_rebuild_database(gexf_content)
1202+
1203+
return jsonify({
1204+
"success": True,
1205+
"should_rebuild": result.get("should_rebuild", False),
1206+
"message": result.get("message", ""),
1207+
"details": result
1208+
})
1209+
1210+
except Exception as e:
1211+
return jsonify({
1212+
"success": False,
1213+
"error": str(e),
1214+
"message": "An error occurred while checking for graph changes"
1215+
}), 500
1216+
1217+
11611218
@app.route("/")
11621219
def home():
11631220
return "Hello World!"

0 commit comments

Comments
 (0)