修改异步机制

This commit is contained in:
Tian jianyong 2025-12-24 20:18:09 +08:00
parent cd5fa88ec4
commit e40a9e5191

View File

@ -323,17 +323,14 @@ def stream_ragflow_response(result: Generator, chat_id: str, start_time: float,
total_time = time.perf_counter() - start_time total_time = time.perf_counter() - start_time
logger.info(f'[RAG_SERVER {time.time():.3f}] ⏱️ Total Stream Duration ({chat_id}): {total_time:.3f}s') logger.info(f'[RAG_SERVER {time.time():.3f}] ⏱️ Total Stream Duration ({chat_id}): {total_time:.3f}s')
# 流结束后存储缓存
if cache_store_func and last_answer and len(last_answer.strip()) >= 10: if cache_store_func and last_answer and len(last_answer.strip()) >= 10:
try: try:
import asyncio import asyncio
loop = asyncio.new_event_loop() cache_task = asyncio.create_task(cache_store_func(last_answer))
asyncio.set_event_loop(loop) cache_task.add_done_callback(
try: lambda t: logger.info(f'[RAG_CACHE] 缓存存储完成 | chat_id={chat_id} | answer_length={len(last_answer)}')
loop.run_until_complete(cache_store_func(last_answer)) if not t.exception() else logger.warning(f'[RAG_CACHE] 缓存存储失败: {t.exception()}')
logger.info(f'[RAG_CACHE] 缓存存储完成 | chat_id={chat_id} | answer_length={len(last_answer)}') )
finally:
loop.close()
except Exception as cache_err: except Exception as cache_err:
logger.warning(f'[RAG_CACHE] 缓存存储失败: {cache_err}') logger.warning(f'[RAG_CACHE] 缓存存储失败: {cache_err}')