2026-07-09 16:29:10 +08:00
|
|
|
"""FastAPI 入口。挂载路由,放行前端跨域,启动时同步接口定义。
|
2026-06-08 13:51:28 +08:00
|
|
|
|
2026-06-10 13:37:24 +08:00
|
|
|
启动: uv run --with-requirements requirements.txt uvicorn app:app --reload --port 8000
|
2026-06-08 13:51:28 +08:00
|
|
|
|
|
|
|
|
路由分组(对齐 dograh 的 routes/ 结构):
|
|
|
|
|
/health 健康检查
|
|
|
|
|
/api/assistants 助手 CRUD
|
2026-06-14 19:36:12 +08:00
|
|
|
/api/interface-definitions 接口定义
|
|
|
|
|
/api/model-resources 模型资源 CRUD
|
2026-06-08 13:51:28 +08:00
|
|
|
/ws/voice WebRTC 输出(浏览器)
|
|
|
|
|
/ws/stream WS 输出(裸音频流)
|
2026-07-06 17:45:53 +08:00
|
|
|
/api/webrtc/ice-servers WebRTC STUN/TURN 配置
|
2026-06-08 13:51:28 +08:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
from contextlib import asynccontextmanager
|
|
|
|
|
|
|
|
|
|
import config
|
|
|
|
|
import uvicorn
|
2026-07-09 16:29:10 +08:00
|
|
|
from db.session import sync_interface_definitions
|
2026-06-08 13:51:28 +08:00
|
|
|
from fastapi import FastAPI
|
|
|
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
|
|
2026-06-09 08:31:39 +08:00
|
|
|
from routes import (
|
|
|
|
|
assistants,
|
|
|
|
|
health,
|
|
|
|
|
knowledge_bases,
|
2026-06-14 19:36:12 +08:00
|
|
|
model_registry,
|
2026-06-15 10:12:41 +08:00
|
|
|
node_types,
|
2026-06-09 08:31:39 +08:00
|
|
|
voice_webrtc,
|
|
|
|
|
voice_ws,
|
|
|
|
|
)
|
2026-06-08 13:51:28 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@asynccontextmanager
|
|
|
|
|
async def lifespan(_app: FastAPI):
|
2026-07-09 16:29:10 +08:00
|
|
|
await sync_interface_definitions()
|
2026-06-08 13:51:28 +08:00
|
|
|
yield
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app = FastAPI(title="AI Video Assistant 平台 - 后端", lifespan=lifespan)
|
|
|
|
|
|
|
|
|
|
app.add_middleware(
|
|
|
|
|
CORSMiddleware,
|
|
|
|
|
allow_origins=config.CORS_ORIGINS,
|
|
|
|
|
allow_credentials=True,
|
|
|
|
|
allow_methods=["*"],
|
|
|
|
|
allow_headers=["*"],
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
app.include_router(health.router)
|
|
|
|
|
app.include_router(assistants.router)
|
2026-06-09 08:31:39 +08:00
|
|
|
app.include_router(knowledge_bases.router)
|
2026-06-14 19:36:12 +08:00
|
|
|
app.include_router(model_registry.router)
|
2026-06-15 10:12:41 +08:00
|
|
|
app.include_router(node_types.router)
|
2026-06-08 13:51:28 +08:00
|
|
|
app.include_router(voice_webrtc.router)
|
|
|
|
|
app.include_router(voice_ws.router)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
uvicorn.run("app:app", host=config.HOST, port=config.PORT, reload=True)
|