zhenghao 5 miesięcy temu
rodzic
commit
7f3a7828fb

+ 18 - 1
src/main/java/cn/jlsxwkj/common/config/UserConfig.java

@@ -12,11 +12,28 @@ import org.springframework.stereotype.Component;
 @Data
 public class UserConfig {
 
+    /**
+     * 用户自定义属性前缀
+     */
     public static final String USER_PREFIX = "customer";
-
+    /**
+     * ocr 地址
+     */
     private String cnocrUrl;
+    /**
+     * 指定的 chat 系统消息
+     */
     private String sysMessage;
+    /**
+     * 消息列表最大长度
+     */
     private Integer maxListMessageLength;
+    /**
+     * 机器人每条消息最大长度, 超过会截取
+     */
     private Integer maxMessageLength;
+    /**
+     * 打印 api 大于指定执行时间
+     */
     private Integer execTime;
 }

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

@@ -30,7 +30,7 @@ public class GlobalRestExceptionHandler {
      * @return 封装异常对象
      */
     @ExceptionHandler(Throwable.class)
-    public ResponseError exception(Exception e) {
+    public ResponseError exception(Throwable e) {
 
         ResponseError responseError = ResponseError.data(e.getClass().getName());
 

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

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

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

@@ -117,9 +117,14 @@ public class ChatService {
      * @param file    文件
      * @return 内容总结
      */
-    public Flux<String> chatSummaryStream(String message, MultipartFile file) throws CustomException {
+    public Flux<String> chatSummaryStream(String message, MultipartFile file) {
         embeddingModel.embed("");
-        Tuple supportFile = isSupportFile(file);
+        Tuple supportFile;
+        try {
+            supportFile = isSupportFile(file);
+        } catch (CustomException e) {
+            return Flux.just(e.getMessage()).concatWithValues("<{完成}>");
+        }
         String fileName = supportFile.get(1);
         String fileTypeCn = supportFile.get(2);
         DocumentReader reader = supportFile.get(3);
@@ -148,7 +153,7 @@ public class ChatService {
      * @param context 提示词
      * @return 提示词
      */
-    private Prompt getChatPrompt2String(String message, Message context) {
+    private Prompt getChatPrompt(String message, Message context) {
         if (listMessage == null) {
             listMessage = new ArrayList<>();
             listMessage.add(new SystemMessage(userConfig.getSysMessage()));
@@ -191,7 +196,7 @@ public class ChatService {
     private Flux<String> stream(String message, Message context) {
         String userId = SaManager.getStpLogic("").getLoginIdAsString();
         chatMessage = new StringBuffer();
-        Flux<ChatResponse> stream = ollamaChatModel.stream(getChatPrompt2String(message, context));
+        Flux<ChatResponse> stream = ollamaChatModel.stream(getChatPrompt(message, context));
         return stream.doOnSubscribe(subscription -> this.subscription = subscription).map(
                 response -> {
                     String str = response.getResult().getOutput().getContent();