diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application.Contracts/Dtos/ModelGetListOutput.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application.Contracts/Dtos/ModelGetListOutput.cs
index b89560aa..1b51665b 100644
--- a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application.Contracts/Dtos/ModelGetListOutput.cs
+++ b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application.Contracts/Dtos/ModelGetListOutput.cs
@@ -1,4 +1,6 @@
-namespace Yi.Framework.AiHub.Application.Contracts.Dtos;
+using Yi.Framework.AiHub.Domain.Shared.Enums;
+
+namespace Yi.Framework.AiHub.Application.Contracts.Dtos;
public class ModelGetListOutput
{
@@ -31,4 +33,14 @@ public class ModelGetListOutput
/// 是否为尊享包
///
public bool IsPremiumPackage { get; set; }
+
+ ///
+ /// 是否免费模型
+ ///
+ public bool IsFree { get; set; }
+
+ ///
+ /// 模型Api类型,现支持同一个模型id,多种接口格式
+ ///
+ public ModelApiTypeEnum ModelApiType { get; set; }
}
\ No newline at end of file
diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/Chat/AiChatService.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/Chat/AiChatService.cs
index bec50005..ea197089 100644
--- a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/Chat/AiChatService.cs
+++ b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/Chat/AiChatService.cs
@@ -50,6 +50,7 @@ public class AiChatService : ApplicationService
private readonly IAccountService _accountService;
private readonly ISqlSugarRepository _agentStoreRepository;
private readonly ISqlSugarRepository _aiModelRepository;
+ private const string FreeModelId = "DeepSeek-V3";
public AiChatService(IHttpContextAccessor httpContextAccessor,
AiBlacklistManager aiBlacklistManager,
@@ -58,7 +59,8 @@ public class AiChatService : ApplicationService
ModelManager modelManager,
PremiumPackageManager premiumPackageManager,
ChatManager chatManager, TokenManager tokenManager, IAccountService accountService,
- ISqlSugarRepository agentStoreRepository, ISqlSugarRepository aiModelRepository)
+ ISqlSugarRepository agentStoreRepository,
+ ISqlSugarRepository aiModelRepository)
{
_httpContextAccessor = httpContextAccessor;
_aiBlacklistManager = aiBlacklistManager;
@@ -94,9 +96,9 @@ public class AiChatService : ApplicationService
public async Task> GetModelAsync()
{
var output = await _aiModelRepository._DbQueryable
- .Where(x=>x.IsEnabled==true)
+ .Where(x => x.IsEnabled == true)
.Where(x => x.ModelType == ModelTypeEnum.Chat)
- .Where(x => x.ModelApiType == ModelApiTypeEnum.OpenAi)
+ .Where(x => x.ModelApiType == ModelApiTypeEnum.Completions)
.OrderByDescending(x => x.OrderNum)
.Select(x => new ModelGetListOutput
{
@@ -105,8 +107,19 @@ public class AiChatService : ApplicationService
ModelName = x.Name,
ModelDescribe = x.Description,
Remark = x.Description,
- IsPremiumPackage = x.IsPremium
+ IsPremiumPackage = x.IsPremium,
+ ModelApiType = x.ModelApiType,
}).ToListAsync();
+
+ output.ForEach(x =>
+ {
+ if (x.ModelId == FreeModelId)
+ {
+ x.IsPremiumPackage = false;
+ x.IsFree = true;
+ }
+ });
+
return output;
}
@@ -122,7 +135,7 @@ public class AiChatService : ApplicationService
CancellationToken cancellationToken)
{
//除了免费模型,其他的模型都要校验
- if (!input.Model.Contains("DeepSeek-R1"))
+ if (input.Model!=FreeModelId)
{
//有token,需要黑名单校验
if (CurrentUser.IsAuthenticated)
@@ -173,22 +186,10 @@ public class AiChatService : ApplicationService
{
throw new BusinessException("当前接口不支持第三方使用");
}
-
+ input.Model = "gpt-5-chat";
if (CurrentUser.IsAuthenticated)
{
await _aiBlacklistManager.VerifiyAiBlacklist(CurrentUser.GetId());
- if (CurrentUser.IsAiVip())
- {
- input.Model = "gpt-5-chat";
- }
- else
- {
- input.Model = "gpt-4.1-mini";
- }
- }
- else
- {
- input.Model = "DeepSeek-R1-0528";
}
//ai网关代理httpcontext
diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain.Shared/Enums/ModelApiTypeEnum.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain.Shared/Enums/ModelApiTypeEnum.cs
index 3ce86e09..becc8cdf 100644
--- a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain.Shared/Enums/ModelApiTypeEnum.cs
+++ b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain.Shared/Enums/ModelApiTypeEnum.cs
@@ -4,15 +4,15 @@ namespace Yi.Framework.AiHub.Domain.Shared.Enums;
public enum ModelApiTypeEnum
{
- [Description("OpenAI")]
- OpenAi,
+ [Description("OpanAi Completions")]
+ Completions,
- [Description("Claude")]
- Claude,
+ [Description("Claude Messages")]
+ Messages,
- [Description("Response")]
- Response,
+ [Description("OpanAi Responses")]
+ Responses,
- [Description("GenerateContent")]
+ [Description("Gemini GenerateContent")]
GenerateContent
}
\ No newline at end of file
diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Managers/AiGateWayManager.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Managers/AiGateWayManager.cs
index 2b80d844..481bb4c2 100644
--- a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Managers/AiGateWayManager.cs
+++ b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Managers/AiGateWayManager.cs
@@ -128,7 +128,7 @@ public class AiGateWayManager : DomainService
var response = httpContext.Response;
// 设置响应头,声明是 json
//response.ContentType = "application/json; charset=UTF-8";
- var modelDescribe = await GetModelAsync(ModelApiTypeEnum.OpenAi, request.Model);
+ var modelDescribe = await GetModelAsync(ModelApiTypeEnum.Completions, request.Model);
var chatService =
LazyServiceProvider.GetRequiredKeyedService(modelDescribe.HandlerName);
@@ -202,7 +202,7 @@ public class AiGateWayManager : DomainService
_specialCompatible.Compatible(request);
- var modelDescribe = await GetModelAsync(ModelApiTypeEnum.OpenAi, request.Model);
+ var modelDescribe = await GetModelAsync(ModelApiTypeEnum.Completions, request.Model);
var chatService =
LazyServiceProvider.GetRequiredKeyedService(modelDescribe.HandlerName);
@@ -351,7 +351,7 @@ public class AiGateWayManager : DomainService
var model = request.Model;
if (string.IsNullOrEmpty(model)) model = "dall-e-2";
- var modelDescribe = await GetModelAsync(ModelApiTypeEnum.OpenAi, model);
+ var modelDescribe = await GetModelAsync(ModelApiTypeEnum.Completions, model);
// 获取渠道指定的实现类型的服务
var imageService =
@@ -422,7 +422,7 @@ public class AiGateWayManager : DomainService
using var embedding =
Activity.Current?.Source.StartActivity("向量模型调用");
- var modelDescribe = await GetModelAsync(ModelApiTypeEnum.OpenAi, input.Model);
+ var modelDescribe = await GetModelAsync(ModelApiTypeEnum.Completions, input.Model);
// 获取渠道指定的实现类型的服务
var embeddingService =
@@ -536,7 +536,7 @@ public class AiGateWayManager : DomainService
var response = httpContext.Response;
// 设置响应头,声明是 json
//response.ContentType = "application/json; charset=UTF-8";
- var modelDescribe = await GetModelAsync(ModelApiTypeEnum.Claude, request.Model);
+ var modelDescribe = await GetModelAsync(ModelApiTypeEnum.Messages, request.Model);
var sourceModelId = request.Model;
if (!string.IsNullOrEmpty(request.Model) &&
@@ -617,7 +617,7 @@ public class AiGateWayManager : DomainService
response.Headers.TryAdd("Connection", "keep-alive");
_specialCompatible.AnthropicCompatible(request);
- var modelDescribe = await GetModelAsync(ModelApiTypeEnum.Claude, request.Model);
+ var modelDescribe = await GetModelAsync(ModelApiTypeEnum.Messages, request.Model);
var chatService =
LazyServiceProvider.GetRequiredKeyedService(modelDescribe.HandlerName);
@@ -726,7 +726,7 @@ public class AiGateWayManager : DomainService
var response = httpContext.Response;
// 设置响应头,声明是 json
//response.ContentType = "application/json; charset=UTF-8";
- var modelDescribe = await GetModelAsync(ModelApiTypeEnum.Response, request.Model);
+ var modelDescribe = await GetModelAsync(ModelApiTypeEnum.Responses, request.Model);
var chatService =
LazyServiceProvider.GetRequiredKeyedService(modelDescribe.HandlerName);
@@ -803,7 +803,7 @@ public class AiGateWayManager : DomainService
response.Headers.TryAdd("Cache-Control", "no-cache");
response.Headers.TryAdd("Connection", "keep-alive");
- var modelDescribe = await GetModelAsync(ModelApiTypeEnum.Response, request.Model);
+ var modelDescribe = await GetModelAsync(ModelApiTypeEnum.Responses, request.Model);
var chatService =
LazyServiceProvider.GetRequiredKeyedService(modelDescribe.HandlerName);
var sourceModelId = request.Model;
diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Managers/ChatManager.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Managers/ChatManager.cs
index 5e411fbb..6a7b54d5 100644
--- a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Managers/ChatManager.cs
+++ b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Managers/ChatManager.cs
@@ -82,7 +82,7 @@ public class ChatManager : DomainService
response.Headers.TryAdd("Cache-Control", "no-cache");
response.Headers.TryAdd("Connection", "keep-alive");
- var modelDescribe = await _aiGateWayManager.GetModelAsync(ModelApiTypeEnum.OpenAi, modelId);
+ var modelDescribe = await _aiGateWayManager.GetModelAsync(ModelApiTypeEnum.Completions, modelId);
//token状态检查,在应用层统一处理
var client = new OpenAIClient(new ApiKeyCredential(token),