tsurumure 5 месяцев назад
Родитель
Сommit
3f0618a5f7

+ 1 - 1
db/ai_chat_model.sql

@@ -16,7 +16,7 @@ CREATE TABLE `ai_chat_model` (
 ) ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='AI助手模型表';
 
 INSERT INTO ai_chat_model(id, parent_id, label, value, disabled, status) VALUES
-    (1, -1, 'DeepSeek R1', 'DEEPSEEK', -1, 1),
+    (1, -1, 'DeepSeek R1', 'DEEPSEEK_R1', -1, 1),
         (2, 1, 'deepseek-r1:1.5b', 'deepseek-r1:1.5b', -1, 1),
         (3, 1, 'deepseek-r1:70b', 'deepseek-r1:70b', -1, 1),
         (4, 1, 'deepseek-r1:671b', 'deepseek-r1:671b', 1, 1),

+ 33 - 29
src/main/java/com/backendsys/modules/ai/chat/service/impl/ChatServiceImpl.java

@@ -122,16 +122,14 @@ public class ChatServiceImpl implements ChatService {
                 );
                 System.out.println("chatList size: " + chatList.size());
 
-
                 // [INSERT][提问] 内容
                 Chat userChat = new Chat();
                 BeanUtil.copyProperties(chat, userChat);
                 chatDao.insert(userChat);
 
-
                 ChatResult chatResult = null;
                 // -- [Deepseek R1] -------------------------------------------------------
-                if ("DEEPSEEK".equals(model) || "GEMMA".equals(model)) {
+                if ("DEEPSEEK_R1".equals(model) || "GEMMA".equals(model)) {
                     chatResult = ollamaUtil.chatDeepSeek(user_id, model_version, prompt, final_history_code, chatList);
                 }
                 // -- [Deepseek Api] ------------------------------------------------------
@@ -145,32 +143,38 @@ public class ChatServiceImpl implements ChatService {
                 }
                 // ------------------------------------------------------------------------
 
-                // [INSERT][思考] THINK
-                String reasoningContent = chatResult.getReasoning_content();
-                if (StrUtil.isNotEmpty(reasoningContent)) {
-                    //
-                    Chat thinkChat = new Chat();
-                    BeanUtil.copyProperties(chat, thinkChat);
-                    //
-                    thinkChat.setRole("assistant");
-                    thinkChat.setContent_type("THINK");
-                    thinkChat.setContent(reasoningContent);
-                    thinkChat.setDuration(chatResult.getReasoning_duration());
-                    chatDao.insert(thinkChat);
-                }
-
-                // [INSERT][回复] REPLY
-                String content = chatResult.getContent();
-                if (StrUtil.isNotEmpty(content)) {
-                    //
-                    Chat replyChat = new Chat();
-                    BeanUtil.copyProperties(chat, replyChat);
-                    //
-                    replyChat.setRole("assistant");
-                    replyChat.setContent_type("REPLY");
-                    replyChat.setContent(content);
-                    replyChat.setDuration(chatResult.getContent_duration());
-                    chatDao.insert(replyChat);
+                if (chatResult != null) {
+
+                    // [INSERT][思考] THINK
+                    String reasoningContent = chatResult.getReasoning_content();
+                    if (StrUtil.isNotEmpty(reasoningContent)) {
+                        //
+                        Chat thinkChat = new Chat();
+                        BeanUtil.copyProperties(chat, thinkChat);
+                        //
+                        thinkChat.setRole("assistant");
+                        thinkChat.setContent_type("THINK");
+                        thinkChat.setContent(reasoningContent);
+                        thinkChat.setDuration(chatResult.getReasoning_duration());
+                        chatDao.insert(thinkChat);
+                    }
+
+                    // [INSERT][回复] REPLY
+                    String content = chatResult.getContent();
+                    if (StrUtil.isNotEmpty(content)) {
+                        //
+                        Chat replyChat = new Chat();
+                        BeanUtil.copyProperties(chat, replyChat);
+                        //
+                        replyChat.setRole("assistant");
+                        replyChat.setContent_type("REPLY");
+                        replyChat.setContent(content);
+                        replyChat.setDuration(chatResult.getContent_duration());
+                        chatDao.insert(replyChat);
+                    }
+
+                } else {
+                    System.out.println("chatResult 结果为空! 请检查当前 (model: " + model + ") 是否正确");
                 }