添加GraphRAG
This commit is contained in:
@@ -15,16 +15,13 @@ from pydantic import BaseModel
|
||||
from graph_query import get_driver, get_graph_stats
|
||||
from graph_builder import build_graph
|
||||
from llm_router import answer_question
|
||||
import uvicorn
|
||||
|
||||
app = FastAPI(title="大唐双龙传 GraphRAG API", version="1.0.0")
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=[
|
||||
"http://localhost:5173", # Vite dev server
|
||||
"http://localhost:4173", # Vite preview
|
||||
"http://127.0.0.1:5173",
|
||||
],
|
||||
allow_origins=["*"],
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
@@ -33,16 +30,18 @@ app.add_middleware(
|
||||
|
||||
# ── Models ────────────────────────────────────────────────
|
||||
|
||||
|
||||
class ChatRequest(BaseModel):
|
||||
question: str
|
||||
|
||||
|
||||
class ImportRequest(BaseModel):
|
||||
clear: bool = False # True = 先清空图谱再重新导入
|
||||
clear: bool = False # True = 先清空图谱再重新导入
|
||||
|
||||
|
||||
# ── Endpoints ─────────────────────────────────────────────
|
||||
|
||||
|
||||
@app.get("/api/health")
|
||||
def health():
|
||||
driver = get_driver()
|
||||
@@ -78,3 +77,7 @@ def chat(req: ChatRequest):
|
||||
if not req.question.strip():
|
||||
raise HTTPException(status_code=400, detail="问题不能为空")
|
||||
return answer_question(req.question)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
uvicorn.run("app:app", host="0.0.0.0", port=8000, reload=True)
|
||||
|
||||
Reference in New Issue
Block a user