From 0469ea2ecdce87b4ee4cf0a29d10116c11869b7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E6=BD=AE?= Date: Thu, 12 Mar 2026 19:32:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BF=83=E8=B7=B3=E8=BE=93=E5=87=BA=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E6=94=B9=E6=88=90json?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routes/chat.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/routes/chat.py b/routes/chat.py index 40d0f82..6ecb5e5 100644 --- a/routes/chat.py +++ b/routes/chat.py @@ -191,8 +191,9 @@ async def enhanced_generate_stream_response( if all(task.done() for task in [preamble_task_handle, agent_task_handle]): # 所有任务都完成了,退出循环 break - # 发送 SSE 心跳注释保持连接活跃,防止 nginx/客户端超时断开 - yield ": heartbeat\n\n" + # 发送空内容心跳包保持连接活跃,防止 nginx/客户端超时断开 + heartbeat_chunk = create_stream_chunk(f"chatcmpl-heartbeat", config.model_name, "") + yield f"data: {json.dumps(heartbeat_chunk, ensure_ascii=False)}\n\n" continue # 发送结束标记