Skip to content

Commit

Permalink
Update GoogleDriveLoader to allow bring your own credentials (#605)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffbryner authored Nov 27, 2024
1 parent 0b5d16a commit d6749c3
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions libs/community/langchain_google_community/drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit d6749c3

Please sign in to comment.