GPT Actions 库 - Google 云端硬盘

2024 年 8 月 11 日
在 Github 中打开

简介

此页面为开发者构建特定应用程序的 GPT Action 提供说明和指南。在继续之前,请务必先熟悉以下信息

这个特定的 GPT Action 概述了如何连接到 Google 云端硬盘,即 Google 的文件存储系统。此 Action 将允许您列出和查询文件名,将文件内容加载到您的 GPT 中,并最终在 ChatGPT 中使用该数据作为上下文。这组 Action 可以通过 Google Drive API 中找到的其他方法进行扩展。如果您想要一个可以读取较小文件的通用 GPT,例如,这将非常有用:

  • 会议纪要
  • 产品设计文档
  • 简短备忘录
  • 常见问题

对于需要读取较长备忘录(如整本书)、包含多行的复杂 CSV 文件等内容,我们建议构建特定于 Google Docs 或 Google Sheets 的 GPT。

价值 + 示例业务案例

用户现在可以利用 ChatGPT 的自然语言能力直接连接到 Google 云端硬盘中的文件

示例用例

  • 用户需要查找哪些文件与特定主题相关
  • 用户需要找到埋藏在文档深处的重要问题的答案

应用信息

在开始之前,请查看来自应用程序的这些链接

应用先决条件

在开始之前,请确保您拥有 Google Cloud 帐户并且已启用 Drive API

  • 设置 Google Cloud 项目
  • 从 Google API 库启用 Google Drive API
  • 如果应用程序的“发布状态”为“测试中”,请确保将用户添加到您的应用程序

ChatGPT 步骤

自定义 GPT 指令示例

创建自定义 GPT 后,要开始使用,请将以下文本复制到“Instructions”(指令)面板中。您可能需要添加特定于您的用例的额外上下文。通过这种方式,值得测试您添加的其他指令,以优化清晰度和准确性。有疑问?请查看入门示例,以了解此步骤的详细工作原理。

*** Context *** 

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.

*** Instructions ***

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:

- Summaries: what happens in a given file?  Please give a consistent, concise answer and read through the entire file before giving an answer.
- Professionalism: Behave professionally, providing clear and concise responses.
- Synthesis, Coding, and Data Analysis: ensure coding blocks are explained.
- When handling dates: make sure that dates are searched using date fields and also if you don't find anything, use titles.
- 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. 
- Privacy and Security: Respect user privacy and handle all data securely.

*** Examples of Documentation ***
Here is the relevant query documentation from Google for the listFiles function:
What you want to query	Example
Files with the name "hello"	name = 'hello'
Files with a name containing the words "hello" and "goodbye"	name contains 'hello' and name contains 'goodbye'
Files with a name that does not contain the word "hello"	not name contains 'hello'
Folders that are Google apps or have the folder MIME type	mimeType = 'application/vnd.google-apps.folder'
Files that are not folders	mimeType != 'application/vnd.google-apps.folder'
Files that contain the text "important" and in the trash	fullText contains 'important' and trashed = true
Files that contain the word "hello"	fullText contains 'hello'
Files that do not have the word "hello"	not fullText contains 'hello'
Files that contain the exact phrase "hello world"	fullText contains '"hello world"'
Files with a query that contains the "\" character (e.g., "\authors")	fullText contains '\\authors'
Files with ID within a collection, e.g. parents collection	'1234567' in parents
Files in an application data folder in a collection	'appDataFolder' in parents
Files for which user "test@example.org" has write permission	'test@example.org' in writers
Files for which members of the group "group@example.org" have write permission	'group@example.org' in writers
Files modified after a given date	modifiedTime > '2012-06-04T12:00:00' // default time zone is UTC
Files shared with the authorized user with "hello" in the name	sharedWithMe and name contains 'hello'
Files that have not been shared with anyone or domains (only private, or shared with specific users or groups)	visibility = 'limited'
Image or video files modified after a specific date	modifiedTime > '2012-06-04T12:00:00' and (mimeType contains 'image/' or mimeType contains 'video/')

OpenAPI Schema 示例

创建自定义 GPT 后,将以下文本复制到“Actions”(Action)面板中。这提供了一个您可以在函数中包含的内容示例,但是。. 有疑问?请查看入门示例,以了解此步骤的详细工作原理。此外,还可以尝试 ActionsGPT,这是一个 OpenAI 创建的自定义 GPT,旨在帮助您使用 Actions。以下是三个示例:

  • List Files(列出文件):这是列出您云端硬盘中文件的核心 Action。其中包含一些参数,例如 qincludeItemsFromAllDrives,supportsAllDrives
  • Get Metadata(获取元数据):如果列表不起作用,这可以作为基于某些结果的备用方案 - 例如,如果用户尝试通过“上周的会议”等进行搜索
  • Export(导出):以字节内容导出。要了解更多信息,请参阅 https://developers.google.com/drive/api/reference/rest/v3/files/export

通常,如果使用“get”,模型将尝试下载文件,这可能是不希望的。因此,建议改用 Export。


{
  "openapi": "3.1.0",
  "info": {
    "title": "Google Drive API",
    "description": "API for interacting with Google Drive",
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "https://www.googleapis.com/drive/v3"
    }
  ],
  "paths": {
    "/files": {
      "get": {
        "operationId": "ListFiles",
        "summary": "List files",
        "description": "Retrieve a list of files in the user's Google Drive.",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "description": "Query string for searching files.",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "includeItemsFromAllDrives",
            "in": "query",
            "description": "Whether both My Drive and shared drive items should be included in results.",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "supportsAllDrives",
            "in": "query",
            "description": "Whether the requesting application supports both My Drives and shared drives.",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "pageSize",
            "in": "query",
            "description": "Maximum number of files to return.",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 10
            }
          },
          {
            "name": "pageToken",
            "in": "query",
            "description": "Token for continuing a previous list request.",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "fields",
            "in": "query",
            "description": "Comma-separated list of fields to include in the response.",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "A list of files.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "kind": {
                      "type": "string",
                      "example": "drive#fileList"
                    },
                    "nextPageToken": {
                      "type": "string",
                      "description": "Token to retrieve the next page of results."
                    },
                    "files": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string"
                          },
                          "name": {
                            "type": "string"
                          },
                          "mimeType": {
                            "type": "string"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/files/{fileId}": {
      "get": {
        "operationId": "getMetadata",
        "summary": "Get file metadata",
        "description": "Retrieve metadata for a specific file.",
        "parameters": [
          {
            "name": "fileId",
            "in": "path",
            "description": "ID of the file to retrieve.",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "fields",
            "in": "query",
            "description": "Comma-separated list of fields to include in the response.",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Metadata of the file.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "name": {
                      "type": "string"
                    },
                    "mimeType": {
                      "type": "string"
                    },
                    "description": {
                      "type": "string"
                    },
                    "createdTime": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/files/{fileId}/export": {
      "get": {
        "operationId": "export",
        "summary": "Export a file",
        "description": "Export a Google Doc to the requested MIME type.",
        "parameters": [
          {
            "name": "fileId",
            "in": "path",
            "description": "ID of the file to export.",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "mimeType",
            "in": "query",
            "description": "The MIME type of the format to export to.",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "application/pdf",
                "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
                "text/plain"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The exported file.",
            "content": {
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "application/vnd.openxmlformats-officedocument.wordprocessingml.document": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "text/plain": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "400": {
            "description": "Invalid MIME type or file ID."
          },
          "404": {
            "description": "File not found."
          }
        }
      }
    }
  }
}

身份验证说明

以下是关于使用此第三方应用程序设置身份验证的说明。有疑问?请查看入门示例,以了解此步骤的详细工作原理。

Action 前步骤

在 ChatGPT 中设置身份验证之前,请在应用程序中执行以下步骤。

  • 转到 Google Cloud Console
  • 导航到“已启用 API 和服务”并启用 Google Drive API

alt_text

alt_text

  • 在搜索栏中,搜索 Google Drive API

alt_text

  • 创建新的 OAuth 凭据(或使用现有的凭据)。请注意,如果您尚未设置 OAuth 凭据屏幕,则需要进行设置。

alt_text

  • 在此过程中,您需要授予对正确权限的访问权限,如果启用了测试,则将主要测试人员设置为测试电子邮件,并设置 OAuth 速率限制。
  • 接下来,转到“凭据”,然后单击“+ 创建凭据”,再单击“创建凭据”。以下是屏幕已设置好后的外观示例。

alt_text

  • 找到您的 OAuth 客户端 ID 和客户端密钥,并将这两个值安全地存储起来(请参见下面的屏幕截图)

alt_text

在 ChatGPT 中

在 ChatGPT 中,单击“Authentication”(身份验证)并选择 “OAuth”。输入以下信息。

Action 后步骤

在 ChatGPT 中设置身份验证后,请按照应用程序中的以下步骤完成 Action。

  • 从 GPT Action 复制回调 URL

alt_text

  • 在“Authorized redirect URIs”(授权重定向 URI)中,添加您的回调 URL

alt_text

常见问题解答和故障排除

  • 回调 URL 错误: 如果您在 ChatGPT 中收到回调 URL 错误,请密切注意上面的屏幕截图。您需要将回调 URL 直接添加到 GCP 中,以便 Action 正确进行身份验证。

您希望我们优先考虑哪些集成?我们的集成中是否存在错误?在我们的 GitHub 中提交 PR 或 issue,我们会进行查看。

gd2md-html: xyzzy 2024 年 8 月 12 日 星期一