commit
9e1adacb1c
@ -0,0 +1,59 @@
|
||||
import threading
|
||||
import logging
|
||||
import uvicorn
|
||||
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from starlette.staticfiles import StaticFiles
|
||||
from tasks.BackgroundTasks import train_document_task
|
||||
from fastapi import FastAPI
|
||||
from utils.Database import *
|
||||
|
||||
# 导入路由
|
||||
from routes import *
|
||||
|
||||
# 在程序开始时添加以下配置
|
||||
logging.basicConfig(
|
||||
level=logging.INFO, # 设置日志级别为INFO
|
||||
format='%(asctime)s - %(levelname)s - %(message)s'
|
||||
)
|
||||
|
||||
async def lifespan(app: FastAPI):
|
||||
# 启动线程
|
||||
thread = threading.Thread(target=train_document_task, daemon=True)
|
||||
thread.start()
|
||||
# 创建数据库连接池
|
||||
await init_database()
|
||||
yield
|
||||
await shutdown_database()
|
||||
|
||||
app = FastAPI(lifespan=lifespan)
|
||||
|
||||
# 配置FastAPI支持CORS
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=["*"],
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"]
|
||||
)
|
||||
|
||||
# 挂载静态文件目录
|
||||
app.mount("/static", StaticFiles(directory="Static"), name="static")
|
||||
|
||||
# 注册路由
|
||||
# 登录相关
|
||||
app.include_router(login_router, prefix="/api/login", tags=["login"])
|
||||
# 主题相关
|
||||
app.include_router(theme_router, prefix="/api/theme", tags=["theme"])
|
||||
# 文档相关
|
||||
app.include_router(document_router, prefix="/api/document", tags=["document"])
|
||||
# 问题相关(大模型应用)
|
||||
app.include_router(question_router, prefix="/api/question", tags=["question"])
|
||||
# 字典相关(Dm)
|
||||
app.include_router(dm_router, prefix="/api/dm", tags=["dm"])
|
||||
# 测试相关
|
||||
# app.include_router(test_router, prefix="/api/test", tags=["test"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
uvicorn.run(app, host="0.0.0.0", port=8888)
|
Loading…
Reference in new issue