|
|
|
@ -17,6 +17,7 @@ import java.util.Objects;
|
|
|
|
|
import java.util.function.Consumer;
|
|
|
|
|
|
|
|
|
|
//update-begin---author:chenrui ---date:20240126 for:【QQYUN-7932】AI助手------------
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* OpenAI的SSE监听
|
|
|
|
|
* @author chenrui
|
|
|
|
@ -102,6 +103,11 @@ public class OpenAISSEEventSourceListener extends EventSourceListener {
|
|
|
|
|
try {
|
|
|
|
|
//update-begin---author:chenrui ---date:20250207 for:[QQYUN-11102/QQYUN-11109]兼容deepseek模型,支持think标签------------
|
|
|
|
|
// 兼容think标签
|
|
|
|
|
//update-begin---author:chenrui ---date:20250210 for:判断空,防止反悔的内容为空报错.------------
|
|
|
|
|
if(null != completionResponse.getChoices()
|
|
|
|
|
&& !completionResponse.getChoices().isEmpty()
|
|
|
|
|
&& null != completionResponse.getChoices().get(0)) {
|
|
|
|
|
//update-end---author:chenrui ---date:20250210 for:判断空,防止反悔的内容为空报错.------------
|
|
|
|
|
Message delta = completionResponse.getChoices().get(0).getDelta();
|
|
|
|
|
if (null != delta) {
|
|
|
|
|
String content = delta.getContent();
|
|
|
|
@ -124,18 +130,17 @@ public class OpenAISSEEventSourceListener extends EventSourceListener {
|
|
|
|
|
// 响应消息体不记录思考过程
|
|
|
|
|
messageContent += null == content ? "" : content;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log.info("ai-chat返回数据,发送给前端:" + content);
|
|
|
|
|
sseEmitter.send(SseEmitter.event()
|
|
|
|
|
.id(this.topicId)
|
|
|
|
|
.data(delta)
|
|
|
|
|
.reconnectTime(3000));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//update-end---author:chenrui ---date:20250207 for:[QQYUN-11102/QQYUN-11109]兼容deepseek模型,支持think标签------------
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error(e.getMessage(),e);
|
|
|
|
|
log.error("ai-chat返回数据,发生异常"+e.getMessage(),e);
|
|
|
|
|
sseEmitter.completeWithError(e);
|
|
|
|
|
eventSource.cancel();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|