|
@@ -112,6 +112,7 @@ public class OllamaUtil {
|
|
|
String content = resJson.getString("response");
|
|
|
|
|
|
// System.out.println("content: " + content);
|
|
|
+ // content: \n\n
|
|
|
// content: <think>
|
|
|
// content: </think>
|
|
|
|
|
@@ -127,21 +128,20 @@ public class OllamaUtil {
|
|
|
System.out.println("推理耗时: " + thinkDuration + "毫秒");
|
|
|
System.out.println("-----------------------------------------------");
|
|
|
|
|
|
- // [SSE] 发送消息
|
|
|
- ChatSseMessage chatSseMessage = new ChatSseMessage("THINK", "[DONE][THINK]", thinkDuration);
|
|
|
- sseUtil.send(user_id, new SseResponse(SseResponseEnum.DEEPSEEK, chatSseMessage).toJsonStr());
|
|
|
+ if (allThinkContent.length() > 0){
|
|
|
+ // [SSE] 发送消息
|
|
|
+ ChatSseMessage chatSseMessage = new ChatSseMessage("THINK", "[DONE][THINK]", thinkDuration);
|
|
|
+ sseUtil.send(user_id, new SseResponse(SseResponseEnum.DEEPSEEK, chatSseMessage).toJsonStr());
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
// [思考] Think
|
|
|
if (isThinking) {
|
|
|
- System.out.println("think: " + content);
|
|
|
-
|
|
|
- if (!content.contains("<think>") && !content.contains("\\n\\n")) {
|
|
|
+ if (!content.contains("<think>") && !content.contains("\n\n") && !content.contains("\n")) {
|
|
|
// [SSE] 发送消息
|
|
|
ChatSseMessage chatSseMessage = new ChatSseMessage("THINK", content);
|
|
|
sseUtil.send(user_id, new SseResponse(SseResponseEnum.DEEPSEEK, chatSseMessage).toJsonStr());
|
|
|
-
|
|
|
// 收集推理内容
|
|
|
allThinkContent.append(content);
|
|
|
}
|
|
@@ -150,14 +150,18 @@ public class OllamaUtil {
|
|
|
// [回答] Reply
|
|
|
if (!isThinking) {
|
|
|
System.out.println("content: " + content);
|
|
|
+ if (!content.contains("</think>") && !content.contains("\n\n")) {
|
|
|
|
|
|
- if (!content.contains("</think>") && !content.contains("\\n\\n")) {
|
|
|
- // [SSE] 发送消息
|
|
|
- ChatSseMessage chatSseMessage = new ChatSseMessage("REPLY", content);
|
|
|
- sseUtil.send(user_id, new SseResponse(SseResponseEnum.DEEPSEEK, chatSseMessage).toJsonStr());
|
|
|
+ Boolean done = resJson.getBoolean("done");
|
|
|
+ if (!done) {
|
|
|
|
|
|
- // 收集回答内容
|
|
|
- allReplyContent.append(content);
|
|
|
+ // [SSE] 发送消息
|
|
|
+ ChatSseMessage chatSseMessage = new ChatSseMessage("REPLY", content);
|
|
|
+ sseUtil.send(user_id, new SseResponse(SseResponseEnum.DEEPSEEK, chatSseMessage).toJsonStr());
|
|
|
+ // 收集回答内容
|
|
|
+ allReplyContent.append(content);
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -172,10 +176,10 @@ public class OllamaUtil {
|
|
|
System.out.println("总输出耗时: " + contentDuration + " 毫秒");
|
|
|
|
|
|
System.out.println("-----");
|
|
|
- System.out.println("Think content: " + allThinkContent.toString());
|
|
|
- System.out.println("Think content length: " + allThinkContent.toString().length());
|
|
|
- System.out.println("Think content is not empty: " + StrUtil.isNotEmpty(allThinkContent.toString()));
|
|
|
- System.out.println("-----");
|
|
|
+// System.out.println("Think content: " + allThinkContent.toString());
|
|
|
+// System.out.println("Think content length: " + allThinkContent.toString().length());
|
|
|
+// System.out.println("Think content is not empty: " + StrUtil.isNotEmpty(allThinkContent.toString()));
|
|
|
+// System.out.println("-----");
|
|
|
|
|
|
if (StrUtil.isNotEmpty(allThinkContent.toString())) {
|
|
|
chatResult.setReasoning_content(allThinkContent.toString());
|