feat: 完成模型库优化
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using Yi.Framework.AiHub.Domain.Shared.Enums;
|
using Yi.Framework.AiHub.Domain.Shared.Enums;
|
||||||
|
using Yi.Framework.AiHub.Domain.Shared.Extensions;
|
||||||
|
|
||||||
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.Model;
|
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.Model;
|
||||||
|
|
||||||
@@ -30,17 +31,13 @@ public class ModelLibraryDto
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 模型类型名称
|
/// 模型类型名称
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string ModelTypeName { get; set; }
|
public string ModelTypeName => ModelType.GetDescription();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 模型API类型
|
/// 模型支持的API类型
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ModelApiTypeEnum ModelApiType { get; set; }
|
public List<ModelApiTypeOutput> ModelApiTypes { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 模型API类型名称
|
|
||||||
/// </summary>
|
|
||||||
public string ModelApiTypeName { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 模型显示倍率
|
/// 模型显示倍率
|
||||||
@@ -61,4 +58,22 @@ public class ModelLibraryDto
|
|||||||
/// 是否为尊享模型(PremiumChat类型)
|
/// 是否为尊享模型(PremiumChat类型)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsPremium { get; set; }
|
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();
|
||||||
}
|
}
|
||||||
@@ -73,7 +73,7 @@ public class AiChatService : ApplicationService
|
|||||||
{
|
{
|
||||||
var output = await _aiModelRepository._DbQueryable
|
var output = await _aiModelRepository._DbQueryable
|
||||||
.Where(x => x.ModelType == ModelTypeEnum.Chat)
|
.Where(x => x.ModelType == ModelTypeEnum.Chat)
|
||||||
.Where(x=>x.ModelApiType==ModelApiTypeEnum.OpenAi)
|
.Where(x => x.ModelApiType == ModelApiTypeEnum.OpenAi)
|
||||||
.OrderByDescending(x => x.OrderNum)
|
.OrderByDescending(x => x.OrderNum)
|
||||||
.Select(x => new ModelGetListOutput
|
.Select(x => new ModelGetListOutput
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -32,8 +32,7 @@ public class ModelService : ApplicationService, IModelService
|
|||||||
RefAsync<int> total = 0;
|
RefAsync<int> total = 0;
|
||||||
|
|
||||||
// 查询所有未删除的模型,使用WhereIF动态添加筛选条件
|
// 查询所有未删除的模型,使用WhereIF动态添加筛选条件
|
||||||
var models = await _modelRepository._DbQueryable
|
var modelIds = (await _modelRepository._DbQueryable
|
||||||
.Where(x => !x.IsDeleted)
|
|
||||||
.WhereIF(!string.IsNullOrWhiteSpace(input.SearchKey), x =>
|
.WhereIF(!string.IsNullOrWhiteSpace(input.SearchKey), x =>
|
||||||
x.Name.Contains(input.SearchKey) || x.ModelId.Contains(input.SearchKey))
|
x.Name.Contains(input.SearchKey) || x.ModelId.Contains(input.SearchKey))
|
||||||
.WhereIF(input.ProviderNames is not null, x =>
|
.WhereIF(input.ProviderNames is not null, x =>
|
||||||
@@ -44,27 +43,29 @@ public class ModelService : ApplicationService, IModelService
|
|||||||
input.ModelApiTypes.Contains(x.ModelApiType))
|
input.ModelApiTypes.Contains(x.ModelApiType))
|
||||||
.WhereIF(input.IsPremiumOnly == true, x =>
|
.WhereIF(input.IsPremiumOnly == true, x =>
|
||||||
PremiumPackageConst.ModeIds.Contains(x.ModelId))
|
PremiumPackageConst.ModeIds.Contains(x.ModelId))
|
||||||
.OrderBy(x => x.OrderNum)
|
.GroupBy(x => x.ModelId)
|
||||||
.OrderBy(x => x.Name)
|
.Select(x => x.ModelId)
|
||||||
.ToPageListAsync(input.SkipCount, input.MaxResultCount, total);
|
.ToPageListAsync(input.SkipCount, input.MaxResultCount, total));
|
||||||
|
|
||||||
// 转换为DTO
|
var entities = await _modelRepository._DbQueryable.Where(x => modelIds.Contains(x.ModelId))
|
||||||
var result = models.Select(model => new ModelLibraryDto
|
.OrderBy(x => x.OrderNum)
|
||||||
|
.OrderBy(x => x.Name).ToListAsync();
|
||||||
|
|
||||||
|
var output= entities.GroupBy(x => x.ModelId).Select(x => new ModelLibraryDto
|
||||||
{
|
{
|
||||||
ModelId = model.ModelId,
|
ModelId = x.First().ModelId,
|
||||||
Name = model.Name,
|
Name = x.First().Name,
|
||||||
Description = model.Description,
|
Description = x.First().Description,
|
||||||
ModelType = model.ModelType,
|
ModelType = x.First().ModelType,
|
||||||
ModelTypeName = model.ModelType.GetDescription(),
|
ModelApiTypes = x.Select(y => new ModelApiTypeOutput { ModelApiType = y.ModelApiType }).ToList(),
|
||||||
ModelApiType = model.ModelApiType,
|
MultiplierShow = x.First().MultiplierShow,
|
||||||
ModelApiTypeName = model.ModelApiType.GetDescription(),
|
ProviderName = x.First().ProviderName,
|
||||||
MultiplierShow = model.MultiplierShow,
|
IconUrl = x.First().IconUrl,
|
||||||
ProviderName = model.ProviderName,
|
IsPremium = PremiumPackageConst.ModeIds.Contains(x.First().ModelId),
|
||||||
IconUrl = model.IconUrl,
|
OrderNum = x.First().OrderNum
|
||||||
IsPremium = PremiumPackageConst.ModeIds.Contains(model.ModelId)
|
|
||||||
}).ToList();
|
}).ToList();
|
||||||
|
|
||||||
return new PagedResultDto<ModelLibraryDto>(total, result);
|
return new PagedResultDto<ModelLibraryDto>(total, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user