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

feat: Google Calendar Tool (wip) #652

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
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
40 changes: 40 additions & 0 deletions docs/ecosystem/google_calendar.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Google Calendar Wrapper

This page covers how to use the Google Calendar API within LangChain.
It is broken into two parts: installation and setup, and then references to specific Pinecone wrappers.

## Installation and Setup
- Install requirements with `pip install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib`

- Follow instructions here https://developers.google.com/calendar/api/quickstart/python

- Download the `credentials.json` file and save it in the root of your project

## Wrappers

### Utility

There exists a GoogleCalendarAPIWrapper utility which wraps this API. To import this utility:

```python
from langchain.utilities.google_calendar import GoogleCalendarAPIWrapper
```

For a more detailed walkthrough of this wrapper, see [this notebook](../modules/utils/examples/google_calendar.ipynb).

### Tool

You can use it like:

```python
from langchain.utilities.google_calendar import GoogleCalendarAPIWrapper

google_calendar = GoogleCalendarAPIWrapper()

Tool(
name="Google Calendar",
func=google_calendar.run,
description="Useful for when you need to perform an action in a calendar. The input should be the initial query you want to ask the calendar.",
),
```

85 changes: 85 additions & 0 deletions docs/modules/utils/examples/google_calendar.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"id": "245a954a",
"metadata": {},
"source": [
"# Google Calendar\n",
"\n",
"This notebook goes over how to use the google calendar component.\n",
"\n",
"Most of the setup can be found instructions can be found [here](https://developers.google.com/calendar/api/quickstart/python).\n",
"\n",
"- Install requirements with `pip install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib`\n",
"\n",
"- Download the `credentials.json` file and save it in the root of your project"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ac4910f8",
"metadata": {},
"outputs": [],
"source": [
"from langchain.utilities import GoogleCalendarAPIWrapper"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "84b8f773",
"metadata": {},
"outputs": [],
"source": [
"calendar = GoogleCalendarAPIWrapper()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "068991a6",
"metadata": {},
"outputs": [],
"source": [
"calendar.run(\"Schedule a birthday party for 2pm tomorrow\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "028f4cba",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7 (default, Sep 16 2021, 08:50:36) \n[Clang 10.0.0 ]"
},
"vscode": {
"interpreter": {
"hash": "53f3bc57609c7a84333bb558594977aa5b4026b1d6070b93987956689e367341"
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}
2 changes: 2 additions & 0 deletions langchain/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
)
from langchain.serpapi import SerpAPIChain, SerpAPIWrapper
from langchain.sql_database import SQLDatabase
from langchain.utilities.google_calendar import GoogleCalendarAPIWrapper
from langchain.utilities.google_search import GoogleSearchAPIWrapper
from langchain.utilities.wolfram_alpha import WolframAlphaAPIWrapper
from langchain.vectorstores import FAISS, ElasticVectorSearch
Expand All @@ -46,6 +47,7 @@
"SerpAPIChain",
"GoogleSearchAPIWrapper",
"WolframAlphaAPIWrapper",
"GoogleCalendarAPIWrapper",
"Cohere",
"OpenAI",
"BasePromptTemplate",
Expand Down
10 changes: 10 additions & 0 deletions langchain/agents/load_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from langchain.requests import RequestsWrapper
from langchain.serpapi import SerpAPIWrapper
from langchain.utilities.bash import BashProcess
from langchain.utilities.google_calendar import GoogleCalendarAPIWrapper
from langchain.utilities.google_search import GoogleSearchAPIWrapper
from langchain.utilities.wolfram_alpha import WolframAlphaAPIWrapper

Expand Down Expand Up @@ -48,6 +49,14 @@ def _get_wolfram_alpha() -> Tool:
)


def _get_google_calendar() -> Tool:
return Tool(
name="Google Calendar",
func=GoogleCalendarAPIWrapper().run,
description="Useful for when you need to perform an action in a calendar. The input should be the initial query you want to ask the calendar.",
)


def _get_requests() -> Tool:
return Tool(
"Requests",
Expand All @@ -71,6 +80,7 @@ def _get_terminal() -> Tool:
"terminal": _get_terminal,
"google-search": _get_google_search,
"wolfram-alpha": _get_wolfram_alpha,
# "google-calendar": _get_google_calendar, TODO: not sure if we should add here
}


Expand Down
2 changes: 2 additions & 0 deletions langchain/utilities/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from langchain.requests import RequestsWrapper
from langchain.serpapi import SerpAPIWrapper
from langchain.utilities.bash import BashProcess
from langchain.utilities.google_calendar import GoogleCalendarAPIWrapper
from langchain.utilities.google_search import GoogleSearchAPIWrapper
from langchain.utilities.wolfram_alpha import WolframAlphaAPIWrapper

Expand All @@ -12,5 +13,6 @@
"PythonREPL",
"GoogleSearchAPIWrapper",
"WolframAlphaAPIWrapper",
"GoogleCalendarAPIWrapper",
"SerpAPIWrapper",
]
4 changes: 4 additions & 0 deletions langchain/utilities/google_calendar/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""Google Calendar utilities."""
from langchain.utilities.google_calendar.base import GoogleCalendarAPIWrapper

__all__ = ["GoogleCalendarAPIWrapper"]
Loading