添加GraphRAG

This commit is contained in:
2026-03-31 19:07:20 +08:00
parent d2cf97387b
commit be26ad3eee
8 changed files with 51 additions and 9 deletions

1
backend/.python-version Normal file
View File

@@ -0,0 +1 @@
3.12

0
backend/README.md Normal file
View File

View File

@@ -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)

View File

@@ -24,7 +24,7 @@ _WRITE_PATTERN = re.compile(
def _get_client() -> anthropic.Anthropic:
global _client
if _client is None:
_client = anthropic.Anthropic(api_key=os.getenv("ANTHROPIC_API_KEY"))
_client = anthropic.Anthropic(base_url=os.getenv("ANTHROPIC_BASE_URL"))
return _client

7
backend/pyproject.toml Normal file
View File

@@ -0,0 +1,7 @@
[project]
name = "backend"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = []

View File

@@ -114,7 +114,7 @@
{ "location": "luoyang", "chapter": 1, "event": "在荣凤祥设宴的文化沙龙中遇各路人物,寇仲与郑石如、侯希白竞争尚秀芳关注" },
{ "location": "luoyang", "chapter": 1, "event": "寇仲与师妃暄初次交锋辩论,激烈对话后相互认可" },
{ "location": "luoyang", "chapter": 2, "event": "徐子陵扮秦节原,与寇仲随王世充出城应对刺杀" },
{ "location": "luoyang", "chapter": 2, "event": "晁公错圆钹刺杀,李密暗算王世充,徐子陵假死""" },
{ "location": "luoyang", "chapter": 2, "event": "晁公错圆钹刺杀,李密暗算王世充,徐子陵假死「李代桃僵」" },
{ "lat": 34.65, "lng": 112.6, "chapter": 3, "event": "与徐子陵抱着伤重王世充离城逃命" },
{ "location": "luoyang", "chapter": 4, "event": "寇仲与宋鲁密议,了解南北势力对立,宋家支持寇仲争天下" },
{ "location": "yiyang", "chapter": 5, "event": "启程赴偃师,担任军师,分析李密动向" },
@@ -162,7 +162,7 @@
"color": "#FF4500",
"route": [
{ "location": "luoyang", "chapter": 1, "event": "出席荣府文化沙龙,与名士佳人交谈应对" },
{ "location": "luoyang", "chapter": 2, "event": "主演""之策,于城外配合王世充应对刺杀" },
{ "location": "luoyang", "chapter": 2, "event": "主演「将计就计」之策,于城外配合王世充应对刺杀" },
{ "location": "luoyang", "chapter": 3, "event": "设计虚行之妙计,令王世充虚张声势见客以稳军心" },
{ "location": "yiyang", "chapter": 5, "event": "与徐子陵秘密进入偃师城,见宣永探知李密行踪" },
{ "location": "yiyang", "chapter": 6, "event": "为杨公卿讲述各种兵法韬略与军队组织原理" },

View File

@@ -0,0 +1,11 @@
services:
dt_map:
image: nginx:alpine
container_name: dt_map
restart: unless-stopped
ports:
- "80:80"
volumes:
- ../dist:/usr/share/nginx/html:ro
- ../data:/usr/share/nginx/data:ro
- ./nginx.conf:/etc/nginx/conf.d/default.conf:ro

View File

@@ -0,0 +1,20 @@
server {
listen 80;
server_name _;
root /usr/share/nginx/html;
index index.html;
gzip on;
gzip_types text/plain text/css application/json application/javascript text/xml;
gzip_min_length 1024;
location / {
try_files $uri $uri/ /index.html;
}
location /data/ {
alias /usr/share/nginx/data/;
charset utf-8;
}
location /assets/ {
expires 30d;
add_header Cache-Control "public, immutable";
}
}