feat: 根据是否有附件和是否自动,自动选择模型并且获取服务;

This commit is contained in:
likunlong
2025-08-19 10:32:17 +08:00
parent 8751bb5104
commit 07cb351807
2 changed files with 16 additions and 9 deletions

View File

@@ -67,4 +67,14 @@ public class ChatRequest {
*/ */
private Long uuid; private Long uuid;
/**
* 是否有附件
*/
private Boolean hasAttachment;
/**
* 是否自动切换模型
*/
private Boolean autoSelectModel;
} }

View File

@@ -128,23 +128,20 @@ public class SseServiceImpl implements ISseService {
*/ */
private IChatService autoSelectModelAndGetService(ChatRequest chatRequest) { private IChatService autoSelectModelAndGetService(ChatRequest chatRequest) {
try { try {
// 处理特殊模型类型 if (Boolean.TRUE.equals(chatRequest.getHasAttachment())) {
if ("gpt-image".equals(chatRequest.getModel())) {
chatModelVo = selectModelByCategory("image"); chatModelVo = selectModelByCategory("image");
return chatServiceFactory.getChatService(chatModelVo.getCategory()); } else if (Boolean.TRUE.equals(chatRequest.getAutoSelectModel())) {
chatModelVo = selectModelByCategory("chat");
} else {
chatModelVo = chatModelService.selectModelByName(chatRequest.getModel());
} }
// 根据模型名称获取模型分类,然后获取该分类下优先级最高的模型 if (chatModelVo == null) {
ChatModelVo tempModel = chatModelService.selectModelByName(chatRequest.getModel());
if (tempModel == null) {
throw new IllegalStateException("未找到模型名称:" + chatRequest.getModel()); throw new IllegalStateException("未找到模型名称:" + chatRequest.getModel());
} }
chatModelVo = selectModelByCategory(tempModel.getCategory());
// 直接返回对应的聊天服务 // 直接返回对应的聊天服务
return chatServiceFactory.getChatService(chatModelVo.getCategory()); return chatServiceFactory.getChatService(chatModelVo.getCategory());
} catch (Exception e) { } catch (Exception e) {
log.error("模型选择和服务获取失败: {}", e.getMessage(), e); log.error("模型选择和服务获取失败: {}", e.getMessage(), e);
throw new IllegalStateException("模型选择和服务获取失败: " + e.getMessage()); throw new IllegalStateException("模型选择和服务获取失败: " + e.getMessage());