Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

community[minor]: Add Google Routes Tool #5329

Merged
merged 23 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c147504
Initial routes feature
Luisotee Apr 20, 2024
fbd79e0
Update field masks, removed json mapping
Luisotee Apr 21, 2024
f75b63e
Fixed JSON return and better fieldMask
Luisotee Apr 21, 2024
9b6b7b5
working condition for all types of transport
Luisotee Apr 21, 2024
c0afbbf
Removed departure and arrival time due to timezone issues
Luisotee Apr 22, 2024
455c048
Better prompt, better typescript, remove warning, fixed duplicated la…
Luisotee Apr 22, 2024
3db1fa2
Working routes tool
Luisotee Apr 26, 2024
ce5eeb4
merged langchain updates
Luisotee Apr 27, 2024
6375acd
Add GoogleRoutesAPI interface and remove console.log statements
Luisotee Apr 27, 2024
e2e2e4a
Update Google Routes Tool documentation
Luisotee Apr 27, 2024
7a1c2d0
Updated example to include a example output
Luisotee Apr 27, 2024
f0120cd
Helper functions for better readability
Luisotee Apr 27, 2024
09497df
testing for google routes tool
Luisotee Apr 28, 2024
c977c96
Changed tool to StructuredTool, input is now an object
Luisotee Apr 28, 2024
1466f66
Updates tests for google routes tool
Luisotee Apr 28, 2024
b95ce84
Better description
Luisotee Apr 29, 2024
6a74f9b
Removed some lines to make explanation simpler
Luisotee Apr 29, 2024
91be7ed
Add TollInfo interface and update filteredRoutes function in google_r…
Luisotee May 1, 2024
591c95d
Working version with other features
Luisotee May 1, 2024
1e17f91
Fix handling of past departure and arrival times in GoogleRoutesAPI
Luisotee May 10, 2024
88c5e0d
Merge
jacoblee93 May 20, 2024
2d28db4
Format
jacoblee93 May 20, 2024
4fa12dd
Skip tests by default
jacoblee93 May 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/core_docs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ docs/use_cases/extraction/how_to/examples.md
docs/use_cases/extraction/how_to/examples.mdx
docs/modules/model_io/output_parsers/custom.md
docs/modules/model_io/output_parsers/custom.mdx
docs/modules/memory/chat_messages/custom.md
docs/modules/memory/chat_messages/custom.mdx
docs/modules/model_io/chat/response_metadata.md
docs/modules/model_io/chat/response_metadata.mdx
docs/modules/model_io/chat/function_calling.md
docs/modules/model_io/chat/function_calling.mdx
docs/modules/memory/chat_messages/custom.md
docs/modules/memory/chat_messages/custom.mdx
docs/modules/data_connection/vectorstores/custom.md
docs/modules/data_connection/vectorstores/custom.mdx
docs/modules/agents/agent_types/tool_calling.md
Expand Down
30 changes: 30 additions & 0 deletions docs/core_docs/docs/integrations/tools/google_routes.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
hide_table_of_contents: true
---

import CodeBlock from "@theme/CodeBlock";

# Google Routes Tool

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

You will need to get an API key from [Google here](https://developers.google.com/maps/documentation/places/web-service/overview)
and [enable the Routes API](https://console.cloud.google.com/apis/library/routes.googleapis.com). Then, set your API key
as `process.env.GOOGLE_ROUTES_API_KEY` or pass it in as an `apiKey` constructor argument.

## Usage

import IntegrationInstallTooltip from "@mdx_components/integration_install_tooltip.mdx";

<IntegrationInstallTooltip></IntegrationInstallTooltip>

```bash npm2yarn
npm install @langchain/openai @langchain/community
```

import ToolExample from "@examples/tools/google_routes.ts";

<CodeBlock language="typescript">{ToolExample}</CodeBlock>
57 changes: 57 additions & 0 deletions examples/src/tools/google_routes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
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.'
} */
}
1 change: 1 addition & 0 deletions langchain/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ MEMGRAPH_PASSWORD=ADD_YOURS_HERE
CLOSEVECTOR_API_KEY=ADD_YOURS_HERE
CLOSEVECTOR_API_SECRET=ADD_YOURS_HERE
GPLACES_API_KEY=ADD_YOURS_HERE
GOOGLE_ROUTES_API_KEY=ADD_YOURS_HERE
CONFLUENCE_USERNAME=ADD_YOURS_HERE
CONFLUENCE_PASSWORD=ADD_YOURS_HERE
CONFLUENCE_PATH=ADD_YOURS_HERE
4 changes: 4 additions & 0 deletions libs/langchain-community/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ tools/google_places.cjs
tools/google_places.js
tools/google_places.d.ts
tools/google_places.d.cts
tools/google_routes.cjs
tools/google_routes.js
tools/google_routes.d.ts
tools/google_routes.d.cts
tools/ifttt.cjs
tools/ifttt.js
tools/ifttt.d.ts
Expand Down
1 change: 1 addition & 0 deletions libs/langchain-community/langchain.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const config = {
"tools/google_calendar": "tools/google_calendar/index",
"tools/google_custom_search": "tools/google_custom_search",
"tools/google_places": "tools/google_places",
"tools/google_routes": "tools/google_routes",
"tools/ifttt": "tools/ifttt",
"tools/searchapi": "tools/searchapi",
"tools/searxng_search": "tools/searxng_search",
Expand Down
13 changes: 13 additions & 0 deletions libs/langchain-community/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,15 @@
"import": "./tools/google_places.js",
"require": "./tools/google_places.cjs"
},
"./tools/google_routes": {
"types": {
"import": "./tools/google_routes.d.ts",
"require": "./tools/google_routes.d.cts",
"default": "./tools/google_routes.d.ts"
},
"import": "./tools/google_routes.js",
"require": "./tools/google_routes.cjs"
},
"./tools/ifttt": {
"types": {
"import": "./tools/ifttt.d.ts",
Expand Down Expand Up @@ -2371,6 +2380,10 @@
"tools/google_places.js",
"tools/google_places.d.ts",
"tools/google_places.d.cts",
"tools/google_routes.cjs",
"tools/google_routes.js",
"tools/google_routes.d.ts",
"tools/google_routes.d.cts",
"tools/ifttt.cjs",
"tools/ifttt.js",
"tools/ifttt.d.ts",
Expand Down
Loading