Skip to main content

Google 地点工具

¥Google Places Tool

Google Places 工具允许你的代理利用 Google Places API 从 Google Places 上列出的位置文本中查找地址、调用号码、网站等。

¥The Google Places Tool allows your agent to utilize the Google Places API in order to find addresses, phone numbers, website, etc. from text about a location listed on Google Places.

设置

¥Setup

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

¥You will need to get an API key from Google here and enable the new Places API. Then, set your API key as process.env.GOOGLE_PLACES_API_KEY or pass it in as an apiKey constructor argument.

用法

¥Usage

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:

¥Related