GPT 操作库:Google 云端硬盘
简介
本页面为开发者提供了构建特定应用程序的 GPT 操作的说明和指南。在继续之前,请务必先熟悉以下信息:
此特定的 GPT 操作提供了关于如何连接到 Google 文件存储系统 Google 云端硬盘的概述。此操作允许您列出文件名称并针对它们进行查询,将文件内容加载到您的 GPT 中,并最终将该数据用作 ChatGPT 中的上下文。可以通过Google 云端硬盘 API找到的附加方法来扩展此操作集。如果您想要一个可以读取较小文件的通用 GPT,例如:
- 会议纪要
- 产品设计文档
- 短备忘录
- 常见问题解答
对于想要读取较长备忘录(如整本书、包含许多行的复杂 CSV)的内容,我们建议构建一个专门针对 Google 文档或 Google 表格的 GPT。
价值 + 示例业务案例
用户现在可以利用 ChatGPT 的自然语言功能直接连接到 Google 云端硬盘中的文件。
示例用例:
- 用户需要查找与特定主题相关的文件
- 用户需要某个关键问题的答案,该问题深埋在文档中
应用程序信息
应用程序关键链接
在开始之前,请查看该应用程序的这些链接:
- 应用程序网站:https://www.google.com/drive/
- 应用程序 API 文档:https://developers.google.com/drive/api/guides/about-sdk
应用程序先决条件
在开始之前,请确保您拥有一个 Google Cloud 帐户并已启用云端硬盘 API:
- 设置 Google Cloud 项目
- 从 Google API 库启用 Google 云端硬盘 API
- 如果应用程序的“发布状态”为“测试”,请确保用户已添加到您的应用程序
ChatGPT 步骤
示例自定义 GPT 说明
创建自定义 GPT 后,请将以下文本复制到“说明”面板中以开始。您可能需要根据您的用例添加其他特定上下文。因此,值得测试您添加的其他说明以优化清晰度和准确性。有疑问吗?请查看入门示例,了解此步骤的详细信息。
*** Context ***
您是一位办公室助手,负责查看 Google 云端硬盘中的文件并读取信息。因此,当被问及某事时,请查看云端硬盘中的所有相关信息。请尊重文件名,同时也要查看每个文档和表格。
*** Instructions ***
使用 'listFiles' 函数获取文档中可用文件的列表。因此,根据名称和标题确定最适合您提取的文件。在 listFiles 的输出被纳入上下文后,请像正常的业务分析师一样行事。您可以被要求做的事情包括:
- 摘要:给定文件发生了什么?请提供一致、简洁的答案,并在给出答案前通读整个文件。
- 专业性:行为专业,提供清晰简洁的回复。
- 综合、编码和数据分析:确保对代码块进行解释。
- 处理日期时:确保使用日期字段搜索日期,如果找不到任何内容,则使用标题。
- 澄清:在需要时寻求澄清,以确保满足用户请求的准确性和完整性。请尽量确保您确切地知道所询问的内容。
- 隐私和安全:尊重用户隐私并安全地处理所有数据。
*** Examples of Documentation ***
以下是 Google 关于 listFiles 函数的相关查询文档:
您想查询的内容 示例
文件名为“hello” name = 'hello'
文件名包含“hello”和“goodbye” name contains 'hello' and name contains 'goodbye'
文件名不包含“hello” not name contains 'hello'
文件夹是 Google 应用或具有文件夹 MIME 类型 mimeType = 'application/vnd.google.apps.folder'
不是文件夹的文件 mimeType != 'application/vnd.google.apps.folder'
包含文本“important”且位于回收站中的文件 fullText contains 'important' and trashed = true
包含单词“hello”的文件 fullText contains 'hello'
不包含单词“hello”的文件 not fullText contains 'hello'
包含精确短语“hello world”的文件 fullText contains '"hello world"'
包含反斜杠“\”(例如,“\authors”)的文件 fullText contains '\\authors'
在集合中包含 ID 的文件,例如 parents 集合 '1234567' in parents
应用程序数据文件夹中的文件 'appDataFolder' in parents
用户“test@example.org”具有写入权限的文件 'test@example.org' in writers
组“group@example.org”的成员具有写入权限的文件 'group@example.org' in writers
修改时间晚于给定日期的文件 modifiedTime > '2012-06-04T12:00:00' // 默认时区为 UTC
与我共享的、文件名包含“hello”的文件 sharedWithMe and name contains 'hello'
未与任何人或域共享的文件(仅限私有,或与特定用户或组共享) visibility = 'limited'
修改时间晚于特定日期的图片或视频文件 modifiedTime > '2012-06-04T12:00:00' and (mimeType contains 'image/' or mimeType contains 'video/')
示例 OpenAPI Schema
创建自定义 GPT 后,请将以下文本复制到“操作”面板中。这提供了您可以包含在 GPT 函数中的示例。
有疑问吗?请查看入门示例以了解此步骤的详细信息。此外,还可以尝试ActionsGPT,这是 OpenAI 创建的一个 CustomGPT,用于帮助处理操作。三个示例是:
- List Files:这是列出您云端硬盘中文件的核心操作。其中包含一些参数,例如
q
、includeItemsFromAllDrives
、supportsAllDrives
- Get Metadata:如果列表不起作用,此操作可以作为基于特定结果的备份——例如,如果用户尝试通过“上周的会议”等进行搜索
- Export:以字节内容导出。有关更多信息,请参阅https://developers.google.com/drive/api/reference/rest/v3/files/export
通常,如果使用“get”,模型将尝试下载文件,这可能不理想。因此,建议使用导出。
{
"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."
}
}
}
}
}
}
身份验证说明
以下是设置此第三方应用程序身份验证的说明。有疑问吗?请查看入门示例以了解此步骤的详细信息。
操作前步骤
在 ChatGPT 中设置身份验证之前,请在应用程序中执行以下步骤。
- 转到 Google Cloud Console
- 导航到已启用的 API 和服务并启用 Google Drive API
- 在搜索栏中,搜索 Google Drive API:
- 创建新的 OAuth 凭据(或使用现有的)。请注意,如果您尚未设置 OAuth 凭据屏幕,则需要进行设置。
- 在此过程中,您需要授予正确的权限,如果启用了测试,请将主要测试人员设置为测试电子邮件,并设置 OAuth 速率限制。
- 接下来,转到凭据并点击“+ 创建凭据”,然后点击“创建凭据”。下面是已设置凭据的屏幕示例。
- 找到您的 OAuth Client ID 和 Client Secret,并将这两个值安全地存储起来(请参见下图)
在 ChatGPT 中
在 ChatGPT 中,点击“身份验证”并选择 “OAuth”。输入以下信息。
- Client ID:使用以上步骤中的 Client ID
- Client Secret:使用以上步骤中的 Client Secret
- Authorization URL:https://accounts.google.com/o/oauth2/auth
- Token URL:https://oauth2.googleapis.com/token
- Scope:https://www.googleapis.com/auth/drive
- 注意:有关已启用范围的更详细列表,请参阅Google 的 OAuth 2.0 指南。
- Token:默认 (POST)
- Privacy Policy:https://policies.google.com/privacy?hl=en-US
操作后步骤
在 ChatGPT 中设置身份验证后,请在应用程序中执行以下步骤以完成操作。
- 复制 GPT 操作中的回调 URL
- 在“授权的重定向 URI”中,添加您的回调 URL
常见问题解答和故障排除
- 回调 URL 错误: 如果在 ChatGPT 中遇到回调 URL 错误,请仔细查看上面的屏幕截图。您需要将回调 URL 直接添加到 GCP 中,操作才能正确进行身份验证。
是否有您希望我们优先处理的集成?我们的集成是否存在错误?请在我们的 GitHub 上提交 PR 或 issue,我们会进行查看。
gd2md-html: xyzzy Mon Aug 12 2024