跳到主要内容
Google 地点工具允许您的代理利用 Google 地点 API,以从 Google 地点上列出的位置文本中查找地址、电话号码、网站等信息。

设置

您需要从这里获取 Google API 密钥,并启用新的 Places API。然后,将您的 API 密钥设置为 process.env.GOOGLE_PLACES_API_KEY,或者将其作为 apiKey 构造函数参数传入。

用法

有关安装 LangChain 软件包的一般说明,请参阅此部分
npm
npm install @langchain/openai @langchain/community @langchain/core
import { GooglePlacesAPI } from "@langchain/community/tools/google_places";
import { OpenAI } from "@langchain/openai";
import { initializeAgentExecutorWithOptions } from "@langchain/classic/agents";

export async function run() {
  const model = new OpenAI({
    temperature: 0,
  });

  const tools = [new GooglePlacesAPI()];

  const executor = await initializeAgentExecutorWithOptions(tools, model, {
    agentType: "zero-shot-react-description",
    verbose: true,
  });

  const res = await executor.invoke({
    input: "Where is the University of Toronto - Scarborough? ",
  });

  console.log(res.output);
}

以编程方式连接这些文档到 Claude、VSCode 等,通过 MCP 获取实时答案。
© . This site is unofficial and not affiliated with LangChain, Inc.