From 36c00e400801786ee0f06a50e6046f49777ed188 Mon Sep 17 00:00:00 2001
From: zhaoqingang <zhaoqg0118@163.com>
Date: 星期二, 14 一月 2025 15:47:31 +0800
Subject: [PATCH] tmp

---
 main.py |   52 +++++++++++++++++++++++++++++++++-------------------
 1 files changed, 33 insertions(+), 19 deletions(-)

diff --git a/main.py b/main.py
index a9e4f0f..dc14409 100644
--- a/main.py
+++ b/main.py
@@ -1,5 +1,5 @@
 from contextlib import asynccontextmanager
-# from apscheduler.schedulers.background import BackgroundScheduler
+from apscheduler.schedulers.background import BackgroundScheduler
 from fastapi import FastAPI
 from fastapi.middleware.cors import CORSMiddleware
 from starlette.staticfiles import StaticFiles
@@ -15,6 +15,7 @@
 from app.api.label import label_router
 from app.api.llm import llm_router
 from app.api.organization import dept_router
+from app.api.v2.chat import chat_router_v2
 from app.api.v2.public_api import public_api
 from app.api.report import router as report_router
 from app.api.resource import menu_router
@@ -22,23 +23,35 @@
 from app.api.user import user_router
 from app.api.group import group_router
 from app.api.role import role_router
-from app.task.fetch_agent import sync_agents, initialize_agents, sync_web_menu, sync_default_data
+from app.models.base_model import init_db
+# from app.models.base_model import init_db
+from app.task.fetch_agent import sync_agents, initialize_agents, sync_agents_v2, sync_knowledge, \
+    sync_resources_from_json
+from app.init_config.init_run_data import sync_default_data
+
+init_db()
 
 
 # 浣跨敤 Lifespan 浜嬩欢澶勭悊绋嬪簭
 @asynccontextmanager
 async def lifespan(app: FastAPI):
     # 鍒濆鍖栦唬鐞�
-    initialize_agents()
-    # 鍦ㄥ簲鐢ㄥ惎鍔ㄦ椂鍚屾浠g悊
-    sync_agents()
-    await sync_default_data()
-    await sync_web_menu()
+    # initialize_agents()
+    # # 鍦ㄥ簲鐢ㄥ惎鍔ㄦ椂鍚屾浠g悊
+    # sync_agents()
+
+
+
+    # await sync_default_data()
+    #
+    # sync_agents_v2()
+    # sync_knowledge()
+    # sync_resources_from_json()
     yield
     # 鍦ㄥ簲鐢ㄥ叧闂椂鎵ц娓呯悊鎿嶄綔锛堝鏋滈渶瑕侊級
     pass
 
-# init_db()
+
 app = FastAPI(
     title="basic_rag_gateway",
     version="0.1",
@@ -47,18 +60,17 @@
 )
 
 # 璁剧疆 CORS 涓棿浠�
-app.add_middleware(
-    CORSMiddleware,
-    allow_origins=["*"],  # 鍏佽鎵�鏈夊煙鍚嶈法鍩熻闂�
-    allow_credentials=True,
-    allow_methods=["*"],  # 鍏佽鎵�鏈夋柟娉�
-    allow_headers=["*"],  # 鍏佽鎵�鏈夊ご閮�
-)
+# app.add_middleware(
+#     CORSMiddleware,
+#     allow_origins=["http://192.168.20.119:9303", "http://192.168.20.119:9301", "http://smartai.com:8293","http://localhost:9303",  "http://127.0.0.1:9303","http://localhost:5173","http://192.168.20.158:5173"],
+#     allow_credentials=True,
+#     allow_methods=["*"],  # 鍏佽鎵�鏈夋柟娉�
+#     allow_headers=["*"],  # 鍏佽鎵�鏈夊ご閮�
+# )
 # 鍒涘缓璋冨害鍣�
-# scheduler = BackgroundScheduler()
-# scheduler.add_job(sync_resource, 'interval', minutes=1, id="sync_resource_data")
-# scheduler.start()
-
+scheduler = BackgroundScheduler()
+scheduler.add_job(sync_agents_v2, 'interval', minutes=60, id="sync_resource_data")
+scheduler.start()
 
 app.include_router(auth_router, prefix='/api/auth', tags=["auth"])
 app.include_router(chat_router, prefix='/api/chat', tags=["chat"])
@@ -77,8 +89,10 @@
 app.include_router(canvas_router, prefix='/api/canvas', tags=["canvas"])
 app.include_router(label_router, prefix='/api/label', tags=["label"])
 app.include_router(public_api, prefix='/v1/api', tags=["public_api"])
+app.include_router(chat_router_v2, prefix='/v1/chat', tags=["chat1"])
 app.mount("/static", StaticFiles(directory="app/images"), name="static")
 
 if __name__ == "__main__":
     import uvicorn
+
     uvicorn.run(app, host="0.0.0.0", port=9201)

--
Gitblit v1.8.0