mirror of
https://gitcode.com/ageerle/ruoyi-ai.git
synced 2026-04-15 12:53:42 +00:00
@@ -98,6 +98,8 @@ public abstract class AbstractStreamingChatService implements IChatService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
SseMessageUtils.sendMessage(userId, "对话出错:" + e.getMessage());
|
||||||
|
SseMessageUtils.completeConnection(userId, tokenValue);
|
||||||
log.error("{}请求失败:{}", getProviderName(), e.getMessage(), e);
|
log.error("{}请求失败:{}", getProviderName(), e.getMessage(), e);
|
||||||
}
|
}
|
||||||
return emitter;
|
return emitter;
|
||||||
@@ -223,6 +225,21 @@ public abstract class AbstractStreamingChatService implements IChatService {
|
|||||||
@Override
|
@Override
|
||||||
public void onError(Throwable error) {
|
public void onError(Throwable error) {
|
||||||
log.error("{}流式响应错误: {}", getProviderName(), error.getMessage(), error);
|
log.error("{}流式响应错误: {}", getProviderName(), error.getMessage(), error);
|
||||||
|
|
||||||
|
// 发送错误消息到前端
|
||||||
|
try {
|
||||||
|
String errorMessage = String.format("模型调用失败: %s", error.getMessage());
|
||||||
|
SseMessageUtils.sendMessage(userId, errorMessage);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("发送错误消息失败: {}", e.getMessage(), e);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 关闭SSE连接,避免前端一直等待
|
||||||
|
try {
|
||||||
|
SseMessageUtils.completeConnection(userId, tokenValue);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("关闭SSE连接失败: {}", e.getMessage(), e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user