-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathserver.py
More file actions
66 lines (52 loc) · 1.58 KB
/
server.py
File metadata and controls
66 lines (52 loc) · 1.58 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
64
65
66
# server.py
import uvicorn
from fastapi import FastAPI, Request
from fastapi.middleware.cors import CORSMiddleware
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
from contextlib import asynccontextmanager
from api.routes import router as api_router
from db.session import create_tables
from utils.logger import logger
from core.plugin_manager import plugin_manager
@asynccontextmanager
async def lifespan(app: FastAPI):
# Load configuration
logger.info("Configuration loaded")
# Create database tables
create_tables()
# Initialize plugin manager
await plugin_manager.initialize()
logger.info("ManusPrime server started")
yield
# Cleanup plugins
await plugin_manager.cleanup()
logger.info("ManusPrime server shutting down")
# Create FastAPI app
app = FastAPI(
title="ManusPrime",
description="Multi-model AI agent API",
version="0.1.0",
lifespan=lifespan
)
# Add CORS middleware
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Mount static files
app.mount("/static", StaticFiles(directory="web/static"), name="static")
# Set up templates
templates = Jinja2Templates(directory="web/templates")
# Create web routes
@app.get("/")
async def index(request: Request):
return templates.TemplateResponse("index.html", {"request": request})
# Include API routes
app.include_router(api_router)
# Run server
if __name__ == "__main__":
uvicorn.run(app, host="localhost", port=8000)