修改GraphRAG后端,另外两本小说入库
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
"""
|
||||
大唐双龙传 GraphRAG — FastAPI 后端
|
||||
武侠三部曲 GraphRAG — FastAPI 后端
|
||||
|
||||
端点:
|
||||
GET /api/health — 健康检查(含 Neo4j 连通性)
|
||||
@@ -13,11 +13,11 @@ from fastapi.middleware.cors import CORSMiddleware
|
||||
from pydantic import BaseModel
|
||||
|
||||
from graph_query import get_driver, get_graph_stats
|
||||
from graph_builder import build_graph
|
||||
from graph_builder import build_all_graphs
|
||||
from llm_router import answer_question
|
||||
import uvicorn
|
||||
|
||||
app = FastAPI(title="大唐双龙传 GraphRAG API", version="1.0.0")
|
||||
app = FastAPI(title="武侠三部曲 GraphRAG API", version="1.1.0")
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
@@ -37,6 +37,7 @@ class ChatRequest(BaseModel):
|
||||
|
||||
class ImportRequest(BaseModel):
|
||||
clear: bool = False # True = 先清空图谱再重新导入
|
||||
novels: list[str] | None = None # 默认导入 dtslz/ldj/tlbb
|
||||
|
||||
|
||||
# ── Endpoints ─────────────────────────────────────────────
|
||||
@@ -62,10 +63,10 @@ def stats():
|
||||
|
||||
@app.post("/api/import")
|
||||
def import_data(req: ImportRequest = ImportRequest()):
|
||||
"""导入所有卷数据到 Neo4j(耗时约 1-3 分钟,请勿重复调用)"""
|
||||
"""导入小说数据到 Neo4j(耗时约 1-3 分钟,请勿重复调用)"""
|
||||
driver = get_driver()
|
||||
try:
|
||||
build_graph(driver, clear=req.clear)
|
||||
build_all_graphs(driver, novels=req.novels, clear=req.clear)
|
||||
stats = get_graph_stats()
|
||||
return {"status": "ok", "stats": stats}
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user