From c4885bca76b5e5eac0a5b6bed82474d95d517ee2 Mon Sep 17 00:00:00 2001 From: Jeff Bryner Date: Sun, 17 Nov 2024 10:09:02 -0800 Subject: [PATCH 1/2] Update GoogleDriveLoader to allow bring your own credentials issue: https://github.com/langchain-ai/langchain-google/issues/168 --- libs/community/langchain_google_community/drive.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libs/community/langchain_google_community/drive.py b/libs/community/langchain_google_community/drive.py index 8bdb93ffe..06a773b64 100644 --- a/libs/community/langchain_google_community/drive.py +++ b/libs/community/langchain_google_community/drive.py @@ -27,6 +27,8 @@ class GoogleDriveLoader(BaseLoader, BaseModel): """Path to the credentials file.""" token_path: Path = Path.home() / ".credentials" / "token.json" """Path to the token file.""" + credentials: Any = None + """Your own google credentials created via your own mechanism""" folder_id: Optional[str] = None """The folder id to load from.""" document_ids: Optional[List[str]] = None @@ -276,6 +278,11 @@ def _load_credentials(self) -> Any: if self.token_path.exists(): creds = Credentials.from_authorized_user_file(str(self.token_path), SCOPES) + if self.credentials: + # use whatever was passed to us + creds = self.credentials + return creds + if not creds or not creds.valid: if creds and creds.expired and creds.refresh_token: creds.refresh(Request()) From c87ca0e7222a6f5e989de4dd7dcc41658bcc7f76 Mon Sep 17 00:00:00 2001 From: Jeff Bryner Date: Sat, 23 Nov 2024 11:52:42 -0800 Subject: [PATCH 2/2] Update drive.py, remove errant trailing spaces --- libs/community/langchain_google_community/drive.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/community/langchain_google_community/drive.py b/libs/community/langchain_google_community/drive.py index 06a773b64..319b56f76 100644 --- a/libs/community/langchain_google_community/drive.py +++ b/libs/community/langchain_google_community/drive.py @@ -28,7 +28,7 @@ class GoogleDriveLoader(BaseLoader, BaseModel): token_path: Path = Path.home() / ".credentials" / "token.json" """Path to the token file.""" credentials: Any = None - """Your own google credentials created via your own mechanism""" + """Your own google credentials created via your own mechanism""" folder_id: Optional[str] = None """The folder id to load from.""" document_ids: Optional[List[str]] = None @@ -281,8 +281,8 @@ def _load_credentials(self) -> Any: if self.credentials: # use whatever was passed to us creds = self.credentials - return creds - + return creds + if not creds or not creds.valid: if creds and creds.expired and creds.refresh_token: creds.refresh(Request())