This is a demo Google Drive connector used in LLM University's Chat with Retrieval-Augmented Generation module. Read the article to learn more.
Currently this connector can only search for Google Docs, Google Sheets, and Google Slide files. It does not support searching for other file types.
This connector supports two types of authentication: Service Account and OAuth.
For service account authentication this connector requires two environment variables:
The GDRIVE_SERVICE_ACCOUNT_INFO variable should contain the JSON content of the service account credentials file. To get the credentials file, follow these steps:
- Create a project in Google Cloud Console.
- Create a service account and activate the Google Drive API in the Google Cloud Console.
- Create a service account key and download the credentials file as JSON. The credentials file should look like this:
{
"type": "service_account",
"project_id": "{project id}",
"private_key_id": "{private_key_id}",
"private_key": "{private_key}",
"client_email": "{client_email}",
"client_id": "{client_id}",
"auth_uri": "{auth_uri}",
"token_uri": "{token_uri}",
"auth_provider_x509_cert_url": "{auth_provider_x509_cert_url}",
"client_x509_cert_url": "{client_x509_cert_url}",
"universe_domain": "{universe_domain}"
}- Convert the JSON credentails to a string through
json.dumps(credentials)and save the result in theGDRIVE_SERVICE_ACCOUNT_INFOenvironment variable. - Make sure to share the folder(s) you want to search with the service account email address.
The GDRIVE_CONNECTOR_API_KEY should contain an API key for the connector. This value must be present in the Authorization header for all requests to the connector.
When using OAuth for authentication, the connector does not require any additional environment variables. Instead, the OAuth flow should occur outside of the Connector and Cohere's API will forward the user's access token to this connector through the Authorization header.
With OAuth the connector will be able to search any Google Drive folders that the user has access to.
This connector also supports a few optional environment variables to configure the search:
GDRIVE_SEARCH_LIMIT- Number of results to return. Default is 10.GDRIVE_FOLDER_ID- ID of the folder to search in. If not provided, the search will be performed in the whole drive.
Create a virtual environment and install dependencies with poetry. We recommend using in-project virtual environments:
$ poetry config virtualenvs.in-project true
$ poetry install --no-rootNext, start up the search connector server:
$ poetry shell
$ flask --app provider --debug run --port 5000and check with curl to see that everything works:
$ curl --request POST \
--url http://localhost:5000/search \
--header 'Content-Type: application/json' \
--data '{
"query": "stainless propane griddle"
}'Alternatively, load up the Swagger UI and try out the API from a browser: http://localhost:5000/ui/