添加GraphRAG
This commit is contained in:
1
backend/.python-version
Normal file
1
backend/.python-version
Normal file
@@ -0,0 +1 @@
|
|||||||
|
3.12
|
||||||
0
backend/README.md
Normal file
0
backend/README.md
Normal file
@@ -15,16 +15,13 @@ from pydantic import BaseModel
|
|||||||
from graph_query import get_driver, get_graph_stats
|
from graph_query import get_driver, get_graph_stats
|
||||||
from graph_builder import build_graph
|
from graph_builder import build_graph
|
||||||
from llm_router import answer_question
|
from llm_router import answer_question
|
||||||
|
import uvicorn
|
||||||
|
|
||||||
app = FastAPI(title="大唐双龙传 GraphRAG API", version="1.0.0")
|
app = FastAPI(title="大唐双龙传 GraphRAG API", version="1.0.0")
|
||||||
|
|
||||||
app.add_middleware(
|
app.add_middleware(
|
||||||
CORSMiddleware,
|
CORSMiddleware,
|
||||||
allow_origins=[
|
allow_origins=["*"],
|
||||||
"http://localhost:5173", # Vite dev server
|
|
||||||
"http://localhost:4173", # Vite preview
|
|
||||||
"http://127.0.0.1:5173",
|
|
||||||
],
|
|
||||||
allow_credentials=True,
|
allow_credentials=True,
|
||||||
allow_methods=["*"],
|
allow_methods=["*"],
|
||||||
allow_headers=["*"],
|
allow_headers=["*"],
|
||||||
@@ -33,6 +30,7 @@ app.add_middleware(
|
|||||||
|
|
||||||
# ── Models ────────────────────────────────────────────────
|
# ── Models ────────────────────────────────────────────────
|
||||||
|
|
||||||
|
|
||||||
class ChatRequest(BaseModel):
|
class ChatRequest(BaseModel):
|
||||||
question: str
|
question: str
|
||||||
|
|
||||||
@@ -43,6 +41,7 @@ class ImportRequest(BaseModel):
|
|||||||
|
|
||||||
# ── Endpoints ─────────────────────────────────────────────
|
# ── Endpoints ─────────────────────────────────────────────
|
||||||
|
|
||||||
|
|
||||||
@app.get("/api/health")
|
@app.get("/api/health")
|
||||||
def health():
|
def health():
|
||||||
driver = get_driver()
|
driver = get_driver()
|
||||||
@@ -78,3 +77,7 @@ def chat(req: ChatRequest):
|
|||||||
if not req.question.strip():
|
if not req.question.strip():
|
||||||
raise HTTPException(status_code=400, detail="问题不能为空")
|
raise HTTPException(status_code=400, detail="问题不能为空")
|
||||||
return answer_question(req.question)
|
return answer_question(req.question)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
uvicorn.run("app:app", host="0.0.0.0", port=8000, reload=True)
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ _WRITE_PATTERN = re.compile(
|
|||||||
def _get_client() -> anthropic.Anthropic:
|
def _get_client() -> anthropic.Anthropic:
|
||||||
global _client
|
global _client
|
||||||
if _client is None:
|
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
|
return _client
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
7
backend/pyproject.toml
Normal file
7
backend/pyproject.toml
Normal 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 = []
|
||||||
@@ -114,7 +114,7 @@
|
|||||||
{ "location": "luoyang", "chapter": 1, "event": "在荣凤祥设宴的文化沙龙中遇各路人物,寇仲与郑石如、侯希白竞争尚秀芳关注" },
|
{ "location": "luoyang", "chapter": 1, "event": "在荣凤祥设宴的文化沙龙中遇各路人物,寇仲与郑石如、侯希白竞争尚秀芳关注" },
|
||||||
{ "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": "晁公错圆钹刺杀,李密暗算王世充,徐子陵假死"李代桃僵"" },
|
{ "location": "luoyang", "chapter": 2, "event": "晁公错圆钹刺杀,李密暗算王世充,徐子陵假死「李代桃僵」" },
|
||||||
{ "lat": 34.65, "lng": 112.6, "chapter": 3, "event": "与徐子陵抱着伤重王世充离城逃命" },
|
{ "lat": 34.65, "lng": 112.6, "chapter": 3, "event": "与徐子陵抱着伤重王世充离城逃命" },
|
||||||
{ "location": "luoyang", "chapter": 4, "event": "寇仲与宋鲁密议,了解南北势力对立,宋家支持寇仲争天下" },
|
{ "location": "luoyang", "chapter": 4, "event": "寇仲与宋鲁密议,了解南北势力对立,宋家支持寇仲争天下" },
|
||||||
{ "location": "yiyang", "chapter": 5, "event": "启程赴偃师,担任军师,分析李密动向" },
|
{ "location": "yiyang", "chapter": 5, "event": "启程赴偃师,担任军师,分析李密动向" },
|
||||||
@@ -162,7 +162,7 @@
|
|||||||
"color": "#FF4500",
|
"color": "#FF4500",
|
||||||
"route": [
|
"route": [
|
||||||
{ "location": "luoyang", "chapter": 1, "event": "出席荣府文化沙龙,与名士佳人交谈应对" },
|
{ "location": "luoyang", "chapter": 1, "event": "出席荣府文化沙龙,与名士佳人交谈应对" },
|
||||||
{ "location": "luoyang", "chapter": 2, "event": "主演"将计就计"之策,于城外配合王世充应对刺杀" },
|
{ "location": "luoyang", "chapter": 2, "event": "主演「将计就计」之策,于城外配合王世充应对刺杀" },
|
||||||
{ "location": "luoyang", "chapter": 3, "event": "设计虚行之妙计,令王世充虚张声势见客以稳军心" },
|
{ "location": "luoyang", "chapter": 3, "event": "设计虚行之妙计,令王世充虚张声势见客以稳军心" },
|
||||||
{ "location": "yiyang", "chapter": 5, "event": "与徐子陵秘密进入偃师城,见宣永探知李密行踪" },
|
{ "location": "yiyang", "chapter": 5, "event": "与徐子陵秘密进入偃师城,见宣永探知李密行踪" },
|
||||||
{ "location": "yiyang", "chapter": 6, "event": "为杨公卿讲述各种兵法韬略与军队组织原理" },
|
{ "location": "yiyang", "chapter": 6, "event": "为杨公卿讲述各种兵法韬略与军队组织原理" },
|
||||||
|
|||||||
11
frontend-deploy/docker-compose.yml
Normal file
11
frontend-deploy/docker-compose.yml
Normal 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
|
||||||
20
frontend-deploy/nginx.conf
Normal file
20
frontend-deploy/nginx.conf
Normal 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";
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user