mirror of
https://gitcode.com/ageerle/ruoyi-ai.git
synced 2026-03-13 20:53:42 +08:00
feat: 根据是否有附件和是否自动,自动选择模型并且获取服务;
This commit is contained in:
@@ -67,4 +67,14 @@ public class ChatRequest {
|
||||
*/
|
||||
private Long uuid;
|
||||
|
||||
/**
|
||||
* 是否有附件
|
||||
*/
|
||||
private Boolean hasAttachment;
|
||||
|
||||
/**
|
||||
* 是否自动切换模型
|
||||
*/
|
||||
private Boolean autoSelectModel;
|
||||
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user