Merge pull request #175 from LM20230311/feat-model-priority

Feat model priority:支持自动选择模型;支持模型的重试;
This commit is contained in:
evo
2025-08-20 14:04:17 +08:00
committed by GitHub
23 changed files with 618 additions and 95 deletions

View File

@@ -76,6 +76,11 @@ public class ChatModel extends BaseEntity {
*/
private String apiKey;
/**
* 优先级
*/
private Integer priority;
/**
* 备注
*/

View File

@@ -74,6 +74,11 @@ public class ChatModelBo extends BaseEntity {
@NotBlank(message = "请求地址不能为空", groups = { AddGroup.class, EditGroup.class })
private String apiHost;
/**
* 优先级
*/
private Integer priority;
/**
* 密钥
*/

View File

@@ -90,6 +90,12 @@ public class ChatModelVo implements Serializable {
@ExcelProperty(value = "密钥")
private String apiKey;
/**
* 优先级(值越大优先级越高)
*/
@ExcelProperty(value = "优先级")
private Integer priority;
/**
* 备注
*/

View File

@@ -57,6 +57,17 @@ public interface IChatModelService {
* 通过模型分类获取模型信息
*/
ChatModelVo selectModelByCategory(String image);
/**
* 通过模型分类获取优先级最高的模型信息
*/
ChatModelVo selectModelByCategoryWithHighestPriority(String category);
/**
* 在同一分类下,查找优先级小于当前优先级的最高优先级模型(用于降级)。
*/
ChatModelVo selectFallbackModelByCategoryAndLessPriority(String category, Integer currentPriority);
/**
* 获取ppt模型信息
*/

View File

@@ -136,6 +136,33 @@ public class ChatModelServiceImpl implements IChatModelService {
public ChatModelVo selectModelByCategory(String category) {
return baseMapper.selectVoOne(Wrappers.<ChatModel>lambdaQuery().eq(ChatModel::getCategory, category));
}
/**
* 通过模型分类获取优先级最高的模型信息
*/
@Override
public ChatModelVo selectModelByCategoryWithHighestPriority(String category) {
return baseMapper.selectVoOne(
Wrappers.<ChatModel>lambdaQuery()
.eq(ChatModel::getCategory, category)
.orderByDesc(ChatModel::getPriority)
.last("LIMIT 1")
);
}
/**
* 在同一分类下,查找优先级小于当前优先级的最高优先级模型(用于降级)。
*/
@Override
public ChatModelVo selectFallbackModelByCategoryAndLessPriority(String category, Integer currentPriority) {
return baseMapper.selectVoOne(
Wrappers.<ChatModel>lambdaQuery()
.eq(ChatModel::getCategory, category)
.lt(ChatModel::getPriority, currentPriority)
.orderByDesc(ChatModel::getPriority)
.last("LIMIT 1")
);
}
@Override
public ChatModel getPPT() {