You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用google/genai库关闭Gemini网页搜索Grounding功能?

关闭Gemini 2.0 Flash网页搜索Grounding功能的正确方法

你之前通过tools: []或省略config参数的方式无法关闭网页搜索,是因为Gemini 2.0 Flash的网页搜索(Grounding)功能由专门的groundingConfig参数控制,而非tools配置项。

正确代码示例

使用google/genai v0.13.0时,只需在generateContent的参数中显式添加groundingConfig: { enabled: false }即可禁用网页搜索:

const { GoogleGenAI } = require('@google/genai');

const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });

async function main() {
  const response = await ai.models.generateContent({
    model: "gemini-2.0-flash",
    contents: "you can search the web? get the current moon phase",
    groundingConfig: { enabled: false }
  });
  console.log(response.text);
}

main();

补充说明

  • Gemini 2.0系列模型默认开启网页搜索功能,必须显式通过groundingConfig.enabled = false来禁用。
  • tools参数用于配置函数调用等工具能力,与网页搜索的控制逻辑无关,因此设置tools: []不会影响搜索功能的开关。

内容的提问来源于stack exchange,提问作者Chris Stryczynski

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 03:48:16