添加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_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)
|
||||
|
||||
@@ -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
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 = []
|
||||
Reference in New Issue
Block a user