Files
FilesReadSystem/backend/app/main.py

62 lines
1.3 KiB
Python

"""
FastAPI 应用主入口
"""
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from app.config import settings
from app.api import api_router
# 创建 FastAPI 应用实例
app = FastAPI(
title=settings.APP_NAME,
description="基于大语言模型的文档理解与多源数据融合系统",
version="1.0.0",
openapi_url=f"{settings.API_V1_STR}/openapi.json",
docs_url=f"{settings.API_V1_STR}/docs",
redoc_url=f"{settings.API_V1_STR}/redoc"
)
# 配置 CORS 中间件
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# 注册 API 路由
app.include_router(api_router, prefix=settings.API_V1_STR)
@app.get("/")
async def root():
"""根路径"""
return {
"message": f"Welcome to {settings.APP_NAME}",
"status": "online",
"version": "1.0.0",
"debug_mode": settings.DEBUG,
"api_docs": f"{settings.API_V1_STR}/docs"
}
@app.get("/health")
async def health_check():
"""健康检查接口"""
return {
"status": "healthy",
"service": settings.APP_NAME
}
if __name__ == "__main__":
import uvicorn
uvicorn.run(
"app.main:app",
host="127.0.0.1",
port=8000,
reload=settings.DEBUG
)