The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
Add service account support to Google Drive (#1761)
Kevin80d8db5f60c0
diff --git a/langchain/document_loaders/googledrive.py b/langchain/document_loaders/googledrive.pyindex cec86f50bc..d6c8951efe 100644--- a/langchain/document_loaders/googledrive.py+++ b/langchain/document_loaders/googledrive.py@@ -6,7 +6,8 @@# https://console.cloud.google.com/flows/enableapi?apiid=drive.googleapis.com# 3. Authorize credentials for desktop app:# https://developers.google.com/drive/api/quickstart/python#authorize_credentials_for_a_desktop_application # noqa: E501-+# 4. For service accounts visit+# https://cloud.google.com/iam/docs/service-accounts-createfrom pathlib import Pathfrom typing import Any, Dict, List, Optional@@ -22,6 +23,7 @@ SCOPES = ["https://www.googleapis.com/auth/drive.readonly"]class GoogleDriveLoader(BaseLoader, BaseModel):"""Loader that loads Google Docs from Google Drive."""+ service_account_key: Path = Path.home() / ".credentials" / "keys.json"credentials_path: Path = Path.home() / ".credentials" / "credentials.json"token_path: Path = Path.home() / ".credentials" / "token.json"folder_id: Optional[str] = None@@ -60,6 +62,7 @@ class GoogleDriveLoader(BaseLoader, BaseModel):# Adapted from https://developers.google.com/drive/api/v3/quickstart/pythontry:from google.auth.transport.requests import Request+ from google.oauth2 import service_accountfrom google.oauth2.credentials import Credentialsfrom google_auth_oauthlib.flow import InstalledAppFlowexcept ImportError:@@ -72,6 +75,11 @@ class GoogleDriveLoader(BaseLoader, BaseModel):)creds = None+ if self.service_account_key.exists():+ return service_account.Credentials.from_service_account_file(+ str(self.service_account_key), scopes=SCOPES+ )+if self.token_path.exists():creds = Credentials.from_authorized_user_file(str(self.token_path), SCOPES)