Skip to main content

Google 地点工具

Google 地点工具允许你的智能代理使用 Google 地点 API,从而从 Google 地点列表中的地点相关文本中获取地址、电话号码、网站等信息。

安装配置

你需要从 Google 的网站 获取一个 API 密钥,并 启用新的地点 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 Reference:

相关内容


Was this page helpful?


You can also leave detailed feedback on GitHub.