From 8b183e289c44ef268d789bbd20082f134416d001 Mon Sep 17 00:00:00 2001 From: ccnetcore Date: Sun, 18 Jan 2026 17:46:34 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E7=94=9F=E6=88=90=E5=86=85=E5=AE=B9=E5=AE=89=E5=85=A8=E6=8B=A6?= =?UTF-8?q?=E6=88=AA=E6=A0=A1=E9=AA=8C=E5=B9=B6=E4=BC=98=E5=8C=96=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 --- .../Managers/AiGateWayManager.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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 2a08157e..90708bbe 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 @@ -1076,11 +1076,19 @@ public class AiGateWayManager : DomainService LazyServiceProvider.GetRequiredKeyedService(modelDescribe.HandlerName); var data = await chatService.GenerateContentAsync(modelDescribe, request, cancellationToken); + // 检查是否被大模型内容安全策略拦截 + var rawResponse = data.GetRawText(); + if (rawResponse.Contains("policies.google.com/terms/generative-ai/use-policy")) + { + _logger.LogWarning($"图片生成被内容安全策略拦截,模型:【{modelId}】,请求信息:【{request}】"); + throw new UserFriendlyException("您的提示词涉及敏感信息,已被大模型拦截,请调整提示词后再试!"); + } + //解析json,获取base64字符串 var imagePrefixBase64 = GeminiGenerateContentAcquirer.GetImagePrefixBase64(data); if (string.IsNullOrWhiteSpace(imagePrefixBase64)) { - _logger.LogError($"图片生成解析失败,模型id:,请求信息:【{request}】,请求响应信息:【{data}】"); + _logger.LogError($"图片生成解析失败,模型:【{modelId}】,请求信息:【{request}】,请求响应信息:【{data}】"); throw new UserFriendlyException("大模型没有返回图片,请调整提示词或稍后再试"); }