Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Default GoogleDriveLoader Behavior to not Load Trashed Files (issue #5104) #5220

Merged
merged 1 commit into from
May 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions langchain/document_loaders/googledrive.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class GoogleDriveLoader(BaseLoader, BaseModel):
file_ids: Optional[List[str]] = None
recursive: bool = False
file_types: Optional[Sequence[str]] = None
load_trashed_files: bool = False

@root_validator
def validate_inputs(cls, values: Dict[str, Any]) -> Dict[str, Any]:
Expand Down Expand Up @@ -215,16 +216,17 @@ def _load_documents_from_folder(
_files = files

returns = []
for file in _files:
if file["mimeType"] == "application/vnd.google-apps.document":
for file in files:
if file["trashed"] and not self.load_trashed_files:
continue
elif file["mimeType"] == "application/vnd.google-apps.document":
returns.append(self._load_document_from_id(file["id"])) # type: ignore
elif file["mimeType"] == "application/vnd.google-apps.spreadsheet":
returns.extend(self._load_sheet_from_id(file["id"])) # type: ignore
elif file["mimeType"] == "application/pdf":
returns.extend(self._load_file_from_id(file["id"])) # type: ignore
else:
pass

return returns

def _fetch_files_recursive(
Expand All @@ -238,7 +240,7 @@ def _fetch_files_recursive(
pageSize=1000,
includeItemsFromAllDrives=True,
supportsAllDrives=True,
fields="nextPageToken, files(id, name, mimeType, parents)",
fields="nextPageToken, files(id, name, mimeType, parents, trashed)",
)
.execute()
)
Expand Down