From 85f2e1b579c01a4ce65aa81be0adb2649b2a245e Mon Sep 17 00:00:00 2001 From: ccnetcore Date: Sun, 7 Sep 2025 01:34:25 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E6=95=B4=E7=90=86=E5=A4=A7=E5=B8=88=E6=9C=8D=E5=8A=A1=E5=8F=8A?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C=E4=B8=8E=E5=AF=B9=E8=AF=9D=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Dtos/FileMaster/VerifyNextInput.cs | 14 +++ .../Services/FileMaster/FileMasterService.cs | 96 +++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application.Contracts/Dtos/FileMaster/VerifyNextInput.cs create mode 100644 Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/FileMaster/FileMasterService.cs diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application.Contracts/Dtos/FileMaster/VerifyNextInput.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application.Contracts/Dtos/FileMaster/VerifyNextInput.cs new file mode 100644 index 00000000..e0d9dea9 --- /dev/null +++ b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application.Contracts/Dtos/FileMaster/VerifyNextInput.cs @@ -0,0 +1,14 @@ +namespace Yi.Framework.AiHub.Application.Contracts.Dtos.FileMaster; + +public class VerifyNextInput +{ + /// + /// 文件数 + /// + public int FileCount { get; set; } + + /// + /// 文件夹数 + /// + public int DirectoryCount { get; set; } +} \ No newline at end of file diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/FileMaster/FileMasterService.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/FileMaster/FileMasterService.cs new file mode 100644 index 00000000..2a06d126 --- /dev/null +++ b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/FileMaster/FileMasterService.cs @@ -0,0 +1,96 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Volo.Abp.Application.Services; +using Volo.Abp.Users; +using Yi.Framework.AiHub.Application.Contracts.Dtos.FileMaster; +using Yi.Framework.AiHub.Domain.Managers; +using Yi.Framework.AiHub.Domain.Shared.Dtos.OpenAi; + +namespace Yi.Framework.AiHub.Application.Services.FileMaster; + +public class FileMasterService : ApplicationService +{ + private readonly IHttpContextAccessor _httpContextAccessor; + private readonly AiGateWayManager _aiGateWayManager; + private readonly AiBlacklistManager _aiBlacklistManager; + + public FileMasterService(IHttpContextAccessor httpContextAccessor, AiGateWayManager aiGateWayManager, AiBlacklistManager aiBlacklistManager) + { + _httpContextAccessor = httpContextAccessor; + _aiGateWayManager = aiGateWayManager; + _aiBlacklistManager = aiBlacklistManager; + } + + /// + /// 校验下一步 + /// + /// + [HttpGet("FileMaster/VerifyNext")] + public Task VerifyNextAsync(VerifyNextInput input) + { + if (!CurrentUser.IsAuthenticated) + { + if (input.DirectoryCount + input.FileCount >= 20) + { + throw new UserFriendlyException("未登录用户,文件夹与文件数量不能大于20个,请登录后解锁全部功能"); + } + } + else + { + if (CurrentUser.IsInRole("")) + { + if (input.DirectoryCount + input.FileCount >= 100) + { + throw new UserFriendlyException("当前活动限免,最大支持文件夹与文件200个数量,如有大额文件整理评论区联系站长"); + } + } + else + { + if (input.DirectoryCount + input.FileCount >= 1000) + { + throw new UserFriendlyException("为防止无限制暴力使用,当前文件整理大师Vip最多支持1000文件与文件夹数量"); + } + } + } + + return Task.FromResult("success"); + } + + + /// + /// 对话 + /// + /// + /// + [HttpPost("FileMaster/chat/completions")] + public async Task ChatCompletionsAsync([FromBody] ThorChatCompletionsRequest input, + CancellationToken cancellationToken) + { + if (CurrentUser.IsAuthenticated) + { + input.Model = "gpt-5-chat"; + } + else + { + input.Model = "gpt-5-mini"; + } + Guid? userId = CurrentUser.IsAuthenticated ? CurrentUser.GetId() : null; + if (userId is not null) + { + await _aiBlacklistManager.VerifiyAiBlacklist(userId.Value); + } + + //ai网关代理httpcontext + if (input.Stream == true) + { + await _aiGateWayManager.CompleteChatStreamForStatisticsAsync(_httpContextAccessor.HttpContext, input, + userId, null, cancellationToken); + } + else + { + await _aiGateWayManager.CompleteChatForStatisticsAsync(_httpContextAccessor.HttpContext, input, userId, + null, + cancellationToken); + } + } +} \ No newline at end of file