AI实验室后端
This commit is contained in:
+15
-4
@@ -1,11 +1,13 @@
|
||||
import asyncio
|
||||
|
||||
from fastapi import FastAPI
|
||||
from fastapi import FastAPI, Request
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from uvicorn import Config, Server
|
||||
|
||||
from config.emqx import mqtt_client_async
|
||||
from config.emqx import mqtt_client_runner
|
||||
from config.yolo import YOLOSingleton
|
||||
from models.BaseResponse import BaseResponse
|
||||
from routers.AnnualMeeting import amRouter
|
||||
from routers.Bot import botRouter
|
||||
from routers.Chat import chatRouter
|
||||
from routers.Datasource import reportDataRouter
|
||||
@@ -51,16 +53,25 @@ async def ai_lab():
|
||||
app.include_router(r, prefix="/llm", tags=["llm"])
|
||||
app.include_router(visionRouter, prefix="/cv", tags=["cv"])
|
||||
app.include_router(systemRouter, prefix="/system", tags=["system"])
|
||||
app.include_router(amRouter, prefix="/am", tags=["annual_meeting"])
|
||||
app.include_router(iot_router, prefix="/iot", tags=["iot"])
|
||||
app.include_router(sentinel_router, prefix="/iot/sentinel", tags=["iot_sentinel"])
|
||||
app.include_router(iot_ws_router, prefix="/iot/ws", tags=["iot_ws"])
|
||||
app.include_router(publicRouter, prefix="/api/public", tags=["api"])
|
||||
config = Config(app=app, host="0.0.0.0", port=13011, log_level="debug")
|
||||
|
||||
# ----------- 全局异常捕获 ---------
|
||||
@app.exception_handler(Exception)
|
||||
async def global_exception_handler(request: Request, exc: Exception):
|
||||
return BaseResponse(status=False, message=str(exc), data=None)
|
||||
|
||||
config = Config(app=app, host="0.0.0.0", port=13011, log_level="warning")
|
||||
server = Server(config)
|
||||
|
||||
await server.serve()
|
||||
|
||||
|
||||
async def main():
|
||||
|
||||
# 初始化模型
|
||||
YOLOSingleton.init_model()
|
||||
# 主干AI实验室FastAPI服务
|
||||
@@ -68,7 +79,7 @@ async def main():
|
||||
# RabbitMQ服务
|
||||
task_mq = asyncio.create_task(sentinel_pull_analysis_async())
|
||||
# 等 HTTP 服务启动后再启动 MQTT
|
||||
task_mqtt = asyncio.create_task(mqtt_client_async())
|
||||
task_mqtt = asyncio.create_task(mqtt_client_runner())
|
||||
await asyncio.gather(task_api, task_mq, task_mqtt)
|
||||
|
||||
# MCP服务-ailab
|
||||
|
||||
Reference in New Issue
Block a user