From 3447e2dc5d1dc3545b135536a748deace0d6a85e Mon Sep 17 00:00:00 2001 From: ccnetcore Date: Sat, 3 Jan 2026 14:07:04 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=B8=85=E7=90=86=E6=97=A0?= =?UTF-8?q?=E7=94=A8=E4=BB=A3=E7=A0=81=E5=B9=B6=E7=BB=9F=E4=B8=80=E7=BD=91?= =?UTF-8?q?=E5=85=B3=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除未使用的 using 和多余空行,优化代码可读性 - 统一 yi- 前缀模型名处理逻辑,减少重复代码 - 使用 EnsureSuccessStatusCode 简化图片上传错误处理流程 - 不影响现有功能,仅做代码结构和规范优化 --- .../Managers/AiGateWayManager.cs | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) 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 32cbe842..b7eb5177 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 @@ -1,6 +1,5 @@ using System.Collections.Concurrent; using System.Diagnostics; -using System.Net; using System.Runtime.CompilerServices; using System.Text; using System.Text.Json; @@ -93,14 +92,12 @@ public class AiGateWayManager : DomainService { throw new UserFriendlyException($"【{modelId}】模型当前版本【{modelApiType}】格式不支持"); } - // ✅ 统一处理 yi- 后缀(网关层模型规范化) if (!string.IsNullOrEmpty(aiModelDescribe.ModelId) && aiModelDescribe.ModelId.StartsWith("yi-", StringComparison.OrdinalIgnoreCase)) { aiModelDescribe.ModelId = aiModelDescribe.ModelId[3..]; } - return aiModelDescribe; } @@ -546,11 +543,11 @@ public class AiGateWayManager : DomainService { request.Model = request.Model[3..]; } - + var chatService = LazyServiceProvider.GetRequiredKeyedService(modelDescribe.HandlerName); var data = await chatService.ChatCompletionsAsync(modelDescribe, request, cancellationToken); - + data.SupplementalMultiplier(modelDescribe.Multiplier); if (userId is not null) @@ -620,7 +617,7 @@ public class AiGateWayManager : DomainService { request.Model = request.Model[3..]; } - + var completeChatResponse = chatService.StreamChatCompletionsAsync(modelDescribe, request, cancellationToken); ThorUsageResponse? tokenUsage = null; StringBuilder backupSystemContent = new StringBuilder(); @@ -980,7 +977,6 @@ public class AiGateWayManager : DomainService } private const string ImageStoreHost = "http://localhost:19001/api/app"; - /// /// Gemini 生成(Image)-非流式-缓存处理 /// 返回图片绝对路径 @@ -1017,13 +1013,7 @@ public class AiGateWayManager : DomainService var uploadUrl = $"{ImageStoreHost}/ai-image/upload-base64"; var content = new StringContent(JsonSerializer.Serialize(imagePrefixBase64), Encoding.UTF8, "application/json"); var uploadResponse = await httpClient.PostAsync(uploadUrl, content, cancellationToken); - // uploadResponse.EnsureSuccessStatusCode(); - if (uploadResponse.StatusCode != HttpStatusCode.OK) - { - var errorMessage = await uploadResponse.Content.ReadAsStringAsync(cancellationToken); - throw new UserFriendlyException($"{errorMessage}"); - } - + uploadResponse.EnsureSuccessStatusCode(); var storeUrl = await uploadResponse.Content.ReadAsStringAsync(cancellationToken); var tokenUsage = new ThorUsageResponse