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");// Access the widget context token from grounding metadataconst 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);