fix: 优化图片生成与上传错误处理及任务信息返回

- 图片上传接口新增状态码校验,返回明确错误信息
- 图片生成任务失败时记录完整错误信息与堆栈
- 图片任务查询结果补充发布状态、分类及错误信息
- 网关层模型名规范化与少量代码格式优化
This commit is contained in:
ccnetcore
2026-01-03 14:03:24 +08:00
parent 5a7f0ab108
commit 88fae0cdc2
3 changed files with 22 additions and 7 deletions

View File

@@ -84,10 +84,11 @@ public class ImageGenerationJob : AsyncBackgroundJob<ImageGenerationJobArgs>, 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);
}

View File

@@ -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,
};
}

View File

@@ -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<IAnthropicChatCompletionService>(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";
/// <summary>
/// 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