- Introduce a new `sync_default_tools` function in `session.py` to ensure essential reusable tools are created without overwriting existing edits. - Update the `lifespan` context manager in `app.py` to call `sync_default_tools`, enhancing the initialization process for the application. - This change improves the management of default tools within the system, ensuring they are available for use while preserving user modifications.
66 lines
1.7 KiB
Python
66 lines
1.7 KiB
Python
"""FastAPI 入口。挂载路由,放行前端跨域,启动时同步接口定义。
|
|
|
|
启动: uv run --with-requirements requirements.txt uvicorn app:app --reload --port 8000
|
|
|
|
路由分组(对齐 dograh 的 routes/ 结构):
|
|
/health 健康检查
|
|
/api/assistants 助手 CRUD
|
|
/api/interface-definitions 接口定义
|
|
/api/model-resources 模型资源 CRUD
|
|
/ws/voice WebRTC 输出(浏览器)
|
|
/ws/stream WS 输出(裸音频流)
|
|
/api/webrtc/ice-servers WebRTC STUN/TURN 配置
|
|
"""
|
|
|
|
from contextlib import asynccontextmanager
|
|
|
|
import settings
|
|
import uvicorn
|
|
from db.session import sync_default_tools, sync_interface_definitions
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from routes import (
|
|
assistants,
|
|
auth,
|
|
health,
|
|
knowledge_bases,
|
|
model_registry,
|
|
node_types,
|
|
tools,
|
|
voice_webrtc,
|
|
voice_ws,
|
|
)
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(_app: FastAPI):
|
|
await sync_interface_definitions()
|
|
await sync_default_tools()
|
|
yield
|
|
|
|
|
|
app = FastAPI(title="AI Video Assistant 平台 - 后端", lifespan=lifespan)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=settings.CORS_ORIGINS,
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
app.include_router(health.router)
|
|
app.include_router(auth.router)
|
|
app.include_router(assistants.router)
|
|
app.include_router(knowledge_bases.router)
|
|
app.include_router(model_registry.router)
|
|
app.include_router(node_types.router)
|
|
app.include_router(tools.router)
|
|
app.include_router(voice_webrtc.router)
|
|
app.include_router(voice_ws.router)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
uvicorn.run("app:app", host=settings.HOST, port=settings.PORT, reload=True)
|