瀏覽代碼

对无任何内容的返空, 对获取历史记录进行封装

zhenghao 5 月之前
父節點
當前提交
b9edf970a3

+ 5 - 3
src/main/java/cn/jlsxwkj/common/exception/AccountAuthFailException.java

@@ -5,9 +5,11 @@ package cn.jlsxwkj.common.exception;
  */
 public class AccountAuthFailException extends CustomException {
 
-    /**
-     * 注册失败
-     */
+    @SuppressWarnings("unused")
+    public AccountAuthFailException() {
+        super("注册失败");
+    }
+
     public AccountAuthFailException(String message) {
         super(message);
     }

+ 6 - 1
src/main/java/cn/jlsxwkj/common/exception/AccountPasswordCheckFailException.java

@@ -3,7 +3,12 @@ package cn.jlsxwkj.common.exception;
 /**
  * @author zh
  */
-public class AccountPasswordCheckFailException extends CustomException{
+public class AccountPasswordCheckFailException extends CustomException {
+
+    @SuppressWarnings("unused")
+    public AccountPasswordCheckFailException() {
+        super("用户密码检查未通过");
+    }
 
     public AccountPasswordCheckFailException(String message) {
         super(message);

+ 5 - 3
src/main/java/cn/jlsxwkj/common/exception/FileDeleteFailException.java

@@ -3,11 +3,13 @@ package cn.jlsxwkj.common.exception;
 /**
  * @author zh
  */
+@SuppressWarnings("unused")
 public class FileDeleteFailException extends CustomException {
 
-    /**
-     * 文件删除失败
-     */
+    public FileDeleteFailException() {
+        super("文件删除失败");
+    }
+
     public FileDeleteFailException(String message) {
         super(message);
     }

+ 5 - 3
src/main/java/cn/jlsxwkj/common/exception/FileTypeDoesNotSupportException.java

@@ -5,9 +5,11 @@ package cn.jlsxwkj.common.exception;
  */
 public class FileTypeDoesNotSupportException extends CustomException {
 
-    /**
-     * 文件类型不支持
-     */
+    @SuppressWarnings("unused")
+    public FileTypeDoesNotSupportException() {
+        super("文件类型不支持");
+    }
+
     public FileTypeDoesNotSupportException(String message) {
         super(message);
     }

+ 5 - 3
src/main/java/cn/jlsxwkj/common/exception/InsertFailException.java

@@ -5,9 +5,11 @@ package cn.jlsxwkj.common.exception;
  */
 public class InsertFailException extends CustomException {
 
-    /**
-     * 插入失败
-     */
+    @SuppressWarnings("unused")
+    public InsertFailException() {
+        super("插入失败");
+    }
+
     public InsertFailException(String message) {
         super(message);
     }

+ 5 - 3
src/main/java/cn/jlsxwkj/common/exception/LoginAccountAlreadyLoginException.java

@@ -5,9 +5,11 @@ package cn.jlsxwkj.common.exception;
  */
 public class LoginAccountAlreadyLoginException extends CustomException {
 
-    /**
-     * 重复登录
-     */
+    @SuppressWarnings("unused")
+    public LoginAccountAlreadyLoginException() {
+        super("重复登录");
+    }
+
     public LoginAccountAlreadyLoginException(String message) {
         super(message);
     }

+ 5 - 3
src/main/java/cn/jlsxwkj/common/exception/LoginWrongPasswordException.java

@@ -5,9 +5,11 @@ package cn.jlsxwkj.common.exception;
  */
 public class LoginWrongPasswordException extends CustomException {
 
-    /**
-     * 登录密码错误
-     */
+    @SuppressWarnings("unused")
+    public LoginWrongPasswordException() {
+        super("登录密码错误");
+    }
+
     public LoginWrongPasswordException(String message) {
         super(message);
     }

+ 16 - 0
src/main/java/cn/jlsxwkj/common/exception/NotContentInFileException.java

@@ -0,0 +1,16 @@
+package cn.jlsxwkj.common.exception;
+
+/**
+ * @author zh
+ */
+@SuppressWarnings("unused")
+public class NotContentInFileException extends CustomException {
+
+    public NotContentInFileException() {
+        super("文件中没有内容");
+    }
+
+    public NotContentInFileException(String message) {
+        super(message);
+    }
+}

+ 3 - 0
src/main/java/cn/jlsxwkj/common/utils/SplitDocument.java

@@ -28,6 +28,9 @@ public class SplitDocument {
     public static List<Document> splitStringToListDocument(String document,
                                                            int windowSize,
                                                            String fileName) {
+        if (document.isBlank()) {
+            return null;
+        }
         ArrayList<Document> readDocuments = new ArrayList<>();
         List<String> paragraphs = Arrays.stream(document.split("\n")).distinct().dropWhile(""::equals).collect(Collectors.toList());
         //采用窗口滑动读取

+ 1 - 1
src/main/java/cn/jlsxwkj/moudles/chat/ChatController.java

@@ -42,7 +42,7 @@ public class ChatController {
 
     @Operation(summary = "问答文档总结流")
     @PostMapping(value = "/chatSummaryStream", produces = {MediaType.TEXT_EVENT_STREAM_VALUE})
-    public Flux<String> chatSummaryStream(@RequestParam String message,
+    public Flux<String> chatSummaryStream(@RequestParam(defaultValue = "帮我总结一下") String message,
                                       @RequestBody MultipartFile file) throws CustomException {
         return chatService.chatSummaryStream(message, file);
     }

+ 5 - 3
src/main/java/cn/jlsxwkj/moudles/chat/ChatService.java

@@ -22,6 +22,7 @@ import org.springframework.ai.chat.model.ChatResponse;
 import org.springframework.ai.chat.prompt.Prompt;
 import org.springframework.ai.document.Document;
 import org.springframework.ai.document.DocumentReader;
+import org.springframework.ai.embedding.EmbeddingModel;
 import org.springframework.ai.ollama.OllamaChatModel;
 import org.springframework.ai.vectorstore.SearchRequest;
 import org.springframework.ai.vectorstore.VectorStore;
@@ -46,12 +47,14 @@ import java.util.stream.Collectors;
 public class ChatService {
 
     private static final MD5 MD5 = cn.hutool.crypto.digest.MD5.create();
-    private static final String PATH = Objects.requireNonNull(ChatService.class.getClassLoader().getResource("")).getPath() + "\\ai_doc\\";
+    private static final String PATH = System.getProperty("user.dir") + "/ai_doc/";
     private static final List<Message> LIST_MESSAGE = new ArrayList<>();
 
     @Resource
     private VectorStore vectorStore;
     @Resource
+    private EmbeddingModel embeddingModel;
+    @Resource
     private OllamaChatModel ollamaChatModel;
     @Resource
     private ChatHistoryService chatHistoryService;
@@ -117,12 +120,12 @@ public class ChatService {
      * @return 内容总结
      */
     public Flux<String> chatSummaryStream(String message, MultipartFile file) throws CustomException {
+        embeddingModel.embed("");
         Tuple supportFile = isSupportFile(file);
         String fileName = supportFile.get(1);
         String fileTypeCn = supportFile.get(2);
         DocumentReader reader = supportFile.get(3);
         String context = fileTypeCn + " : " + fileName + " ====> " + mergeDocuments(reader.get()).replace("\n", " ");
-        Log.info(this.getClass(), context);
         return stream(message, new UserMessage(context + " : " + message));
     }
 
@@ -146,7 +149,6 @@ public class ChatService {
      * @return 提示词
      */
     private Prompt getChatPrompt2String(String message, Message context) {
-        Log.info(this.getClass(), "{} message : {}", "user", message);
         ChatService.LIST_MESSAGE.add(new SystemMessage(userConfig.getSysMessage()));
         if (context.getMessageType().equals(MessageType.SYSTEM)) {
             ChatService.LIST_MESSAGE.add(new UserMessage(message));

+ 1 - 1
src/main/java/cn/jlsxwkj/moudles/chathistory/ChatHistoryController.java

@@ -20,7 +20,7 @@ public class ChatHistoryController {
 
     @Operation(summary = "获取历史对话")
     @GetMapping("/getHistory")
-    public List<ChatHistory> selectHistory() {
+    public List<ChatHistoryVO> selectHistory() {
         return chatHistoryService.selectHistoryByUserId();
     }
 }

+ 1 - 1
src/main/java/cn/jlsxwkj/moudles/chathistory/ChatHistoryMapper.java

@@ -29,5 +29,5 @@ public interface ChatHistoryMapper {
             order by create_time desc
             limit 20
             """)
-    List<ChatHistory> selectHistoryByUserId(@Param("userId") String userId);
+    List<ChatHistoryVO> selectHistoryByUserId(@Param("userId") String userId);
 }

+ 1 - 1
src/main/java/cn/jlsxwkj/moudles/chathistory/ChatHistoryService.java

@@ -25,7 +25,7 @@ public class ChatHistoryService {
         }
     }
 
-    public List<ChatHistory> selectHistoryByUserId() {
+    public List<ChatHistoryVO> selectHistoryByUserId() {
         String userId = SaManager.getStpLogic("").getLoginIdAsString();
         return chatHistoryMapper.selectHistoryByUserId(userId);
     }

+ 13 - 0
src/main/java/cn/jlsxwkj/moudles/chathistory/ChatHistoryVO.java

@@ -0,0 +1,13 @@
+package cn.jlsxwkj.moudles.chathistory;
+
+import lombok.Data;
+
+/**
+ * @author zh
+ */
+@Data
+public class ChatHistoryVO {
+    private String userId;
+    private String userQ;
+    private String chatA;
+}