From b80dc6e23fa9acc5ffa9b3189a9cf1556f77a0ce Mon Sep 17 00:00:00 2001 From: ageerle Date: Tue, 28 Jul 2026 11:22:19 +0800 Subject: [PATCH] =?UTF-8?q?fix(shortdrama):=20=E6=B5=81=E5=BC=8F=E7=94=9F?= =?UTF-8?q?=E6=88=90=E5=A2=9E=E5=8A=A0=E9=A6=96=20token=2090=20=E7=A7=92?= =?UTF-8?q?=E8=B6=85=E6=97=B6=E5=85=9C=E5=BA=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 部分聚合站对 stream=true 既不返回内容也不报错,外层 30 分钟总超时 才会失败,前端会长时间卡死。90 秒内未收到任何 token 时快速失败, 提示更换模型或使用同步生成。收到首 token 后取消兜底计时。 Co-Authored-By: Claude --- .../service/shortdrama/impl/ShortDramaServiceImpl.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ruoyi-modules/ruoyi-chat/src/main/java/org/ruoyi/service/shortdrama/impl/ShortDramaServiceImpl.java b/ruoyi-modules/ruoyi-chat/src/main/java/org/ruoyi/service/shortdrama/impl/ShortDramaServiceImpl.java index 219dfb08..49e0cdad 100644 --- a/ruoyi-modules/ruoyi-chat/src/main/java/org/ruoyi/service/shortdrama/impl/ShortDramaServiceImpl.java +++ b/ruoyi-modules/ruoyi-chat/src/main/java/org/ruoyi/service/shortdrama/impl/ShortDramaServiceImpl.java @@ -1864,10 +1864,20 @@ public class ShortDramaServiceImpl implements IShortDramaService { }); heartbeat.scheduleAtFixedRate(() -> emit(emitter, streamPhase, "running", "模型仍在处理中,请稍候..."), 15, 15, TimeUnit.SECONDS); + // 首 token 超时兜底:部分聚合站对 stream=true 既不返回内容也不报错, + // 外层 30 分钟总超时才会失败,前端会长时间卡死。90 秒内未收到任何 token 时快速失败。 + final AtomicBoolean firstTokenReceived = new AtomicBoolean(false); + heartbeat.schedule(() -> { + if (firstTokenReceived.compareAndSet(false, true)) { + done.completeExceptionally(new RuntimeException( + "模型在90秒内未返回任何流式内容,可能该模型或服务不支持流式输出,请更换模型或使用同步生成")); + } + }, 90, TimeUnit.SECONDS); List messages = List.of(UserMessage.from(prompt)); streamingModel.chat(messages, new StreamingChatResponseHandler() { @Override public void onPartialResponse(String text) { + firstTokenReceived.set(true); buf.append(text); emitStream(emitter, streamPhase, text); if (onPartial != null) {