-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_api.py
More file actions
63 lines (51 loc) · 1.28 KB
/
main_api.py
File metadata and controls
63 lines (51 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""
Main FastAPI application for RAG system backend with web frontend.
"""
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import FileResponse
from pathlib import Path
from backend.routes import router
# Initialize FastAPI app
app = FastAPI(
title="RAG System API",
description="Backend API for Retrieval-Augmented Generation system",
version="0.1.0"
)
# Configure CORS
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Include API routes
app.include_router(router, tags=["rag"])
frontend_path = Path(__file__).parent / "frontend" / "index.html"
@app.get("/")
async def root():
"""Serve the web frontend."""
if frontend_path.exists():
return FileResponse(frontend_path, media_type="text/html")
return {
"message": "RAG System API",
"docs": "/docs",
"frontend": "Not available",
}
if __name__ == "__main__":
import uvicorn
uvicorn.run(
"main_api:app",
host="0.0.0.0",
port=8000,
reload=True
)
if __name__ == "__main__":
import uvicorn
uvicorn.run(
"main_api:app",
host="0.0.0.0",
port=8000,
reload=True
)