|
|
|
@ -13,7 +13,6 @@ from Dao.KbDao import KbDao
|
|
|
|
|
from Util.MySQLUtil import init_mysql_pool
|
|
|
|
|
from Config import Config
|
|
|
|
|
from fastapi.staticfiles import StaticFiles
|
|
|
|
|
import urllib3
|
|
|
|
|
|
|
|
|
|
# 初始化日志
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
@ -43,23 +42,7 @@ async def lifespan(app: FastAPI):
|
|
|
|
|
api_key=Config.DEEPSEEK_API_KEY,
|
|
|
|
|
base_url=Config.DEEPSEEK_URL
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# 启动文档处理任务
|
|
|
|
|
async def document_processor():
|
|
|
|
|
while True:
|
|
|
|
|
try:
|
|
|
|
|
# 获取未处理文档
|
|
|
|
|
# 处理文档
|
|
|
|
|
# 保存到ES
|
|
|
|
|
await asyncio.sleep(10)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
logger.error(f"文档处理出错: {e}")
|
|
|
|
|
await asyncio.sleep(10)
|
|
|
|
|
|
|
|
|
|
task = asyncio.create_task(document_processor())
|
|
|
|
|
yield
|
|
|
|
|
# 关闭时取消任务
|
|
|
|
|
task.cancel()
|
|
|
|
|
# 关闭数据库连接池
|
|
|
|
|
await app.state.kb_dao.mysql_pool.close()
|
|
|
|
|
|
|
|
|
|