feat: 添加对Gemini原生搜索功能的支持

This commit is contained in:
Raven95676
2025-04-17 20:36:22 +08:00
parent 1be5b4c7ff
commit ea8035e854
2 changed files with 17 additions and 3 deletions
+7
View File
@@ -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",
+10 -3
View File
@@ -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"])