2025-12-09 19:11:30 +08:00
|
|
|
|
using Mapster;
|
|
|
|
|
|
using SqlSugar;
|
|
|
|
|
|
using Volo.Abp.Application.Dtos;
|
|
|
|
|
|
using Volo.Abp.Application.Services;
|
|
|
|
|
|
using Yi.Framework.AiHub.Application.Contracts.Dtos.Model;
|
|
|
|
|
|
using Yi.Framework.AiHub.Application.Contracts.IServices;
|
|
|
|
|
|
using Yi.Framework.AiHub.Domain.Entities.Model;
|
2025-12-10 15:08:16 +08:00
|
|
|
|
using Yi.Framework.AiHub.Domain.Shared.Consts;
|
2025-12-09 19:11:30 +08:00
|
|
|
|
using Yi.Framework.AiHub.Domain.Shared.Enums;
|
|
|
|
|
|
using Yi.Framework.AiHub.Domain.Shared.Extensions;
|
|
|
|
|
|
using Yi.Framework.SqlSugarCore.Abstractions;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Yi.Framework.AiHub.Application.Services.Chat;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 模型服务
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class ModelService : ApplicationService, IModelService
|
|
|
|
|
|
{
|
|
|
|
|
|
private readonly ISqlSugarRepository<AiModelEntity, Guid> _modelRepository;
|
|
|
|
|
|
|
|
|
|
|
|
public ModelService(ISqlSugarRepository<AiModelEntity, Guid> modelRepository)
|
|
|
|
|
|
{
|
|
|
|
|
|
_modelRepository = modelRepository;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取模型库列表(公开接口,无需登录)
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public async Task<PagedResultDto<ModelLibraryDto>> GetListAsync(ModelLibraryGetListInput input)
|
|
|
|
|
|
{
|
|
|
|
|
|
RefAsync<int> total = 0;
|
|
|
|
|
|
|
|
|
|
|
|
// 查询所有未删除的模型,使用WhereIF动态添加筛选条件
|
|
|
|
|
|
var models = await _modelRepository._DbQueryable
|
|
|
|
|
|
.Where(x => !x.IsDeleted)
|
|
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.SearchKey), x =>
|
|
|
|
|
|
x.Name.Contains(input.SearchKey) || x.ModelId.Contains(input.SearchKey))
|
2025-12-10 00:31:14 +08:00
|
|
|
|
.WhereIF(input.ProviderNames is not null, x =>
|
|
|
|
|
|
input.ProviderNames.Contains(x.ProviderName))
|
|
|
|
|
|
.WhereIF(input.ModelTypes is not null, x =>
|
|
|
|
|
|
input.ModelTypes.Contains(x.ModelType))
|
|
|
|
|
|
.WhereIF(input.ModelApiTypes is not null, x =>
|
|
|
|
|
|
input.ModelApiTypes.Contains(x.ModelApiType))
|
2025-12-09 19:11:30 +08:00
|
|
|
|
.WhereIF(input.IsPremiumOnly == true, x =>
|
2025-12-10 15:08:16 +08:00
|
|
|
|
PremiumPackageConst.ModeIds.Contains(x.ModelId))
|
2025-12-09 19:11:30 +08:00
|
|
|
|
.OrderBy(x => x.OrderNum)
|
|
|
|
|
|
.OrderBy(x => x.Name)
|
|
|
|
|
|
.ToPageListAsync(input.SkipCount, input.MaxResultCount, total);
|
|
|
|
|
|
|
|
|
|
|
|
// 转换为DTO
|
|
|
|
|
|
var result = models.Select(model => 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,
|
2025-12-10 15:08:16 +08:00
|
|
|
|
IsPremium = PremiumPackageConst.ModeIds.Contains(model.ModelId)
|
2025-12-09 19:11:30 +08:00
|
|
|
|
}).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
return new PagedResultDto<ModelLibraryDto>(total, result);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取供应商列表(公开接口,无需登录)
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public async Task<List<string>> GetProviderListAsync()
|
|
|
|
|
|
{
|
|
|
|
|
|
var providers = await _modelRepository._DbQueryable
|
|
|
|
|
|
.Where(x => !x.IsDeleted)
|
|
|
|
|
|
.Where(x => !string.IsNullOrEmpty(x.ProviderName))
|
|
|
|
|
|
.GroupBy(x => x.ProviderName)
|
|
|
|
|
|
.OrderBy(x => x.ProviderName)
|
|
|
|
|
|
.Select(x => x.ProviderName)
|
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
|
|
|
|
|
|
|
return providers;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取模型类型选项列表(公开接口,无需登录)
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public Task<List<ModelTypeOption>> GetModelTypeOptionsAsync()
|
|
|
|
|
|
{
|
|
|
|
|
|
var options = Enum.GetValues<ModelTypeEnum>()
|
|
|
|
|
|
.Select(e => new ModelTypeOption
|
|
|
|
|
|
{
|
|
|
|
|
|
Label = e.GetDescription(),
|
|
|
|
|
|
Value = (int)e
|
|
|
|
|
|
})
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
return Task.FromResult(options);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取API类型选项列表(公开接口,无需登录)
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public Task<List<ModelApiTypeOption>> GetApiTypeOptionsAsync()
|
|
|
|
|
|
{
|
|
|
|
|
|
var options = Enum.GetValues<ModelApiTypeEnum>()
|
|
|
|
|
|
.Select(e => new ModelApiTypeOption
|
|
|
|
|
|
{
|
|
|
|
|
|
Label = e.GetDescription(),
|
|
|
|
|
|
Value = (int)e
|
|
|
|
|
|
})
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
return Task.FromResult(options);
|
|
|
|
|
|
}
|
2025-12-10 00:31:14 +08:00
|
|
|
|
}
|