Configure LlamaIndex to read from Google Calendar
Using data loaders, we can give LlamaIndex access to a Google Calendar to gain information about schedules and events.
LlamaIndex can read from the Google Calendar API, but to do so, you must first configure a credentials file.
To generate the credentials file, first navigate to this guide on creating credentials. To read from the Calendar, we'll need an OAuth client ID (see relevant heading). Click the Go to Credentials button and navigate to the Credentials dashboard.
If you don't yet have an account, sign up.
If you don't yet have a service account, make one.
Return to the Credentials dashboard, click Create Credentials, and choose OAuth client ID. Fill out the required details on the first screen (OAuth consent screen).
Next, you'll need to add a scope to read from the calendar. Click Add or remove scopes and add the following scope from the list:
Return to the Credentials dashboard, click Create Credentials, and click OAuth client ID. Under Application type, choose Desktop app, add a name, then click Create.
On the pop-up window that appears, click Download json and save your credentials file as
credentials.json. This credentials file should live alongside the python script you'll use.
Place the following script in a python file alongside your credentials file:
# llama_index 0.6.5 from llama_index import GPTVectorStoreIndex, download_loader # Setup data loader GoogleCalendarReader = download_loader('GoogleCalendarReader') loader = GoogleCalendarReader() # load data documents = loader.load_data() index = GPTVectorStoreIndex.from_documents(documents) # query model query_engine = index.as_query_engine() response = query_engine.query('<your question>') print(response)
When you run the application for the first time, a browser window will open asking you to consent to API access.
Once you consent, the script will run and answer your question.
Access calendar events from other users' calendars
The default LlamaIndex Google Calendar loader only loads calendar events for the authenticated user. In order to access calendar events for other users as well, I've written my own Google Calendar loader.
Problems using a Vector store for calendar events
The basic index used in LlamaIndex examples is the GPTSimpleVectorIndex. However, a vector store is most useful for creating a cloud of ideas and doing text analysis. It is not a good data structure for handling calendaring events.
Here are all the LlamaIndex index types.
A better index type for calendar events is probably the List index. The pros to this are that the LLM can examine all of the events to come to a conclusion. The cons are that we need to pass ALL the events through to the model, and this takes a while and uses up a lot of tokens. Running a test with this method took over a minute for a response when comparing only two users' calendars.
It seems like it would be better to handle calendaring logic in code itself, and have the LLM be the conversationalist/middle-man between the user and the code.