From c691c7c1cfddf0f8b53011b6c76fc6898c92ab5b Mon Sep 17 00:00:00 2001 From: snaily Date: Tue, 25 Mar 2025 15:18:27 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E5=BD=93=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E5=8F=AF=E7=94=A8=E5=B7=A5=E5=85=B7=E6=97=B6=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E7=A9=BA=E5=88=97=E8=A1=A8=E8=80=8C=E9=9D=9E=E5=8C=85=E5=90=AB?= =?UTF-8?q?=E7=A9=BA=E5=AD=97=E5=85=B8=E7=9A=84=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在_build_tools函数中,当没有工具配置可用时(即tool为空字典),现在会返回空列表[]而不是[{}]。这个防御性编程修复可以避免向Gemini API发送无效的工具配置,防止可能的API调用错误。 --- app/service/chat/gemini_chat_service.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/service/chat/gemini_chat_service.py b/app/service/chat/gemini_chat_service.py index 6a85e36..7d2367e 100644 --- a/app/service/chat/gemini_chat_service.py +++ b/app/service/chat/gemini_chat_service.py @@ -62,7 +62,7 @@ def _build_tools(model: str, payload: Dict[str, Any]) -> List[Dict[str, Any]]: tool.pop("googleSearch", None) tool.pop("codeExecution", None) - return [tool] + return [tool] if tool else [] def _get_safety_settings(model: str) -> List[Dict[str, str]]: