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 返回的内容为空。")