zhenghao 5 miesięcy temu
rodzic
commit
5276f8a04b

+ 5 - 0
README.md

@@ -16,6 +16,11 @@ ollama (linux环境)
   <localRepository>存储文件目录(如D:/repo)</localRepository>
   <mirrors>
     <mirror>
+      <id>public</id>
+      <url>https://maven.aliyun.com/repository/public</url>
+      <mirrorOf>public,!bladex</mirrorOf>
+    </mirror>
+    <mirror>
       <id>central</id>
       <url>https://maven.aliyun.com/repository/central</url>
       <mirrorOf>central,!bladex</mirrorOf>

+ 1 - 1
pom.xml

@@ -4,7 +4,7 @@
 	<parent>
 		<groupId>org.springframework.boot</groupId>
 		<artifactId>spring-boot-starter-parent</artifactId>
-		<version>3.3.1</version>
+		<version>3.3.2</version>
 		<relativePath/>
 	</parent>
 	<groupId>cn.jlsxwkj</groupId>

+ 2 - 0
src/main/java/cn/jlsxwkj/RagChatApplication.java

@@ -3,11 +3,13 @@ package cn.jlsxwkj;
 import cn.jlsxwkj.common.utils.Log;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.scheduling.annotation.EnableAsync;
 
 /**
  * @author zh
  */
 @SpringBootApplication
+@EnableAsync
 public class RagChatApplication {
 
 	public static void main(String[] args) {

+ 15 - 0
src/main/java/cn/jlsxwkj/common/dao/Dao.java

@@ -0,0 +1,15 @@
+package cn.jlsxwkj.common.dao;
+
+import lombok.Data;
+
+/**
+ * @author zh
+ */
+@Data
+public class Dao {
+
+    private Long id;
+    private java.sql.Timestamp createTime;
+    private java.sql.Timestamp updateTime;
+    private Integer isDeleted;
+}

+ 11 - 11
src/main/java/cn/jlsxwkj/common/handler/GlobalRestExceptionHandler.java

@@ -29,30 +29,30 @@ public class GlobalRestExceptionHandler {
      */
     @ExceptionHandler(Throwable.class)
     public ResponseError exception(Exception e) {
-        ResponseError errorHandler = ResponseError.data(e.getClass().getName());
+        ResponseError responseError = ResponseError.data(e.getClass().getName());
 
         if (e instanceof CustomException) {
-            errorHandler.setMessage(e.getMessage());
+            responseError.setMessage(e.getMessage());
         }
         if (e instanceof ErrorResponse) {
-            errorHandler.setCode(((ErrorResponse)e).getStatusCode().value());
-            errorHandler.setMessage(e.getMessage());
+            responseError.setCode(((ErrorResponse)e).getStatusCode().value());
+            responseError.setMessage(e.getMessage());
         }
         if (e instanceof SaTokenException) {
-            errorHandler.setCode(((SaTokenException)e).getCode());
-            errorHandler.setMessage("账户未登录");
+            responseError.setCode(((SaTokenException)e).getCode());
+            responseError.setMessage("账户未登录");
         }
 
-        LogError errorHandlerToLogError = new LogError().castErrorHandlerToLogError(errorHandler);
+        LogError errorHandlerToLogError = new LogError().castResponseErrorToLogError(responseError);
         errorHandlerToLogError.setErrorInfo(e.getMessage());
         errorHandlerToLogError.setErrorStackTrace(Arrays.toString(e.getStackTrace()));
         logErrorService.insertOne(errorHandlerToLogError);
 
-        Log.error(e.getClass(), "Code       ====> {}", errorHandler.getCode());
-        Log.error(e.getClass(), "Exception  ====> {}", errorHandler.getException());
-        Log.error(e.getClass(), "Message    ====> {}", errorHandler.getMessage());
+        Log.error(e.getClass(), "Code       ====> {}", responseError.getCode());
+        Log.error(e.getClass(), "Exception  ====> {}", responseError.getException());
+        Log.error(e.getClass(), "Message    ====> {}", responseError.getMessage());
         Log.error(e.getClass(), "ErrInfo    ====> {}", e.getMessage());
 
-        return errorHandler;
+        return responseError;
     }
 }

+ 0 - 3
src/main/java/cn/jlsxwkj/common/handler/ResultResponseHandler.java

@@ -53,9 +53,6 @@ public class ResultResponseHandler implements ResponseBodyAdvice<Object> {
                 Log.error(e.getClass(), Arrays.toString(e.getStackTrace()));
             }
         }
-        if (null == o) {
-            return null;
-        }
         return ResponseSucceed.data(o);
     }
 }

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

@@ -143,15 +143,14 @@ public class ChatService {
 		//查询获取文档信息
 		String content = search(message);
 		//封装prompt并调用大模型
-		Prompt chatPrompt2String = getChatPrompt2String(message, content);
-		return ollamaChatModel.stream(chatPrompt2String).map(
-				response -> {
+		return ollamaChatModel.stream(getChatPrompt2String(message, content))
+				.map(response -> {
 					String str = response.getResult().getOutput().getContent();
 					System.out.print(str);
 					chatMessage.append(str);
 					return str.replace(" ", "  ");
 				}).concatWithValues("<{完成}>")
-				.onErrorStop()
+				.onErrorComplete()
 				.doOnComplete(() -> {
 					System.out.println();
 					LIST_MESSAGE.add(new AssistantMessage(chatMessage.toString()));

+ 4 - 3
src/main/java/cn/jlsxwkj/moudles/chathistory/ChatHistory.java

@@ -1,17 +1,18 @@
 package cn.jlsxwkj.moudles.chathistory;
 
+import cn.jlsxwkj.common.dao.Dao;
 import lombok.Data;
+import lombok.EqualsAndHashCode;
 
 /**
  * @author zh
  */
+@EqualsAndHashCode(callSuper = true)
 @Data
-public class ChatHistory {
+public class ChatHistory extends Dao {
 
-  private Long id;
   private String userId;
   private String userQ;
   private String chatA;
-  private java.sql.Timestamp createTime;
 
 }

+ 5 - 4
src/main/java/cn/jlsxwkj/moudles/logerror/LogError.java

@@ -1,22 +1,23 @@
 package cn.jlsxwkj.moudles.logerror;
 
 import cn.jlsxwkj.common.R.ResponseError;
+import cn.jlsxwkj.common.dao.Dao;
 import lombok.Data;
+import lombok.EqualsAndHashCode;
 
 /**
  * @author zh
  */
+@EqualsAndHashCode(callSuper = true)
 @Data
-public class LogError {
+public class LogError extends Dao {
 
-    private long id;
     private String exception;
     private String message;
     private String errorInfo;
     private String errorStackTrace;
-    private java.sql.Timestamp createTime;
 
-    public LogError castErrorHandlerToLogError(ResponseError errorHandler) {
+    public LogError castResponseErrorToLogError(ResponseError errorHandler) {
         this.setMessage(errorHandler.getMessage());
         this.setException(errorHandler.getException());
         return this;

+ 4 - 2
src/main/java/cn/jlsxwkj/moudles/userlist/UserList.java

@@ -1,13 +1,15 @@
 package cn.jlsxwkj.moudles.userlist;
 
+import cn.jlsxwkj.common.dao.Dao;
 import lombok.Data;
+import lombok.EqualsAndHashCode;
 
 /**
  * @author zh
  */
+@EqualsAndHashCode(callSuper = true)
 @Data
-public class UserList {
-    private Long id;
+public class UserList extends Dao {
     private String userId;
     private String userName;
     private String userPassword;

+ 1 - 1
src/main/resources/application-dev.yml

@@ -11,6 +11,6 @@ spring:
     ollama:
       base-url: http://localhost:11434
       chat:
-        model: qwen2:1.5b
+        model: qwen2:7b
       embedding:
         model: mofanke/dmeta-embedding-zh