【优化】处理 AI stream 返回,改为 map

This commit is contained in:
cherishsince 2024-05-24 14:27:08 +08:00
parent e39513c6b2
commit f0e4e535f4

View File

@ -136,7 +136,7 @@ public class AiChatMessageServiceImpl implements AiChatMessageService {
// 3.3 流式返回
// 注意Schedulers.immediate() 目的是避免默认 Schedulers.parallel() 并发消费 chunk 导致 SSE 响应前端会乱序问题
StringBuffer contentBuffer = new StringBuffer();
return streamResponse.publishOn(Schedulers.single()).map(chunk -> {
return streamResponse.map(chunk -> {
String newContent = chunk.getResult() != null ? chunk.getResult().getOutput().getContent() : null;
newContent = StrUtil.nullToDefault(newContent, ""); // 避免 null 情况
contentBuffer.append(newContent);