Google Drive 检索文档。
先决条件
- 创建 Google Cloud 项目或使用现有项目
- 启用 Google Drive API
- 授权桌面应用程序的凭据
pip install -U google-api-python-client google-auth-httplib2 google-auth-oauthlib
检索 Google 文档
默认情况下,GoogleDriveRetriever 期望 credentials.json 文件位于 ~/.credentials/credentials.json,但这可以使用 GOOGLE_ACCOUNT_FILE 环境变量进行配置。token.json 的位置使用相同的目录(或使用参数 token_path)。请注意,token.json 将在您首次使用检索器时自动创建。 GoogleDriveRetriever 可以通过一些请求检索选定的文件。 默认情况下,如果您使用 folder_id,该文件夹中的所有文件都可以检索到 Document。 您可以从 URL 获取您的文件夹和文档 ID:- 文件夹:drive.google.com/drive/u/0/folders/1yucgL9WGgWZdM1TOuKkeghlPizuzMYb5 -> 文件夹 ID 是
"1yucgL9WGgWZdM1TOuKkeghlPizuzMYb5" - 文档:docs.google.com/document/d/1bfaMQ18_i56204VaQDVeAFpqEijJTgvurupdEDiaUQw/edit -> 文档 ID 是
"1bfaMQ18_i56204VaQDVeAFpqEijJTgvurupdEDiaUQw"
root 表示您的个人主页。
Document。
text/texttext/plaintext/htmltext/csvtext/markdownimage/pngimage/jpegapplication/epub+zipapplication/pdfapplication/rtfapplication/vnd.google-apps.document(GDoc)application/vnd.google-apps.presentation(GSlide)application/vnd.google-apps.spreadsheet(GSheet)application/vnd.google.colaboratory(Notebook colab)application/vnd.openxmlformats-officedocument.presentationml.presentation(PPTX)application/vnd.openxmlformats-officedocument.wordprocessingml.document(DOCX)
GoogleDriveRetriever 的文档。 但是,必须安装相应的包。| 模板 | 描述 |
|---|---|
gdrive-all-in-folder | 从 folder_id 返回所有兼容文件 |
gdrive-query | 在所有驱动器中搜索 query |
gdrive-by-name | 搜索名为 query 的文件 |
gdrive-query-in-folder | 在 folder_id 中搜索 query(以及 _recursive=true 中的子文件夹) |
gdrive-mime-type | 搜索特定的 mime_type |
gdrive-mime-type-in-folder | 在 folder_id 中搜索特定的 mime_type |
gdrive-query-with-mime-type | 搜索带有特定 mime_type 的 query |
gdrive-query-with-mime-type-and-folder | 搜索带有特定 mime_type 并在 folder_id 中的 query |
PromptTemplate 自定义提示。
使用 Google Drive 的“描述”元数据
每个 Google Drive 在元数据中都有一个description 字段(参见文件详细信息)。使用 snippets 模式返回所选文件的描述。
以编程方式连接这些文档到 Claude、VSCode 等,通过 MCP 获取实时答案。