From f1e8b66689e94f83bcc4814a5af39eacedbe06c7 Mon Sep 17 00:00:00 2001 From: ccnetcore Date: Thu, 8 Jan 2026 22:09:42 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=AE=8C=E5=96=84AI=E7=BD=91=E5=85=B3?= =?UTF-8?q?=E4=B8=8EAnthropic=E5=BC=82=E5=B8=B8=E5=A4=84=E7=90=86=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 图片生成解析失败时补充错误日志,便于问题定位 - Anthropic 非流式对话异常时,根据提示词过长场景补充返回信息 - 统一并优化 Anthropic 流式与非流式异常日志格式,提升可读性 --- .../Chats/AnthropicChatCompletionsService.cs | 19 ++++++++++++++----- .../Managers/AiGateWayManager.cs | 1 + 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/AiGateWay/Impl/ThorClaude/Chats/AnthropicChatCompletionsService.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/AiGateWay/Impl/ThorClaude/Chats/AnthropicChatCompletionsService.cs index dbd7de1c..83986cb8 100644 --- a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/AiGateWay/Impl/ThorClaude/Chats/AnthropicChatCompletionsService.cs +++ b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/AiGateWay/Impl/ThorClaude/Chats/AnthropicChatCompletionsService.cs @@ -75,15 +75,22 @@ public class AnthropicChatCompletionsService( { Guid errorId = Guid.NewGuid(); var error = await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - logger.LogError($"Anthropic非流式对话异常 请求地址:{options.Endpoint},ErrorId:{errorId}, StatusCode: {response.StatusCode.GetHashCode()}, Response: {error}"); - throw new Exception( $"恭喜你运气爆棚遇到了错误,尊享包对话异常:StatusCode【{response.StatusCode.GetHashCode()}】,ErrorId【{errorId}】"); + var message = $"恭喜你运气爆棚遇到了错误,尊享包对话异常:StatusCode【{response.StatusCode.GetHashCode()}】,ErrorId【{errorId}】"; + if (error.Contains("prompt is too long")) + { + message += $", Response: {error}"; + } + + logger.LogError( + $"Anthropic非流式对话异常 请求地址:{options.Endpoint},ErrorId:{errorId}, StatusCode: {response.StatusCode.GetHashCode()}, Response: {error}"); + throw new Exception(message); } var value = await response.Content.ReadFromJsonAsync(ThorJsonSerializer.DefaultOptions, cancellationToken: cancellationToken); - + return value; } @@ -122,9 +129,11 @@ public class AnthropicChatCompletionsService( { Guid errorId = Guid.NewGuid(); var error = await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - logger.LogError($"Anthropic流式对话异常 请求地址:{options.Endpoint},ErrorId:{errorId}, StatusCode: {response.StatusCode.GetHashCode()}, Response: {error}"); + logger.LogError( + $"Anthropic流式对话异常 请求地址:{options.Endpoint},ErrorId:{errorId}, StatusCode: {response.StatusCode.GetHashCode()}, Response: {error}"); - throw new Exception( $"恭喜你运气爆棚遇到了错误,尊享包对话异常:StatusCode【{response.StatusCode.GetHashCode()}】,ErrorId【{errorId}】"); + throw new Exception( + $"恭喜你运气爆棚遇到了错误,尊享包对话异常:StatusCode【{response.StatusCode.GetHashCode()}】,ErrorId【{errorId}】"); } using var stream = new StreamReader(await response.Content.ReadAsStreamAsync(cancellationToken)); 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 481bb4c2..d6302dbb 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 @@ -1080,6 +1080,7 @@ public class AiGateWayManager : DomainService var imagePrefixBase64 = GeminiGenerateContentAcquirer.GetImagePrefixBase64(data); if (string.IsNullOrWhiteSpace(imagePrefixBase64)) { + _logger.LogError($"图片生成解析失败,模型id:,请求信息:【{request}】,请求响应信息:{imagePrefixBase64}"); throw new UserFriendlyException("大模型没有返回图片,请调整提示词或稍后再试"); }