feat: 完成模型库优化

This commit is contained in:
ccnetcore
2025-12-11 21:12:29 +08:00
parent 53e56134d4
commit a46a552097
3 changed files with 44 additions and 28 deletions

View File

@@ -1,4 +1,5 @@
using Yi.Framework.AiHub.Domain.Shared.Enums;
using Yi.Framework.AiHub.Domain.Shared.Extensions;
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.Model;
@@ -30,18 +31,14 @@ public class ModelLibraryDto
/// <summary>
/// 模型类型名称
/// </summary>
public string ModelTypeName { get; set; }
public string ModelTypeName => ModelType.GetDescription();
/// <summary>
/// 模型API类型
/// 模型支持的API类型
/// </summary>
public ModelApiTypeEnum ModelApiType { get; set; }
/// <summary>
/// 模型API类型名称
/// </summary>
public string ModelApiTypeName { get; set; }
public List<ModelApiTypeOutput> ModelApiTypes { get; set; }
/// <summary>
/// 模型显示倍率
/// </summary>
@@ -61,4 +58,22 @@ public class ModelLibraryDto
/// 是否为尊享模型PremiumChat类型
/// </summary>
public bool IsPremium { get; set; }
/// <summary>
/// 排序
/// </summary>
public int OrderNum { get; set; }
}
public class ModelApiTypeOutput
{
/// <summary>
/// 模型类型
/// </summary>
public ModelApiTypeEnum ModelApiType { get; set; }
/// <summary>
/// 模型类型名称
/// </summary>
public string ModelApiTypeName => ModelApiType.GetDescription();
}

View File

@@ -73,7 +73,7 @@ public class AiChatService : ApplicationService
{
var output = await _aiModelRepository._DbQueryable
.Where(x => x.ModelType == ModelTypeEnum.Chat)
.Where(x=>x.ModelApiType==ModelApiTypeEnum.OpenAi)
.Where(x => x.ModelApiType == ModelApiTypeEnum.OpenAi)
.OrderByDescending(x => x.OrderNum)
.Select(x => new ModelGetListOutput
{

View File

@@ -32,8 +32,7 @@ public class ModelService : ApplicationService, IModelService
RefAsync<int> total = 0;
// 查询所有未删除的模型使用WhereIF动态添加筛选条件
var models = await _modelRepository._DbQueryable
.Where(x => !x.IsDeleted)
var modelIds = (await _modelRepository._DbQueryable
.WhereIF(!string.IsNullOrWhiteSpace(input.SearchKey), x =>
x.Name.Contains(input.SearchKey) || x.ModelId.Contains(input.SearchKey))
.WhereIF(input.ProviderNames is not null, x =>
@@ -44,27 +43,29 @@ public class ModelService : ApplicationService, IModelService
input.ModelApiTypes.Contains(x.ModelApiType))
.WhereIF(input.IsPremiumOnly == true, x =>
PremiumPackageConst.ModeIds.Contains(x.ModelId))
.GroupBy(x => x.ModelId)
.Select(x => x.ModelId)
.ToPageListAsync(input.SkipCount, input.MaxResultCount, total));
var entities = await _modelRepository._DbQueryable.Where(x => modelIds.Contains(x.ModelId))
.OrderBy(x => x.OrderNum)
.OrderBy(x => x.Name)
.ToPageListAsync(input.SkipCount, input.MaxResultCount, total);
.OrderBy(x => x.Name).ToListAsync();
// 转换为DTO
var result = models.Select(model => new ModelLibraryDto
var output= entities.GroupBy(x => x.ModelId).Select(x => new ModelLibraryDto
{
ModelId = model.ModelId,
Name = model.Name,
Description = model.Description,
ModelType = model.ModelType,
ModelTypeName = model.ModelType.GetDescription(),
ModelApiType = model.ModelApiType,
ModelApiTypeName = model.ModelApiType.GetDescription(),
MultiplierShow = model.MultiplierShow,
ProviderName = model.ProviderName,
IconUrl = model.IconUrl,
IsPremium = PremiumPackageConst.ModeIds.Contains(model.ModelId)
ModelId = x.First().ModelId,
Name = x.First().Name,
Description = x.First().Description,
ModelType = x.First().ModelType,
ModelApiTypes = x.Select(y => new ModelApiTypeOutput { ModelApiType = y.ModelApiType }).ToList(),
MultiplierShow = x.First().MultiplierShow,
ProviderName = x.First().ProviderName,
IconUrl = x.First().IconUrl,
IsPremium = PremiumPackageConst.ModeIds.Contains(x.First().ModelId),
OrderNum = x.First().OrderNum
}).ToList();
return new PagedResultDto<ModelLibraryDto>(total, result);
return new PagedResultDto<ModelLibraryDto>(total, output);
}
/// <summary>