From 88ae2fcd43de3138d2923f16bb59d2580b687579 Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期三, 30 十月 2024 01:56:21 +0800 Subject: [PATCH] 程序启动时初始化agent表并从ragflow和毕昇拉取智能体id然后更新agent表 --- main.py | 22 +++++++++++++++++++--- 1 files changed, 19 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 2470d4b..e629cbf 100644 --- a/main.py +++ b/main.py @@ -1,3 +1,5 @@ +from contextlib import asynccontextmanager + from fastapi import FastAPI from app.api.auth import router as auth_router from app.api.chat import router as chat_router @@ -6,12 +8,26 @@ from app.api.files import router as files_router from app.api.report import router as report_router from app.models.base_model import init_db +from app.task.fetch_agent import sync_agents, initialize_agents + + +# 浣跨敤 Lifespan 浜嬩欢澶勭悊绋嬪簭 +@asynccontextmanager +async def lifespan(app: FastAPI): + # 鍒濆鍖栦唬鐞� + initialize_agents() + # 鍦ㄥ簲鐢ㄥ惎鍔ㄦ椂鍚屾浠g悊 + sync_agents() + yield + # 鍦ㄥ簲鐢ㄥ叧闂椂鎵ц娓呯悊鎿嶄綔锛堝鏋滈渶瑕侊級 + pass init_db() app = FastAPI( - title="basic_rag_gateway", - version="0.1", - description="", + title="basic_rag_gateway", + version="0.1", + description="", + lifespan=lifespan ) app.include_router(auth_router, prefix='/api/auth', tags=["auth"]) -- Gitblit v1.8.0