Merge remote-tracking branch 'origin/ai-hub' into ai-hub
This commit is contained in:
@@ -30,11 +30,13 @@ public class AiChatService : ApplicationService
|
|||||||
private readonly AiBlacklistManager _aiBlacklistManager;
|
private readonly AiBlacklistManager _aiBlacklistManager;
|
||||||
|
|
||||||
public AiChatService(IHttpContextAccessor httpContextAccessor,
|
public AiChatService(IHttpContextAccessor httpContextAccessor,
|
||||||
AiMessageManager aiMessageManager, AiBlacklistManager aiBlacklistManager)
|
AiMessageManager aiMessageManager, AiBlacklistManager aiBlacklistManager,
|
||||||
|
ISqlSugarRepository<AiModelEntity> aiModelRepository)
|
||||||
{
|
{
|
||||||
this._httpContextAccessor = httpContextAccessor;
|
this._httpContextAccessor = httpContextAccessor;
|
||||||
_aiMessageManager = aiMessageManager;
|
_aiMessageManager = aiMessageManager;
|
||||||
_aiBlacklistManager = aiBlacklistManager;
|
_aiBlacklistManager = aiBlacklistManager;
|
||||||
|
_aiModelRepository = aiModelRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -57,7 +59,9 @@ public class AiChatService : ApplicationService
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<List<ModelGetListOutput>> GetModelAsync()
|
public async Task<List<ModelGetListOutput>> GetModelAsync()
|
||||||
{
|
{
|
||||||
var output = await _aiModelRepository._DbQueryable.Select(x => new ModelGetListOutput
|
var output = await _aiModelRepository._DbQueryable
|
||||||
|
.OrderByDescending(x=>x.OrderNum)
|
||||||
|
.Select(x => new ModelGetListOutput
|
||||||
{
|
{
|
||||||
Id = x.Id,
|
Id = x.Id,
|
||||||
Category = "chat",
|
Category = "chat",
|
||||||
@@ -83,22 +87,22 @@ public class AiChatService : ApplicationService
|
|||||||
public async Task PostSendAsync(SendMessageInput input, CancellationToken cancellationToken)
|
public async Task PostSendAsync(SendMessageInput input, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
//除了免费模型,其他的模型都要校验
|
//除了免费模型,其他的模型都要校验
|
||||||
if (input.Model != "DeepSeek-R1-0528")
|
// if (input.Model != "DeepSeek-R1-0528")
|
||||||
{
|
// {
|
||||||
//有token,需要黑名单校验
|
// //有token,需要黑名单校验
|
||||||
if (CurrentUser.IsAuthenticated)
|
// if (CurrentUser.IsAuthenticated)
|
||||||
{
|
// {
|
||||||
await _aiBlacklistManager.VerifiyAiBlacklist(CurrentUser.GetId());
|
// await _aiBlacklistManager.VerifiyAiBlacklist(CurrentUser.GetId());
|
||||||
if (!CurrentUser.Roles.Contains("YiXinAi-Vip"))
|
// if (!CurrentUser.Roles.Contains("YiXinAi-Vip"))
|
||||||
{
|
// {
|
||||||
throw new UserFriendlyException("该模型需要VIP用户才能使用,请购买VIP后重新登录重试");
|
// throw new UserFriendlyException("该模型需要VIP用户才能使用,请购买VIP后重新登录重试");
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
throw new UserFriendlyException("未登录用户,只能使用未加速的DeepSeek-R1,请登录后重试");
|
// throw new UserFriendlyException("未登录用户,只能使用未加速的DeepSeek-R1,请登录后重试");
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
//前面都是校验,后面才是真正的调用
|
//前面都是校验,后面才是真正的调用
|
||||||
var httpContext = this._httpContextAccessor.HttpContext;
|
var httpContext = this._httpContextAccessor.HttpContext;
|
||||||
|
|||||||
@@ -25,7 +25,10 @@ public class AzureChatService : IChatService
|
|||||||
new AzureKeyCredential(apiKey));
|
new AzureKeyCredential(apiKey));
|
||||||
ChatClient chatClient = azureClient.GetChatClient(deploymentName);
|
ChatClient chatClient = azureClient.GetChatClient(deploymentName);
|
||||||
|
|
||||||
var response = chatClient.CompleteChatStreamingAsync(messages, cancellationToken: cancellationToken);
|
var response = chatClient.CompleteChatStreamingAsync(messages, new ChatCompletionOptions()
|
||||||
|
{
|
||||||
|
MaxOutputTokenCount = 2048
|
||||||
|
}, cancellationToken: cancellationToken);
|
||||||
|
|
||||||
await foreach (StreamingChatCompletionUpdate update in response)
|
await foreach (StreamingChatCompletionUpdate update in response)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -19,14 +19,6 @@ public class AzureRestChatService : IChatService
|
|||||||
{
|
{
|
||||||
// 设置API URL
|
// 设置API URL
|
||||||
var apiUrl = $"{aiModelDescribe.Endpoint}models/chat/completions";
|
var apiUrl = $"{aiModelDescribe.Endpoint}models/chat/completions";
|
||||||
|
|
||||||
|
|
||||||
var ss = messages.Select(x => new
|
|
||||||
{
|
|
||||||
role = x.GetRoleAsString(),
|
|
||||||
content = x.Content.FirstOrDefault()?.Text
|
|
||||||
}).ToList();
|
|
||||||
|
|
||||||
// 准备请求内容
|
// 准备请求内容
|
||||||
var requestBody = new
|
var requestBody = new
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -20,10 +20,15 @@ public class UsageStatisticsAggregateRoot : FullAuditedAggregateRoot<Guid>
|
|||||||
public string ModelId { get; set; }
|
public string ModelId { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 总token使用
|
/// 输入使用token使用
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public decimal TotalTokens { get; set; }
|
public decimal InputTokens { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 输出使用token使用
|
||||||
|
/// </summary>
|
||||||
|
public decimal OutputTokens { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 对话次数
|
/// 对话次数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Volo.Abp.Domain;
|
using Volo.Abp.Domain;
|
||||||
|
using Yi.Framework.AiHub.Domain.AiChat;
|
||||||
|
using Yi.Framework.AiHub.Domain.AiChat.Impl;
|
||||||
using Yi.Framework.AiHub.Domain.Shared;
|
using Yi.Framework.AiHub.Domain.Shared;
|
||||||
using Yi.Framework.Mapster;
|
using Yi.Framework.Mapster;
|
||||||
|
|
||||||
@@ -16,17 +18,16 @@ namespace Yi.Framework.AiHub.Domain
|
|||||||
{
|
{
|
||||||
var configuration = context.Services.GetConfiguration();
|
var configuration = context.Services.GetConfiguration();
|
||||||
var services = context.Services;
|
var services = context.Services;
|
||||||
|
|
||||||
// Configure<AiGateWayOptions>(configuration.GetSection("AiGateWay"));
|
// Configure<AiGateWayOptions>(configuration.GetSection("AiGateWay"));
|
||||||
//
|
//
|
||||||
// services.AddKeyedTransient<IChatService, AzureChatService>(nameof(AzureChatService));
|
services.AddKeyedTransient<IChatService, AzureChatService>(nameof(AzureChatService));
|
||||||
// services.AddKeyedTransient<IChatService, AzureRestChatService>(nameof(AzureRestChatService));
|
services.AddKeyedTransient<IChatService, AzureRestChatService>(nameof(AzureRestChatService));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task OnApplicationInitializationAsync(ApplicationInitializationContext context)
|
public override async Task OnApplicationInitializationAsync(ApplicationInitializationContext context)
|
||||||
{
|
{
|
||||||
var service = context.ServiceProvider;
|
var service = context.ServiceProvider;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user