fix:当没有可用工具时返回空列表而非包含空字典的列表

在_build_tools函数中,当没有工具配置可用时(即tool为空字典),现在会返回空列表[]而不是[{}]。这个防御性编程修复可以避免向Gemini API发送无效的工具配置,防止可能的API调用错误。
This commit is contained in:
snaily
2025-03-25 15:18:27 +08:00
parent 97db7eebf1
commit c691c7c1cf

View File

@@ -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]]: