From 07cb351807a09c499d659594bae0ea8d07a2958f Mon Sep 17 00:00:00 2001 From: likunlong Date: Tue, 19 Aug 2025 10:32:17 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=A0=B9=E6=8D=AE=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E6=9C=89=E9=99=84=E4=BB=B6=E5=92=8C=E6=98=AF=E5=90=A6=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=EF=BC=8C=E8=87=AA=E5=8A=A8=E9=80=89=E6=8B=A9=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=E5=B9=B6=E4=B8=94=E8=8E=B7=E5=8F=96=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ruoyi/common/chat/request/ChatRequest.java | 10 ++++++++++ .../chat/service/chat/impl/SseServiceImpl.java | 15 ++++++--------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/ruoyi-common/ruoyi-common-chat/src/main/java/org/ruoyi/common/chat/request/ChatRequest.java b/ruoyi-common/ruoyi-common-chat/src/main/java/org/ruoyi/common/chat/request/ChatRequest.java index 20a021de..276f5dc8 100644 --- a/ruoyi-common/ruoyi-common-chat/src/main/java/org/ruoyi/common/chat/request/ChatRequest.java +++ b/ruoyi-common/ruoyi-common-chat/src/main/java/org/ruoyi/common/chat/request/ChatRequest.java @@ -67,4 +67,14 @@ public class ChatRequest { */ private Long uuid; + /** + * 是否有附件 + */ + private Boolean hasAttachment; + + /** + * 是否自动切换模型 + */ + private Boolean autoSelectModel; + } 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 e0d72866..6dfa302a 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 @@ -128,23 +128,20 @@ public class SseServiceImpl implements ISseService { */ private IChatService autoSelectModelAndGetService(ChatRequest chatRequest) { try { - // 处理特殊模型类型 - if ("gpt-image".equals(chatRequest.getModel())) { + if (Boolean.TRUE.equals(chatRequest.getHasAttachment())) { chatModelVo = selectModelByCategory("image"); - return chatServiceFactory.getChatService(chatModelVo.getCategory()); + } else if (Boolean.TRUE.equals(chatRequest.getAutoSelectModel())) { + chatModelVo = selectModelByCategory("chat"); + } else { + chatModelVo = chatModelService.selectModelByName(chatRequest.getModel()); } - // 根据模型名称获取模型分类,然后获取该分类下优先级最高的模型 - ChatModelVo tempModel = chatModelService.selectModelByName(chatRequest.getModel()); - if (tempModel == null) { + if (chatModelVo == null) { throw new IllegalStateException("未找到模型名称:" + chatRequest.getModel()); } - chatModelVo = selectModelByCategory(tempModel.getCategory()); - // 直接返回对应的聊天服务 return chatServiceFactory.getChatService(chatModelVo.getCategory()); - } catch (Exception e) { log.error("模型选择和服务获取失败: {}", e.getMessage(), e); throw new IllegalStateException("模型选择和服务获取失败: " + e.getMessage());