跳到主要内容

Google Places Tool

Google Places Tool 允许您的 Agent 利用 Google Places API,以便从 Google Places 上列出的位置文本中查找地址、电话号码、网站等。

设置

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

使用方法

提示

有关安装集成包的一般说明,请参阅此部分

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/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);
}

API 参考


此页面是否对您有帮助?


您也可以留下详细的反馈 在 GitHub 上.