Просмотр исходного кода

修复如下问题:
1.调用gemini api出现异常时没有向下游返回错误信息,后续处理流程可能要根据错误信息做相应补偿机制
2.修复特殊场景中出现索引越界导导致应用退出

熊伟(10007228) 2 лет назад
Родитель
Сommit
800419e7cc
1 измененных файлов с 3 добавлено и 0 удалено
  1. 3 0
      bot/gemini/google_gemini_bot.py

+ 3 - 0
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: