修复空值检查问题

This commit is contained in:
Tian jianyong 2025-12-17 17:11:56 +08:00
parent ea1e10ad21
commit 16f80b3100

View File

@ -169,6 +169,15 @@ def stream_ragflow_response(result: Generator, chat_id: str, start_time: float)
if isinstance(body, dict) and 'answer' in body:
current_answer = body['answer']
# 安全检查确保current_answer不为None且为字符串
if current_answer is None:
logger.warning(f"[RAG_SERVER {chunk_time:.3f}] ⚠️ current_answer为None跳过处理")
continue
if not isinstance(current_answer, str):
logger.warning(f"[RAG_SERVER {chunk_time:.3f}] ⚠️ current_answer不是字符串类型: {type(current_answer)}")
current_answer = str(current_answer)
# 计算增量内容
if current_answer.startswith(last_answer):
delta = current_answer[len(last_answer):]