From 1be5b4c7ff44b3456a5b96bc068bdf3a6f69a16b Mon Sep 17 00:00:00 2001 From: Raven95676 Date: Wed, 16 Apr 2025 00:34:08 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=85=BC=E5=AE=B9=E6=97=A7=E7=89=88?= =?UTF-8?q?=E6=9C=ACgoogle-genai=20sdk?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/provider/sources/gemini_source.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/astrbot/core/provider/sources/gemini_source.py b/astrbot/core/provider/sources/gemini_source.py index 79e9aae89..f822ee4ee 100644 --- a/astrbot/core/provider/sources/gemini_source.py +++ b/astrbot/core/provider/sources/gemini_source.py @@ -249,10 +249,14 @@ class ProviderGoogleGenAI(Provider): types.FinishReason.PROHIBITED_CONTENT, types.FinishReason.SPII, types.FinishReason.BLOCKLIST, - types.FinishReason.IMAGE_SAFETY, }: raise Exception("模型生成内容违反Gemini平台政策") + # 防止旧版本SDK不存在IMAGE_SAFETY + if hasattr(types.FinishReason, "IMAGE_SAFETY"): + if finish_reason == types.FinishReason.IMAGE_SAFETY: + raise Exception("模型生成内容违反Gemini平台政策") + if not result_parts: logger.debug(result.candidates) raise Exception("API 返回的内容为空。")