From 09ca6948f0bed39a87ae03a996aa77dadc2a7811 Mon Sep 17 00:00:00 2001 From: Tian jianyong <11429339@qq.com> Date: Wed, 24 Dec 2025 19:00:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module_admin/controller/ragflow_controller.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/ruoyi-fastapi-backend/module_admin/controller/ragflow_controller.py b/ruoyi-fastapi-backend/module_admin/controller/ragflow_controller.py index e2a0770..6106e23 100644 --- a/ruoyi-fastapi-backend/module_admin/controller/ragflow_controller.py +++ b/ruoyi-fastapi-backend/module_admin/controller/ragflow_controller.py @@ -340,11 +340,17 @@ def stream_ragflow_response(result: Generator, chat_id: str, start_time: float, total_time = time.perf_counter() - start_time logger.info(f'[RAG_SERVER {time.time():.3f}] ⏱️ Total Stream Duration ({chat_id}): {total_time:.3f}s') - # 流结束后存储缓存(使用 create_task 确保异步任务被执行) + # 流结束后存储缓存 if cache_store_func and last_answer and len(last_answer.strip()) >= 10: try: - asyncio.create_task(cache_store_func(last_answer)) - logger.info(f'[RAG_CACHE] 缓存存储任务已调度 | chat_id={chat_id} | answer_length={len(last_answer)}') + import asyncio + loop = asyncio.new_event_loop() + asyncio.set_event_loop(loop) + try: + loop.run_until_complete(cache_store_func(last_answer)) + logger.info(f'[RAG_CACHE] 缓存存储完成 | chat_id={chat_id} | answer_length={len(last_answer)}') + finally: + loop.close() except Exception as cache_err: logger.warning(f'[RAG_CACHE] 缓存存储失败: {cache_err}')