From 7d856756f4214bfa674be48c5deba9a1c27bceac Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Sun, 23 Feb 2025 17:24:37 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20=E4=BF=AE=E5=A4=8D=20gemi?= =?UTF-8?q?ni=20=E8=AF=B7=E6=B1=82=E6=97=B6=E5=87=BA=E7=8E=B0=E5=A4=9A?= =?UTF-8?q?=E6=AC=A1=E4=B8=8D=E6=94=AF=E6=8C=81=E5=87=BD=E6=95=B0=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E8=B0=83=E7=94=A8=E6=9C=80=E5=90=8E=20429=20=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/provider/sources/gemini_source.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/astrbot/core/provider/sources/gemini_source.py b/astrbot/core/provider/sources/gemini_source.py index aa440ab8c..c6357bf7a 100644 --- a/astrbot/core/provider/sources/gemini_source.py +++ b/astrbot/core/provider/sources/gemini_source.py @@ -225,6 +225,7 @@ class ProviderGoogleGenAI(Provider): if 'tools' in payloads: del payloads['tools'] llm_response = await self._query(payloads, None) + break elif "429" in str(e) or "API key not valid" in str(e): keys.remove(chosen_key) if len(keys) > 0: @@ -232,7 +233,7 @@ class ProviderGoogleGenAI(Provider): logger.info(f"检测到 Key 异常({str(e)}),正在尝试更换 API Key 重试... 当前 Key: {chosen_key[:12]}...") continue else: - logger.error(f"A检测到 Key 异常({str(e)}),且已没有可用的 Key。 当前 Key: {chosen_key[:12]}...") + logger.error(f"检测到 Key 异常({str(e)}),且已没有可用的 Key。 当前 Key: {chosen_key[:12]}...") raise Exception("API 资源已耗尽,且没有可用的 Key 重试...") else: logger.error(f"发生了错误(gemini_source)。Provider 配置如下: {self.provider_config}") @@ -281,4 +282,8 @@ class ProviderGoogleGenAI(Provider): with open(image_url, "rb") as f: image_bs64 = base64.b64encode(f.read()).decode('utf-8') return "data:image/jpeg;base64," + image_bs64 - return '' \ No newline at end of file + return '' + + async def terminate(self): + await self.client.client.close() + logger.info("Google GenAI 适配器已终止。") \ No newline at end of file