From 84b8d6f675c2f3aed83e0503e79cf1fa05e888e5 Mon Sep 17 00:00:00 2001
From: ageer <ageerle@163.com>
Date: 星期日, 11 五月 2025 17:25:02 +0800
Subject: [PATCH] feat: 支持coze,dify,派欧云等三方模型调用

---
 ruoyi-modules/ruoyi-chat/src/main/java/org/ruoyi/chat/service/chat/impl/SseServiceImpl.java |   20 +++++---------------
 1 files changed, 5 insertions(+), 15 deletions(-)

diff --git a/ruoyi-modules/ruoyi-chat/src/main/java/org/ruoyi/chat/service/chat/impl/SseServiceImpl.java b/ruoyi-modules/ruoyi-chat/src/main/java/org/ruoyi/chat/service/chat/impl/SseServiceImpl.java
index c12ed44..cc5f289 100644
--- a/ruoyi-modules/ruoyi-chat/src/main/java/org/ruoyi/chat/service/chat/impl/SseServiceImpl.java
+++ b/ruoyi-modules/ruoyi-chat/src/main/java/org/ruoyi/chat/service/chat/impl/SseServiceImpl.java
@@ -8,7 +8,9 @@
 import lombok.extern.slf4j.Slf4j;
 import okhttp3.ResponseBody;
 import org.ruoyi.chat.enums.ChatModeType;
+import org.ruoyi.chat.factory.ChatServiceFactory;
 import org.ruoyi.chat.service.chat.IChatCostService;
+import org.ruoyi.chat.service.chat.IChatService;
 import org.ruoyi.chat.service.chat.ISseService;
 import org.ruoyi.chat.util.IpUtil;
 import org.ruoyi.chat.util.SSEUtil;
@@ -61,9 +63,7 @@
 
     private final IChatModelService chatModelService;
 
-    private final OpenAIServiceImpl openAIService;
-
-    private final OllamaServiceImpl ollamaService;
+    private final ChatServiceFactory chatServiceFactory;
 
     private final IChatSessionService chatSessionService;
 
@@ -95,7 +95,8 @@
                 chatCostService.deductToken(chatRequest);
             }
             // 鏍规嵁妯″瀷鍒嗙被璋冪敤涓嶅悓鐨勫鐞嗛�昏緫
-            switchModelAndHandle(chatRequest,sseEmitter);
+            IChatService chatService = chatServiceFactory.getChatService(chatModelVo.getCategory());
+            chatService.chat(chatRequest, sseEmitter);
         } catch (Exception e) {
             log.error(e.getMessage(),e);
             SSEUtil.sendErrorEvent(sseEmitter,e.getMessage());
@@ -147,17 +148,6 @@
             }
     }
 
-    /**
-     *  鏍规嵁妯″瀷鍚嶇О鍓嶇紑璋冪敤涓嶅悓鐨勫鐞嗛�昏緫
-     */
-    private void switchModelAndHandle(ChatRequest chatRequest,SseEmitter emitter) {
-        // 璋冪敤ollama涓儴缃茬殑鏈湴妯″瀷
-        if (ChatModeType.OLLAMA.getCode().equals(chatModelVo.getCategory())) {
-            ollamaService.chat(chatRequest,emitter);
-        } else {
-            openAIService.chat(chatRequest,emitter);
-        }
-    }
 
     /**
      *  鏋勫缓娑堟伅鍒楄〃

--
Gitblit v1.9.3