From 88fae0cdc2d04452264403855f094c4e1c770b55 Mon Sep 17 00:00:00 2001 From: ccnetcore Date: Sat, 3 Jan 2026 14:03:24 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E7=94=9F=E6=88=90=E4=B8=8E=E4=B8=8A=E4=BC=A0=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E5=A4=84=E7=90=86=E5=8F=8A=E4=BB=BB=E5=8A=A1=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 图片上传接口新增状态码校验,返回明确错误信息 - 图片生成任务失败时记录完整错误信息与堆栈 - 图片任务查询结果补充发布状态、分类及错误信息 - 网关层模型名规范化与少量代码格式优化 --- .../Jobs/ImageGenerationJob.cs | 5 +++-- .../Services/Chat/AiImageService.cs | 6 +++++- .../Managers/AiGateWayManager.cs | 18 ++++++++++++++---- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Jobs/ImageGenerationJob.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Jobs/ImageGenerationJob.cs index 062b6e31..d0912fe2 100644 --- a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Jobs/ImageGenerationJob.cs +++ b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Jobs/ImageGenerationJob.cs @@ -84,10 +84,11 @@ public class ImageGenerationJob : AsyncBackgroundJob, IT } catch (Exception ex) { - _logger.LogError(ex, "图片生成任务失败,TaskId: {TaskId}, Error: {Error}", args.TaskId, ex.Message); + var error = $"图片任务失败,TaskId: {args.TaskId},错误信息: {ex.Message},错误堆栈:{ex.StackTrace}"; + _logger.LogError(ex, error); task.TaskStatus = TaskStatusEnum.Fail; - task.ErrorInfo = ex.Message; + task.ErrorInfo = error; await _imageStoreTaskRepository.UpdateAsync(task); } diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/Chat/AiImageService.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/Chat/AiImageService.cs index fc1487e9..bf0a1a9d 100644 --- a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/Chat/AiImageService.cs +++ b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/Chat/AiImageService.cs @@ -143,7 +143,11 @@ public class AiImageService : ApplicationService // StoreBase64 = task.StoreBase64, StoreUrl = task.StoreUrl, TaskStatus = task.TaskStatus, - CreationTime = task.CreationTime + PublishStatus = task.PublishStatus, + Categories = task.Categories, + CreationTime = task.CreationTime, + ErrorInfo = task.ErrorInfo, + }; } 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 b7eb5177..32cbe842 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,5 +1,6 @@ using System.Collections.Concurrent; using System.Diagnostics; +using System.Net; using System.Runtime.CompilerServices; using System.Text; using System.Text.Json; @@ -92,12 +93,14 @@ 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; } @@ -543,11 +546,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) @@ -617,7 +620,7 @@ public class AiGateWayManager : DomainService { request.Model = request.Model[3..]; } - + var completeChatResponse = chatService.StreamChatCompletionsAsync(modelDescribe, request, cancellationToken); ThorUsageResponse? tokenUsage = null; StringBuilder backupSystemContent = new StringBuilder(); @@ -977,6 +980,7 @@ public class AiGateWayManager : DomainService } private const string ImageStoreHost = "http://localhost:19001/api/app"; + /// /// Gemini 生成(Image)-非流式-缓存处理 /// 返回图片绝对路径 @@ -1013,7 +1017,13 @@ 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(); + // uploadResponse.EnsureSuccessStatusCode(); + if (uploadResponse.StatusCode != HttpStatusCode.OK) + { + var errorMessage = await uploadResponse.Content.ReadAsStringAsync(cancellationToken); + throw new UserFriendlyException($"{errorMessage}"); + } + var storeUrl = await uploadResponse.Content.ReadAsStringAsync(cancellationToken); var tokenUsage = new ThorUsageResponse