From 125afb51d791577ef078554f0ceec817a7ca4e22 Mon Sep 17 00:00:00 2001 From: Will Henchy Date: Sat, 8 Apr 2023 11:46:55 -0400 Subject: [PATCH] Add shared Google Drive folder support (#2562) closes #1634 Adds support for loading files from a shared Google Drive folder to `GoogleDriveLoader`. Shared drives are commonly used by businesses on their Google Workspace accounts (this is my particular use case). --- langchain/document_loaders/googledrive.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/langchain/document_loaders/googledrive.py b/langchain/document_loaders/googledrive.py index 8695bcdf..47eaee33 100644 --- a/langchain/document_loaders/googledrive.py +++ b/langchain/document_loaders/googledrive.py @@ -148,7 +148,7 @@ class GoogleDriveLoader(BaseLoader, BaseModel): creds = self._load_credentials() service = build("drive", "v3", credentials=creds) - file = service.files().get(fileId=id).execute() + file = service.files().get(fileId=id, supportsAllDrives=True).execute() request = service.files().export_media(fileId=id, mimeType="text/plain") fh = BytesIO() downloader = MediaIoBaseDownload(fh, request) @@ -182,6 +182,8 @@ class GoogleDriveLoader(BaseLoader, BaseModel): .list( q=f"'{self.folder_id}' in parents", pageSize=1000, + includeItemsFromAllDrives=True, + supportsAllDrives=True, fields="nextPageToken, files(id, name, mimeType)", ) .execute() @@ -217,7 +219,7 @@ class GoogleDriveLoader(BaseLoader, BaseModel): creds = self._load_credentials() service = build("drive", "v3", credentials=creds) - file = service.files().get(fileId=id).execute() + file = service.files().get(fileId=id, supportsAllDrives=True).execute() request = service.files().get_media(fileId=id) fh = BytesIO() downloader = MediaIoBaseDownload(fh, request)