feat: implement AI model API proxy service
This commit is contained in:
46
backend/app/main.py
Normal file
46
backend/app/main.py
Normal file
@@ -0,0 +1,46 @@
|
||||
"""FastAPI application entry point."""
|
||||
from contextlib import asynccontextmanager
|
||||
from fastapi import FastAPI
|
||||
|
||||
from .database import init_db, seed_default_providers
|
||||
from .services.logger import async_logger
|
||||
from .routes import health_router, chat_router, openai_router, anthropic_router
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
"""Application lifespan handler."""
|
||||
# Startup
|
||||
await init_db()
|
||||
await seed_default_providers()
|
||||
await async_logger.start()
|
||||
|
||||
yield
|
||||
|
||||
# Shutdown
|
||||
await async_logger.stop()
|
||||
|
||||
|
||||
app = FastAPI(
|
||||
title="zzrouter",
|
||||
description="AI Model API Proxy Service",
|
||||
version="0.1.0",
|
||||
lifespan=lifespan
|
||||
)
|
||||
|
||||
# Register routers
|
||||
app.include_router(health_router)
|
||||
app.include_router(chat_router)
|
||||
app.include_router(openai_router)
|
||||
app.include_router(anthropic_router)
|
||||
|
||||
|
||||
def run_server():
|
||||
"""Run the server (entry point for script)."""
|
||||
import uvicorn
|
||||
from .config import HOST, PORT
|
||||
uvicorn.run(app, host=HOST, port=PORT)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run_server()
|
||||
Reference in New Issue
Block a user