From 6bcd10cd5c98d21451823137c0fd75196aa4d83e Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Sun, 9 Feb 2025 13:56:55 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20gemini=20=E6=8A=A5=E9=94=99=E6=97=B6?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=20apikey?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/provider/sources/gemini_source.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/astrbot/core/provider/sources/gemini_source.py b/astrbot/core/provider/sources/gemini_source.py index 9a6b8f6ae..af4b55bd5 100644 --- a/astrbot/core/provider/sources/gemini_source.py +++ b/astrbot/core/provider/sources/gemini_source.py @@ -48,13 +48,18 @@ class SimpleGoogleGenAIClient(): logger.debug(f"payload: {payload}") request_url = f"{self.api_base}/v1beta/models/{model}:generateContent?key={self.api_key}" async with self.client.post(request_url, json=payload, timeout=self.timeout) as resp: - try: - response = await resp.json() - except Exception as e: + if "application/json" in resp.headers.get("Content-Type"): + try: + response = await resp.json() + except Exception as e: + text = await resp.text() + logger.error(f"Gemini 返回了非 json 数据: {text}") + raise e + return response + else: text = await resp.text() - logger.error(f"gemini 返回了非 json 数据: {text}") - raise e - return response + logger.error(f"Gemini 返回了非 json 数据: {text}") + raise Exception("Gemini 返回了非 json 数据: ") @register_provider_adapter("googlegenai_chat_completion", "Google Gemini Chat Completion 提供商适配器")