|
@@ -88,6 +88,7 @@ public class OllamaUtil {
|
|
|
System.out.println("---- 历史对话 (history_code): " + history_code + " ----");
|
|
|
|
|
|
List<DSRequestMessage> messages = new ArrayList<>();
|
|
|
+
|
|
|
if (chatList != null && !chatList.isEmpty()) {
|
|
|
chatList.stream().forEach(chat -> {
|
|
|
if (!"THINK".equals(chat.getContent_type())) {
|
|
@@ -98,10 +99,12 @@ public class OllamaUtil {
|
|
|
Collections.reverse(messages);
|
|
|
}
|
|
|
|
|
|
+ // 【要把搜索到的内容塞到 'user' 里?】
|
|
|
+
|
|
|
// -- [博查] Web Search API ----------------------------------------------
|
|
|
if (internet) {
|
|
|
|
|
|
- // 博查、统计接口时间、设置返回参数
|
|
|
+ // 远程查询、统计接口时间、设置返回参数
|
|
|
long internetStartTime = System.currentTimeMillis();
|
|
|
JsonNode searchResult = bochaService.WebSearch(new BochaParam(prompt));
|
|
|
String context = bochaService.WebSearchToString(searchResult);
|
|
@@ -111,6 +114,12 @@ public class OllamaUtil {
|
|
|
|
|
|
// 将搜索结果作为上下文添加到消息中
|
|
|
messages.add(new DSRequestMessage("system", context));
|
|
|
+ messages.add(new DSRequestMessage("user", "在回答时引用以上全部数据进行分析")); // 的 "name"、"summary"
|
|
|
+ messages.add(new DSRequestMessage("assistant", "好的"));
|
|
|
+
|
|
|
+ // [SSE] 发送消息
|
|
|
+ ChatSseMessage chatSearchSseMessage = new ChatSseMessage("SEARCH", context, null, history_code);
|
|
|
+ sseUtil.send(user_id, new SseResponse(SseResponseEnum.OLLAMA, chatSearchSseMessage).toJsonStr());
|
|
|
}
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
@@ -190,7 +199,7 @@ public class OllamaUtil {
|
|
|
|
|
|
// [SSE] 发送消息
|
|
|
ChatSseMessage chatLoadingSseMessage = new ChatSseMessage("LOADING", "正在思考", null, history_code);
|
|
|
- sseUtil.send(user_id, new SseResponse(SseResponseEnum.DEEPSEEK, chatLoadingSseMessage).toJsonStr());
|
|
|
+ sseUtil.send(user_id, new SseResponse(SseResponseEnum.OLLAMA, chatLoadingSseMessage).toJsonStr());
|
|
|
|
|
|
String line;
|
|
|
while ((line = reader.readLine()) != null) {
|
|
@@ -226,9 +235,9 @@ public class OllamaUtil {
|
|
|
String errJsonMessage = resJson.getString("error");
|
|
|
if (errJsonMessage != null) {
|
|
|
// [SSE] 发送消息
|
|
|
- sseUtil.send(user_id, new SseResponse(SseResponseEnum.DEEPSEEK, new ChatSseMessage("REPLY", errJsonMessage, contentDuration, history_code)).toJsonStr());
|
|
|
+ sseUtil.send(user_id, new SseResponse(SseResponseEnum.OLLAMA, new ChatSseMessage("REPLY", errJsonMessage, contentDuration, history_code)).toJsonStr());
|
|
|
// [SSE] 发送消息 (完成)
|
|
|
- sseUtil.send(user_id, new SseResponse(SseResponseEnum.DEEPSEEK, new ChatSseMessage("REPLY", "[DONE][REPLY]", contentDuration, history_code)).toJsonStr());
|
|
|
+ sseUtil.send(user_id, new SseResponse(SseResponseEnum.OLLAMA, new ChatSseMessage("REPLY", "[DONE][REPLY]", contentDuration, history_code)).toJsonStr());
|
|
|
//
|
|
|
chatResult.setContent(errJsonMessage);
|
|
|
return chatResult;
|
|
@@ -258,7 +267,7 @@ public class OllamaUtil {
|
|
|
if (allThinkContent.length() > 0){
|
|
|
// [SSE] 发送消息
|
|
|
ChatSseMessage chatSseMessage = new ChatSseMessage("THINK", "[DONE][THINK]", thinkDuration, history_code);
|
|
|
- sseUtil.send(user_id, new SseResponse(SseResponseEnum.DEEPSEEK, chatSseMessage).toJsonStr());
|
|
|
+ sseUtil.send(user_id, new SseResponse(SseResponseEnum.OLLAMA, chatSseMessage).toJsonStr());
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -268,7 +277,7 @@ public class OllamaUtil {
|
|
|
if (!content.contains("<think>") && !content.contains("\n\n") && !content.contains("\n")) {
|
|
|
// [SSE] 发送消息
|
|
|
ChatSseMessage chatSseMessage = new ChatSseMessage("THINK", content, null, history_code);
|
|
|
- sseUtil.send(user_id, new SseResponse(SseResponseEnum.DEEPSEEK, chatSseMessage).toJsonStr());
|
|
|
+ sseUtil.send(user_id, new SseResponse(SseResponseEnum.OLLAMA, chatSseMessage).toJsonStr());
|
|
|
// 收集推理内容
|
|
|
allThinkContent.append(content);
|
|
|
}
|
|
@@ -286,7 +295,7 @@ public class OllamaUtil {
|
|
|
|
|
|
// [SSE] 发送消息
|
|
|
ChatSseMessage chatSseMessage = new ChatSseMessage("REPLY", content, null, history_code);
|
|
|
- sseUtil.send(user_id, new SseResponse(SseResponseEnum.DEEPSEEK, chatSseMessage).toJsonStr());
|
|
|
+ sseUtil.send(user_id, new SseResponse(SseResponseEnum.OLLAMA, chatSseMessage).toJsonStr());
|
|
|
// 收集回答内容
|
|
|
allReplyContent.append(content);
|
|
|
|
|
@@ -325,7 +334,7 @@ public class OllamaUtil {
|
|
|
// [SSE] 发送消息
|
|
|
String contentType = (isThinking ? "THINK_ABORT" : "REPLY_ABORT");
|
|
|
ChatSseMessage chatSseMessage = new ChatSseMessage(contentType, message, contentDuration, history_code);
|
|
|
- sseUtil.send(user_id, new SseResponse(SseResponseEnum.DEEPSEEK, chatSseMessage).toJsonStr());
|
|
|
+ sseUtil.send(user_id, new SseResponse(SseResponseEnum.OLLAMA, chatSseMessage).toJsonStr());
|
|
|
|
|
|
// chatResult.setContent(e.getMessage());
|
|
|
|
|
@@ -350,7 +359,7 @@ public class OllamaUtil {
|
|
|
// [SSE] 发送消息
|
|
|
String contentType = (isThinking ? "THINK_ABORT" : "REPLY_ABORT");
|
|
|
ChatSseMessage chatSseMessage = new ChatSseMessage(contentType, e.getMessage(), contentDuration, history_code);
|
|
|
- sseUtil.send(user_id, new SseResponse(SseResponseEnum.DEEPSEEK, chatSseMessage).toJsonStr());
|
|
|
+ sseUtil.send(user_id, new SseResponse(SseResponseEnum.OLLAMA, chatSseMessage).toJsonStr());
|
|
|
|
|
|
redisUtil.delete(requestOfRedisKey);
|
|
|
|
|
@@ -360,7 +369,7 @@ public class OllamaUtil {
|
|
|
|
|
|
// [SSE] 发送消息 (完成)
|
|
|
ChatSseMessage chatSseMessage = new ChatSseMessage("REPLY", "[DONE][REPLY]", contentDuration, history_code);
|
|
|
- sseUtil.send(user_id, new SseResponse(SseResponseEnum.DEEPSEEK, chatSseMessage).toJsonStr());
|
|
|
+ sseUtil.send(user_id, new SseResponse(SseResponseEnum.OLLAMA, chatSseMessage).toJsonStr());
|
|
|
|
|
|
}
|
|
|
|