From 9cc827de21312abf06015579dc36a1b245ca29fc Mon Sep 17 00:00:00 2001 From: Xiaofeng Huang Date: Wed, 2 Oct 2024 10:49:52 +0800 Subject: [PATCH 1/3] get port of redirect uri from google credentials file --- .../llama_index/readers/google/docs/base.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/llama-index-integrations/readers/llama-index-readers-google/llama_index/readers/google/docs/base.py b/llama-index-integrations/readers/llama-index-readers-google/llama_index/readers/google/docs/base.py index affac80454f79..4dc226a795459 100644 --- a/llama-index-integrations/readers/llama-index-readers-google/llama_index/readers/google/docs/base.py +++ b/llama-index-integrations/readers/llama-index-readers-google/llama_index/readers/google/docs/base.py @@ -1,5 +1,6 @@ """Google docs reader.""" +import json import logging import os import random @@ -112,7 +113,15 @@ def _get_credentials(self) -> Any: flow = InstalledAppFlow.from_client_secrets_file( "credentials.json", SCOPES ) - creds = flow.run_local_server(port=0) + + port = 8080 + with open("credentials.json", "r") as json_file: + client_config = json.load(json_file) + redirect_uris = client_config["web"].get("redirect_uris", []) + if len(redirect_uris) > 0: + port = redirect_uris[0].strip("/").split(":")[-1] + + creds = flow.run_local_server(port=port) # Save the credentials for the next run with open("token.json", "w") as token: token.write(creds.to_json()) From 5fa968306cafc78432f0c8799f90c9adf610c75b Mon Sep 17 00:00:00 2001 From: Xiaofeng Huang Date: Fri, 4 Oct 2024 15:16:05 +0800 Subject: [PATCH 2/3] fix the lint error --- .../llama_index/readers/google/docs/base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/llama-index-integrations/readers/llama-index-readers-google/llama_index/readers/google/docs/base.py b/llama-index-integrations/readers/llama-index-readers-google/llama_index/readers/google/docs/base.py index 4dc226a795459..b87ebbb7743c5 100644 --- a/llama-index-integrations/readers/llama-index-readers-google/llama_index/readers/google/docs/base.py +++ b/llama-index-integrations/readers/llama-index-readers-google/llama_index/readers/google/docs/base.py @@ -103,6 +103,7 @@ def _get_credentials(self) -> Any: Credentials, the obtained credential. """ creds = None + port = 8080 if os.path.exists("token.json"): creds = Credentials.from_authorized_user_file("token.json", SCOPES) # If there are no (valid) credentials available, let the user log in. @@ -114,8 +115,7 @@ def _get_credentials(self) -> Any: "credentials.json", SCOPES ) - port = 8080 - with open("credentials.json", "r") as json_file: + with open("credentials.json") as json_file: client_config = json.load(json_file) redirect_uris = client_config["web"].get("redirect_uris", []) if len(redirect_uris) > 0: From e72f0030e45353bfc72cf8ddf6226449da4b31c8 Mon Sep 17 00:00:00 2001 From: Logan Markewich Date: Mon, 14 Oct 2024 13:01:54 -0600 Subject: [PATCH 3/3] vbump --- .../readers/llama-index-readers-google/pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llama-index-integrations/readers/llama-index-readers-google/pyproject.toml b/llama-index-integrations/readers/llama-index-readers-google/pyproject.toml index aaf3adefdeb25..2cce97748e141 100644 --- a/llama-index-integrations/readers/llama-index-readers-google/pyproject.toml +++ b/llama-index-integrations/readers/llama-index-readers-google/pyproject.toml @@ -47,7 +47,7 @@ maintainers = [ ] name = "llama-index-readers-google" readme = "README.md" -version = "0.4.1" +version = "0.4.2" [tool.poetry.dependencies] python = ">=3.10,<4.0"