From ea8035e854b9c13761fa2a781e2542a5bf53a95f Mon Sep 17 00:00:00 2001 From: Raven95676 Date: Thu, 17 Apr 2025 20:36:22 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=AF=B9Gemini?= =?UTF-8?q?=E5=8E=9F=E7=94=9F=E6=90=9C=E7=B4=A2=E5=8A=9F=E8=83=BD=E7=9A=84?= =?UTF-8?q?=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/config/default.py | 7 +++++++ astrbot/core/provider/sources/gemini_source.py | 13 ++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/astrbot/core/config/default.py b/astrbot/core/config/default.py index 6d48a3c9f..68a693209 100644 --- a/astrbot/core/config/default.py +++ b/astrbot/core/config/default.py @@ -534,6 +534,7 @@ CONFIG_METADATA_2 = { "model": "gemini-2.0-flash-exp", }, "gm_resp_image_modal": False, + "gm_native_search": False, "gm_native_coderunner": False, "gm_safety_settings": { "harassment": "BLOCK_MEDIUM_AND_ABOVE", @@ -711,6 +712,12 @@ CONFIG_METADATA_2 = { "type": "bool", "hint": "启用后,将支持返回图片内容。需要模型支持,否则会报错。具体支持模型请查看 Google Gemini 官方网站。温馨提示,如果您需要生成图片,请关闭 `启用群员识别` 配置获得更好的效果。", }, + "gm_native_search": { + "description": "启用原生搜索功能", + "type": "bool", + "hint": "启用后所有函数工具将全部失效,免费次数限制请查阅官方文档", + "obvious_hint": True, + }, "gm_native_coderunner": { "description": "启用原生代码执行器", "type": "bool", diff --git a/astrbot/core/provider/sources/gemini_source.py b/astrbot/core/provider/sources/gemini_source.py index f822ee4ee..7bef1f726 100644 --- a/astrbot/core/provider/sources/gemini_source.py +++ b/astrbot/core/provider/sources/gemini_source.py @@ -140,10 +140,17 @@ class ProviderGoogleGenAI(Provider): modalities = ["Text"] tool_list = None - if self.provider_config.get("gm_native_coderunner", False): + native_coderunner = self.provider_config.get("gm_native_coderunner", False) + native_search = self.provider_config.get("gm_native_search", False) + + if native_coderunner or native_search: if tools: - logger.warning("Gemini原生代码执行器已启用,函数工具将被忽略") - tool_list = [types.Tool(code_execution=types.ToolCodeExecution())] + logger.warning("Gemini原生工具已启用,函数工具将被忽略") + tool_list = [] + if native_coderunner: + tool_list.append(types.Tool(code_execution=types.ToolCodeExecution())) + if native_search: + tool_list.append(types.Tool(google_search=types.GoogleSearch())) elif tools and (func_desc := tools.get_func_desc_google_genai_style()): tool_list = [ types.Tool(function_declarations=func_desc["function_declarations"])