From 800419e7cc79c558c201872e555f12bb91d7ecfd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=86=8A=E4=BC=9F=2810007228=29?= <xiongw@glodon.com>
Date: Thu, 14 Mar 2024 13:44:14 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=A6=82=E4=B8=8B=E9=97=AE?=
 =?UTF-8?q?=E9=A2=98=EF=BC=9A=201.=E8=B0=83=E7=94=A8gemini=20api=E5=87=BA?=
 =?UTF-8?q?=E7=8E=B0=E5=BC=82=E5=B8=B8=E6=97=B6=E6=B2=A1=E6=9C=89=E5=90=91?=
 =?UTF-8?q?=E4=B8=8B=E6=B8=B8=E8=BF=94=E5=9B=9E=E9=94=99=E8=AF=AF=E4=BF=A1?=
 =?UTF-8?q?=E6=81=AF=EF=BC=8C=E5=90=8E=E7=BB=AD=E5=A4=84=E7=90=86=E6=B5=81?=
 =?UTF-8?q?=E7=A8=8B=E5=8F=AF=E8=83=BD=E8=A6=81=E6=A0=B9=E6=8D=AE=E9=94=99?=
 =?UTF-8?q?=E8=AF=AF=E4=BF=A1=E6=81=AF=E5=81=9A=E7=9B=B8=E5=BA=94=E8=A1=A5?=
 =?UTF-8?q?=E5=81=BF=E6=9C=BA=E5=88=B6=202.=E4=BF=AE=E5=A4=8D=E7=89=B9?=
 =?UTF-8?q?=E6=AE=8A=E5=9C=BA=E6=99=AF=E4=B8=AD=E5=87=BA=E7=8E=B0=E7=B4=A2?=
 =?UTF-8?q?=E5=BC=95=E8=B6=8A=E7=95=8C=E5=AF=BC=E5=AF=BC=E8=87=B4=E5=BA=94?=
 =?UTF-8?q?=E7=94=A8=E9=80=80=E5=87=BA?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 bot/gemini/google_gemini_bot.py | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/bot/gemini/google_gemini_bot.py b/bot/gemini/google_gemini_bot.py
index 1a49d60..e63f1cb 100644
--- a/bot/gemini/google_gemini_bot.py
+++ b/bot/gemini/google_gemini_bot.py
@@ -44,6 +44,7 @@ class GoogleGeminiBot(Bot):
         except Exception as e:
             logger.error("[Gemini] fetch reply error, may contain unsafe content")
             logger.error(e)
+            return Reply(ReplyType.ERROR, "invoke [Gemini] api failed!")
 
     def _convert_to_gemini_messages(self, messages: list):
         res = []
@@ -63,6 +64,8 @@ class GoogleGeminiBot(Bot):
     def _filter_messages(self, messages: list):
         res = []
         turn = "user"
+        if not messages:
+            return res
         for i in range(len(messages) - 1, -1, -1):
             message = messages[i]
             if message.get("role") != turn: