Google Places 工具
Google Places 工具允许您的代理使用 Google Places API 来查找地址、电话号码、网站等信息,这些信息来自 Google Places 上列出的位置的文本。
设置
您需要从 此处获得 Google 的 API 密钥 并 启用新的 Places API。然后,将您的 API 密钥设置为 process.env.GOOGLE_PLACES_API_KEY
或将其作为 apiKey
构造函数参数传递。
用法
提示
- npm
- Yarn
- pnpm
npm install @langchain/openai @langchain/community
yarn add @langchain/openai @langchain/community
pnpm add @langchain/openai @langchain/community
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 参考
- GooglePlacesAPI 来自
@langchain/community/tools/google_places
- OpenAI 来自
@langchain/openai
- initializeAgentExecutorWithOptions 来自
langchain/agents