STT 数据流处理-试一下合并后的格式
This commit is contained in:
@@ -100,6 +100,7 @@ public class OpenAiStreamClient {
|
|||||||
// 检查是否为结束标记
|
// 检查是否为结束标记
|
||||||
if (data.equals("[DONE]")) {
|
if (data.equals("[DONE]")) {
|
||||||
listener.onMessage(bufferStr.toString());
|
listener.onMessage(bufferStr.toString());
|
||||||
|
bufferStr.replace(0, bufferStr.length(), "");
|
||||||
listener.onComplete();
|
listener.onComplete();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -113,19 +114,12 @@ public class OpenAiStreamClient {
|
|||||||
.getStr("content");
|
.getStr("content");
|
||||||
|
|
||||||
if (content != null && !content.isEmpty()) {
|
if (content != null && !content.isEmpty()) {
|
||||||
if(punctuationStr.contains(content)){
|
//加入缓冲区
|
||||||
//说明有标点啦,直接返回
|
|
||||||
bufferStr.append(content);
|
bufferStr.append(content);
|
||||||
|
if(punctuationStr.contains(content.trim())){
|
||||||
|
//说明有标点啦,直接返回
|
||||||
listener.onMessage(bufferStr.toString());
|
listener.onMessage(bufferStr.toString());
|
||||||
bufferStr.replace(0, bufferStr.length(), "");
|
bufferStr.replace(0, bufferStr.length(), "");
|
||||||
// bufferStr = new StringBuffer();
|
|
||||||
}else{
|
|
||||||
//加入缓冲区
|
|
||||||
if(StrUtil.isEmpty(bufferStr.toString())){
|
|
||||||
bufferStr.append(content);
|
|
||||||
}else {
|
|
||||||
bufferStr.append(" ").append(content);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// listener.onMessage(content);
|
// listener.onMessage(content);
|
||||||
|
|||||||
Reference in New Issue
Block a user