Google 路线工具
¥Google Routes Tool
Google Routes 工具允许你的代理利用 Google Routes API 查找两个或多个目的地之间的路线。你可以获取步行、公交、汽车、摩托车和自行车的路线。
¥The Google Routes Tool allows your agent to utilize the Google Routes API in order to find a route between two or more destinations. You can get a route by walk, transit, car, motorcycle and bicycle.
设置
¥Setup
你需要从 Google 链接 和 启用路由 API 获取 API 密钥。然后,将你的 API 密钥设置为 process.env.GOOGLE_ROUTES_API_KEY
或将其作为 apiKey
构造函数参数传递。
¥You will need to get an API key from Google here
and enable the Routes API. Then, set your API key
as process.env.GOOGLE_ROUTES_API_KEY
or pass it in as an apiKey
constructor argument.
用法
¥Usage
tip
- npm
- Yarn
- pnpm
npm install @langchain/openai @langchain/community @langchain/core
yarn add @langchain/openai @langchain/community @langchain/core
pnpm add @langchain/openai @langchain/community @langchain/core
import { GoogleRoutesAPI } from "@langchain/community/tools/google_routes";
import { ChatPromptTemplate } from "@langchain/core/prompts";
import { ChatOpenAI } from "@langchain/openai";
import { AgentExecutor, createToolCallingAgent } from "langchain/agents";
export async function run() {
const tools = [new GoogleRoutesAPI()];
const llm = new ChatOpenAI({
model: "gpt-3.5-turbo-0125",
});
const prompt = ChatPromptTemplate.fromMessages([
["system", "You are a helpful assistant"],
["placeholder", "{chat_history}"],
["human", "{input}"],
["placeholder", "{agent_scratchpad}"],
]);
const agent = await createToolCallingAgent({
llm,
tools,
prompt,
});
const agentExecutor = new AgentExecutor({
agent,
tools,
});
const result = await agentExecutor.invoke({
input: "How to go from the Eiffel Tower to the Louvre Museum by transit?",
});
console.log(result);
/* {
input: 'How to go from the Eiffel Tower to the Louvre Museum by transit?',
output: 'To travel from the Eiffel Tower to the Louvre Museum by transit, here is the route information:\n' +
'\n' +
'- Departure: Eiffel Tower\n' +
'- Arrival: Louvre Museum\n' +
'- Distance: 4.1 km\n' +
'- Duration: 18 minutes\n' +
'- Transit Fare: €2.15\n' +
'\n' +
'Travel Instructions:\n' +
"1. Walk to Pont d'Iéna\n" +
'2. Take bus 72 towards Gare de Lyon - Maison de La RATP\n' +
'3. Walk to your destination\n' +
'\n' +
'Departure Time: 22:03\n' +
'Arrival Time: 22:15\n' +
'\n' +
'Please follow these instructions to reach the Louvre Museum from the Eiffel Tower.'
} */
}
API Reference:
- GoogleRoutesAPI from
@langchain/community/tools/google_routes
- ChatPromptTemplate from
@langchain/core/prompts
- ChatOpenAI from
@langchain/openai
- AgentExecutor from
langchain/agents
- createToolCallingAgent from
langchain/agents
相关
¥Related
工具 概念指南
¥Tool conceptual guide
工具 操作指南
¥Tool how-to guides