googleSearch 工具使用实时的 Google 搜索结果来接地模型响应。这对于关于时事或特定事实的问题很有用。
import { ChatGoogle } from "@langchain/google";const llm = new ChatGoogle("gemini-2.5-flash") .bindTools([ { googleSearch: {}, }, ]);const res = await llm.invoke("Who won the latest World Series?");console.log(res.text);
googleMaps 工具使用来自 Google 地图的地理空间上下文来接地响应。这对于与地点相关的查询很有用。
import { ChatGoogle } from "@langchain/google";const llm = new ChatGoogle("gemini-2.5-flash") .bindTools([ { googleMaps: {}, }, ]);const res = await llm.invoke("What are the best coffee shops near Times Square?");console.log(res.text);
你可以启用小部件上下文令牌来渲染 Google 地图小部件:
const llm = new ChatGoogle("gemini-2.5-flash") .bindTools([ { googleMaps: { enableWidget: true, }, },]);const res = await llm.invoke("Find Italian restaurants in downtown Chicago");// 从接地元数据中访问小部件上下文令牌const groundingMetadata = res.response_metadata?.groundingMetadata;console.log(groundingMetadata?.googleMapsWidgetContextToken);
fileSearch 工具从文件搜索存储中执行语义检索。文件必须首先使用 Gemini 文件 API 导入。
import { ChatGoogle } from "@langchain/google";const llm = new ChatGoogle("gemini-2.5-flash") .bindTools([ { fileSearch: { fileSearchStoreNames: ["fileSearchStores/my-store-123"], }, },]);const res = await llm.invoke("What does the report say about Q4 revenue?");console.log(res.text);
import { ChatGoogle } from "@langchain/google";const llm = new ChatGoogle("gemini-2.5-flash") .bindTools([ { mcpServers: [ { name: "my-mcp-server", streamableHttpTransport: { url: "https://my-mcp-server.example.com/mcp", }, }, ], },]);const res = await llm.invoke("Use the tools from the MCP server to help me.");console.log(res.text);