Commit af716593 by zhangxingmin

push

parent 1f4a3464
......@@ -100,9 +100,23 @@ public class ApiAiStreamServiceImpl implements ApiAiStreamService {
// 将 RxJava Flowable 转为 Reactor Flux
return Flux.from(flowable)
.filter(result -> {
// 过滤掉空结果或没有内容的事件
return result != null
&& result.getOutput() != null
&& result.getOutput().getChoices() != null
&& !result.getOutput().getChoices().isEmpty()
&& result.getOutput().getChoices().get(0).getMessage() != null
&& result.getOutput().getChoices().get(0).getMessage().getContent() != null;
})
.map(result -> {
String delta = result.getOutput().getChoices().get(0).getMessage().getContent();
// 注意:不要对 delta 做额外处理,保持原样以保留 Markdown 格式
return ServerSentEvent.builder(delta).build();
})
.onErrorResume(e -> {
log.error("流式响应处理出错: {}", e.getMessage());
return Flux.just(ServerSentEvent.builder("系统繁忙,请稍后重试").build());
});
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment