google-drive (#1373)

Co-authored-by: pap <pap@openai.com>
pull/1343/head^2
Luke Xing 1 month ago committed by GitHub
parent 2f0b7e61de
commit 368a24950c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -142,3 +142,8 @@ evanweiss-openai:
name: "Evan Weiss"
website: "https://www.linkedin.com/in/evanpweiss/"
avatar: "https://avatars.githubusercontent.com/u/150647345"
lxing-oai:
name: "Luke Xing"
website: "https://www.linkedin.com/in/lukexing/"
avatar: "https://avatars.githubusercontent.com/u/176698727"

@ -0,0 +1,508 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "d2d3ee052fd5a2c0",
"metadata": {},
"source": [
"# **GPT Action Library: Google Drive**\n",
"\n",
"\n",
"## **Introduction**\n",
"\n",
"This page provides an instruction & guide for developers building a GPT Action for a specific application. Before you proceed, make sure to first familiarize yourself with the following information:\n",
"\n",
"\n",
"* [Introduction to GPT Actions](https://platform.openai.com/docs/actions/introduction)\n",
"* [Introduction to GPT Actions Library](https://platform.openai.com/docs/actions/actions-library)\n",
"* [Example of Building a GPT Action from Scratch](https://platform.openai.com/docs/actions/getting-started)\n",
"\n",
"This particular GPT Action provides an overview of how to connect to **Google Drive**, Googles File storage system. This action will allow you to list and query against file names, load the file content into your GPT, and ultimately use that data as context in ChatGPT. This set of actions is extensible by additional methods found via the [Google Drive API](https://developers.google.com/drive/api/guides/about-sdk). This is great if you want a generalist GPT that can read smaller files, such as: \n",
"\n",
"\n",
"* Meetings minutes\n",
"* Product design documents\n",
"* Short memos\n",
"* Frequently-asked questions\n",
"\n",
"For something that wants to read longer memos such as entire books, complex CSVs with many rows, we suggest building a Google Docs or Google Sheets-specific GPT.\n",
"\n",
"### Value + Example business case\n",
"\n",
"Users can now leverage ChatGPT's natural language capability to connect directly to files in Google Drive\n",
"\n",
"Example Use Cases:\n",
"\n",
"- A user needs to look up which files relate to a certain topic\n",
"- A user needs an answer to a critical question, buried deep in documents\n",
"\n",
"\n",
"## **Application Information**\n",
"\n",
"\n",
"### **Application Key Links**\n",
"\n",
"Check out these links from the application before you get started:\n",
"\n",
"\n",
"* Application Website: [https://www.google.com/drive/](https://www.google.com/drive/)\n",
"* Application API Documentation: [https://developers.google.com/drive/api/guides/about-sdk](https://developers.google.com/drive/api/guides/about-sdk)\n",
"\n",
"\n",
"### **Application Prerequisites**\n",
"\n",
"Before you get started, make sure you have a Google Cloud account and that the Drive API is enabled:\n",
"\n",
"\n",
"\n",
"* Set up a Google Cloud project\n",
"* Enable Google Drive API from Google API Library\n",
"* If applications “Publishing Status” is “Testing”, ensure users are added to your application\n",
"\n",
"\n",
"## **ChatGPT Steps**\n",
"\n",
"\n",
"### **Example Custom GPT Instructions**\n",
"\n",
"Once you've created a Custom GPT, to get started, copy the text below in the Instructions panel. You may have to add additional context specific to your use case. In this way, it is worth testing additional instructions you add to optimize for clarity and accuracy. Have questions? Check out [Getting Started Example](https://platform.openai.com/docs/actions/getting-started) to see how this step works in more detail.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "64aafb001b1e1247",
"metadata": {},
"outputs": [],
"source": [
"*** Context *** \n",
"\n",
"You are an office helper who takes a look at files within Google Drive and reads in information. In this way, when asked about something, please take a look at all of the relevant information within the drive. Respect file names, but also take a look at each document and sheet.\n",
"\n",
"*** Instructions ***\n",
"\n",
"Use the 'listFiles' function to get a list of files available within docs. In this way, determine out of this list which files make the most sense for you to pull back taking into account name and title. After the output of listFiles is called into context, act like a normal business analyst. Things you could be asked to be are:\n",
"\n",
"- Summaries: what happens in a given file? Please give a consistent, concise answer and read through the entire file before giving an answer.\n",
"- Professionalism: Behave professionally, providing clear and concise responses.\n",
"- Synthesis, Coding, and Data Analysis: ensure coding blocks are explained.\n",
"- When handling dates: make sure that dates are searched using date fields and also if you don't find anything, use titles.\n",
"- Clarification: Ask for clarification when needed to ensure accuracy and completeness in fulfilling user requests. Try to make sure you know exactly what is being asked. \n",
"- Privacy and Security: Respect user privacy and handle all data securely.\n",
"\n",
"*** Examples of Documentation ***\n",
"Here is the relevant query documentation from Google for the listFiles function:\n",
"What you want to query\tExample\n",
"Files with the name \"hello\"\tname = 'hello'\n",
"Files with a name containing the words \"hello\" and \"goodbye\"\tname contains 'hello' and name contains 'goodbye'\n",
"Files with a name that does not contain the word \"hello\"\tnot name contains 'hello'\n",
"Folders that are Google apps or have the folder MIME type\tmimeType = 'application/vnd.google-apps.folder'\n",
"Files that are not folders\tmimeType != 'application/vnd.google-apps.folder'\n",
"Files that contain the text \"important\" and in the trash\tfullText contains 'important' and trashed = true\n",
"Files that contain the word \"hello\"\tfullText contains 'hello'\n",
"Files that do not have the word \"hello\"\tnot fullText contains 'hello'\n",
"Files that contain the exact phrase \"hello world\"\tfullText contains '\"hello world\"'\n",
"Files with a query that contains the \"\\\" character (e.g., \"\\authors\")\tfullText contains '\\\\authors'\n",
"Files with ID within a collection, e.g. parents collection\t'1234567' in parents\n",
"Files in an application data folder in a collection\t'appDataFolder' in parents\n",
"Files for which user \"test@example.org\" has write permission\t'test@example.org' in writers\n",
"Files for which members of the group \"group@example.org\" have write permission\t'group@example.org' in writers\n",
"Files modified after a given date\tmodifiedTime > '2012-06-04T12:00:00' // default time zone is UTC\n",
"Files shared with the authorized user with \"hello\" in the name\tsharedWithMe and name contains 'hello'\n",
"Files that have not been shared with anyone or domains (only private, or shared with specific users or groups)\tvisibility = 'limited'\n",
"Image or video files modified after a specific date\tmodifiedTime > '2012-06-04T12:00:00' and (mimeType contains 'image/' or mimeType contains 'video/')\n"
]
},
{
"cell_type": "markdown",
"id": "1a915aafe09758dd",
"metadata": {},
"source": [
"### **Example OpenAPI Schema**\n",
"\n",
"Once you've created a Custom GPT, copy the text below in the Actions panel. This offers an example of what you could include within functions, but . Have questions? Check out [Getting Started Example](https://platform.openai.com/docs/getting-started) to see how this step works in more detail. As well, try [ActionsGPT](https://chatgpt.com/g/g-TYEliDU6A-actionsgpt), a CustomGPT OpenAI created to help with Actions. The three examples are:\n",
"\n",
"\n",
"* **List Files**: this is the core action that lists the files in your drive. Within this are a few parameters, such as `q`, `includeItemsFromAllDrives,supportsAllDrives`\n",
"* **Get Metadata**: in case list doesn't work, this can offer as a backup based on certain results - for example, if users attempt to make a search via “meeting from last week”, etc \n",
"* **Export**: exports in a byte content. For more reading, please consult [https://developers.google.com/drive/api/reference/rest/v3/files/export](https://developers.google.com/drive/api/reference/rest/v3/files/export)\n",
"\n",
"Generally, if get is used, the model will attempt to download the file, which may be undesirable. Thus, Export is recommended instead.\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a52135e94d17d425",
"metadata": {},
"outputs": [],
"source": [
"\n",
"{\n",
" \"openapi\": \"3.1.0\",\n",
" \"info\": {\n",
" \"title\": \"Google Drive API\",\n",
" \"description\": \"API for interacting with Google Drive\",\n",
" \"version\": \"1.0.0\"\n",
" },\n",
" \"servers\": [\n",
" {\n",
" \"url\": \"https://www.googleapis.com/drive/v3\"\n",
" }\n",
" ],\n",
" \"paths\": {\n",
" \"/files\": {\n",
" \"get\": {\n",
" \"operationId\": \"ListFiles\",\n",
" \"summary\": \"List files\",\n",
" \"description\": \"Retrieve a list of files in the user's Google Drive.\",\n",
" \"parameters\": [\n",
" {\n",
" \"name\": \"q\",\n",
" \"in\": \"query\",\n",
" \"description\": \"Query string for searching files.\",\n",
" \"required\": false,\n",
" \"schema\": {\n",
" \"type\": \"string\"\n",
" }\n",
" },\n",
" {\n",
" \"name\": \"includeItemsFromAllDrives\",\n",
" \"in\": \"query\",\n",
" \"description\": \"Whether both My Drive and shared drive items should be included in results.\",\n",
" \"required\": false,\n",
" \"schema\": {\n",
" \"type\": \"string\"\n",
" }\n",
" },\n",
" {\n",
" \"name\": \"supportsAllDrives\",\n",
" \"in\": \"query\",\n",
" \"description\": \"Whether the requesting application supports both My Drives and shared drives.\",\n",
" \"required\": false,\n",
" \"schema\": {\n",
" \"type\": \"string\"\n",
" }\n",
" },\n",
" {\n",
" \"name\": \"pageSize\",\n",
" \"in\": \"query\",\n",
" \"description\": \"Maximum number of files to return.\",\n",
" \"required\": false,\n",
" \"schema\": {\n",
" \"type\": \"integer\",\n",
" \"default\": 10\n",
" }\n",
" },\n",
" {\n",
" \"name\": \"pageToken\",\n",
" \"in\": \"query\",\n",
" \"description\": \"Token for continuing a previous list request.\",\n",
" \"required\": false,\n",
" \"schema\": {\n",
" \"type\": \"string\"\n",
" }\n",
" },\n",
" {\n",
" \"name\": \"fields\",\n",
" \"in\": \"query\",\n",
" \"description\": \"Comma-separated list of fields to include in the response.\",\n",
" \"required\": false,\n",
" \"schema\": {\n",
" \"type\": \"string\"\n",
" }\n",
" }\n",
" ],\n",
" \"responses\": {\n",
" \"200\": {\n",
" \"description\": \"A list of files.\",\n",
" \"content\": {\n",
" \"application/json\": {\n",
" \"schema\": {\n",
" \"type\": \"object\",\n",
" \"properties\": {\n",
" \"kind\": {\n",
" \"type\": \"string\",\n",
" \"example\": \"drive#fileList\"\n",
" },\n",
" \"nextPageToken\": {\n",
" \"type\": \"string\",\n",
" \"description\": \"Token to retrieve the next page of results.\"\n",
" },\n",
" \"files\": {\n",
" \"type\": \"array\",\n",
" \"items\": {\n",
" \"type\": \"object\",\n",
" \"properties\": {\n",
" \"id\": {\n",
" \"type\": \"string\"\n",
" },\n",
" \"name\": {\n",
" \"type\": \"string\"\n",
" },\n",
" \"mimeType\": {\n",
" \"type\": \"string\"\n",
" }\n",
" }\n",
" }\n",
" }\n",
" }\n",
" }\n",
" }\n",
" }\n",
" }\n",
" }\n",
" }\n",
" },\n",
" \"/files/{fileId}\": {\n",
" \"get\": {\n",
" \"operationId\": \"getMetadata\",\n",
" \"summary\": \"Get file metadata\",\n",
" \"description\": \"Retrieve metadata for a specific file.\",\n",
" \"parameters\": [\n",
" {\n",
" \"name\": \"fileId\",\n",
" \"in\": \"path\",\n",
" \"description\": \"ID of the file to retrieve.\",\n",
" \"required\": true,\n",
" \"schema\": {\n",
" \"type\": \"string\"\n",
" }\n",
" },\n",
" {\n",
" \"name\": \"fields\",\n",
" \"in\": \"query\",\n",
" \"description\": \"Comma-separated list of fields to include in the response.\",\n",
" \"required\": false,\n",
" \"schema\": {\n",
" \"type\": \"string\"\n",
" }\n",
" }\n",
" ],\n",
" \"responses\": {\n",
" \"200\": {\n",
" \"description\": \"Metadata of the file.\",\n",
" \"content\": {\n",
" \"application/json\": {\n",
" \"schema\": {\n",
" \"type\": \"object\",\n",
" \"properties\": {\n",
" \"id\": {\n",
" \"type\": \"string\"\n",
" },\n",
" \"name\": {\n",
" \"type\": \"string\"\n",
" },\n",
" \"mimeType\": {\n",
" \"type\": \"string\"\n",
" },\n",
" \"description\": {\n",
" \"type\": \"string\"\n",
" },\n",
" \"createdTime\": {\n",
" \"type\": \"string\",\n",
" \"format\": \"date-time\"\n",
" }\n",
" }\n",
" }\n",
" }\n",
" }\n",
" }\n",
" }\n",
" }\n",
" },\n",
" \"/files/{fileId}/export\": {\n",
" \"get\": {\n",
" \"operationId\": \"export\",\n",
" \"summary\": \"Export a file\",\n",
" \"description\": \"Export a Google Doc to the requested MIME type.\",\n",
" \"parameters\": [\n",
" {\n",
" \"name\": \"fileId\",\n",
" \"in\": \"path\",\n",
" \"description\": \"ID of the file to export.\",\n",
" \"required\": true,\n",
" \"schema\": {\n",
" \"type\": \"string\"\n",
" }\n",
" },\n",
" {\n",
" \"name\": \"mimeType\",\n",
" \"in\": \"query\",\n",
" \"description\": \"The MIME type of the format to export to.\",\n",
" \"required\": true,\n",
" \"schema\": {\n",
" \"type\": \"string\",\n",
" \"enum\": [\n",
" \"application/pdf\",\n",
" \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\",\n",
" \"text/plain\"\n",
" ]\n",
" }\n",
" }\n",
" ],\n",
" \"responses\": {\n",
" \"200\": {\n",
" \"description\": \"The exported file.\",\n",
" \"content\": {\n",
" \"application/pdf\": {\n",
" \"schema\": {\n",
" \"type\": \"string\",\n",
" \"format\": \"binary\"\n",
" }\n",
" },\n",
" \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\": {\n",
" \"schema\": {\n",
" \"type\": \"string\",\n",
" \"format\": \"binary\"\n",
" }\n",
" },\n",
" \"text/plain\": {\n",
" \"schema\": {\n",
" \"type\": \"string\",\n",
" \"format\": \"binary\"\n",
" }\n",
" }\n",
" }\n",
" },\n",
" \"400\": {\n",
" \"description\": \"Invalid MIME type or file ID.\"\n",
" },\n",
" \"404\": {\n",
" \"description\": \"File not found.\"\n",
" }\n",
" }\n",
" }\n",
" }\n",
" }\n",
"}"
]
},
{
"cell_type": "markdown",
"id": "5eea91bff57eb26",
"metadata": {},
"source": [
"## **Authentication Instructions**\n",
"\n",
"Below are instructions on setting up authentication with this 3rd party application. Have questions? Check out [Getting Started Example](https://platform.openai.com/docs/actions/getting-started) to see how this step works in more detail.\n",
"\n",
"\n",
"### **Pre-Action Steps**\n",
"\n",
"Before you set up authentication in ChatGPT, please take the following steps in the application.\n",
"\n",
"\n",
"\n",
"* Go to the Google Cloud Console\n",
"* Navigate to Enabled API & Services and enable Google Drive API \n",
"\n",
"\n",
"![alt_text](../../../images/gptactions_gd_api_services_pin.png \"api_and_services\")\n",
"\n",
"![alt_text](../../../images/gptactions_gd_nav_to_enabled_api.png \"api_lib\")\n",
"\n",
"\n",
"* Within the search bar, search Google Drive API:\n",
"\n",
"![alt_text](../../../images/gptactions_gd_search_google_drive_api.png \"gpt_actions\")\n",
"\n",
"\n",
"* Create new OAuth credentials (or use an existing one). Note that if you havent set up an OAuth credentials screen, you will need to do that.\n",
"\n",
"\n",
"![alt_text](../../../images/gptactions_gd_oauth_consent_screen.png \"oauth_consent\")\n",
"\n",
"\n",
"\n",
"\n",
"* Within this process, you will need to grant access to the correct permissions, establish the primary tester as a testing email if Testing is enabled, and set up the OAuth rate limit.\n",
"* Next, go to credentials and click “+ Create Credentials” and click “Create Credentials”. Below is an example of what this screen looks like when its already set up.\n",
"\n",
"\n",
"![alt_text](../../../images/gptactions_gd_go_to_create_credentials.png \"creds\")\n",
"\n",
"\n",
"\n",
"\n",
"* Locate your OAuth Client ID & Client Secret and store both values securely (see screenshot below)\n",
"\n",
"\n",
"\n",
"![alt_text](../../../images/gptactions_gd_oauthcid_and_csecret.png \"id and secret\")\n",
"\n",
"\n",
"\n",
"### **In ChatGPT**\n",
"\n",
"In ChatGPT, click on \"Authentication\" and choose **\"OAuth\"**. Enter in the information below.\n",
"\n",
"* **Client ID**: use Client ID from steps above\n",
"* **Client Secret**: use Client Secret from steps above\n",
"* **Authorization URL**: [https://accounts.google.com/o/oauth2/auth](https://accounts.google.com/o/oauth2/auth)\n",
"* **Token URL**: [https://oauth2.googleapis.com/token](https://oauth2.googleapis.com/token)\n",
"* **Scope**: [https://www.googleapis.com/auth/drive](https://www.googleapis.com/auth/drive.readonly)\n",
" * **Note**: for a list of more detailed scopes enabled, please refer to [Googles OAuth 2.0 guide.](https://developers.google.com/identity/protocols/oauth2/scopes)\n",
"* **Token**: Default (POST)\n",
"* **Privacy Policy**: [https://policies.google.com/privacy?hl=en-US](https://policies.google.com/privacy?hl=en-US)\n",
"\n",
"\n",
"### **Post-Action Steps**\n",
"\n",
"Once you've set up authentication in ChatGPT, follow the steps below in the application to finalize the Action.\n",
"\n",
"\n",
"\n",
"* Copy the callback URL from the GPT Action\n",
"\n",
"\n",
"![alt_text](../../../images/gptactions_gd_callbackurl_from_gpt_action.png \"callback\")\n",
"\n",
"\n",
"\n",
"\n",
"* In the “Authorized redirect URIs”, add your callback URL\n",
"\n",
"\n",
"![alt_text](../../../images/gptactions_gd_authorized_redirect_uris.png \"image_tooltip\")\n",
"\n",
"\n",
"\n",
"### **FAQ & Troubleshooting**\n",
"\n",
"\n",
"\n",
"* _Callback URL Error:_ If you get a callback URL error in ChatGPT, pay close attention to the screenshot above. You need to add the callback URL directly into GCP for the action to authenticate correctly.\n",
"\n",
"_Are there integrations that youd like us to prioritize? Are there errors in our integrations? File a PR or issue in our GitHub, and well take a look._\n",
"\n",
"\n",
"\n",
"\n",
"<!-- watermark --><div style=\"background-color:#FFFFFF\"><p style=\"color:#FFFFFF; font-size: 1px\">gd2md-html: xyzzy Mon Aug 12 2024</p></div>\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.11.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 205 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 189 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 301 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 KiB

@ -1505,3 +1505,12 @@
tags:
- completions
- functions
- title: GPT Actions library - Google Drive
path: examples/chatgpt/gpt_actions_library/gpt_action_google_drive.ipynb
date: 2024-08-11
authors:
- lxing-oai
tags:
- gpt-actions-library
- chat
Loading…
Cancel
Save