Llama Indexでスプレッドシートの情報を読み込みたい
前提
Pythonの実行環境:Google Colaboratory
解決したいこと
Llama Indexとスプレッドシートの連携
Llama Indexの download_loader
を用いてスプレッドシートの情報を読み込ませたい
発生している問題・エラー
ValueError Traceback (most recent call last)
<ipython-input-1-4bec563806a0> in <cell line: 22>()
20 gdoc_ids = ['hogehoge']
21 loader = GoogleSheetsReader()
---> 22 documents = loader.load_data(gdoc_ids)
23 index = GPTSimpleVectorIndex.from_documents(documents)
4 frames
/usr/local/lib/python3.10/dist-packages/llama_index/readers/llamahub_modules/google_sheets/base.py in load_data(self, spreadsheet_ids)
59 results = []
60 for spreadsheet_id in spreadsheet_ids:
---> 61 sheet = self._load_sheet(spreadsheet_id)
62 results.append(
63 Document(sheet, extra_info={"spreadsheet_id": spreadsheet_id})
/usr/local/lib/python3.10/dist-packages/llama_index/readers/llamahub_modules/google_sheets/base.py in _load_sheet(self, spreadsheet_id)
76 import googleapiclient.discovery as discovery
77
---> 78 credentials = self._get_credentials()
79 sheets_service = discovery.build("sheets", "v4", credentials=credentials)
80 spreadsheet_data = (
/usr/local/lib/python3.10/dist-packages/llama_index/readers/llamahub_modules/google_sheets/base.py in _get_credentials(self)
126 creds.refresh(Request())
127 else:
--> 128 flow = InstalledAppFlow.from_client_secrets_file(
129 "credentials.json", SCOPES
130 )
/usr/local/lib/python3.10/dist-packages/google_auth_oauthlib/flow.py in from_client_secrets_file(cls, client_secrets_file, scopes, **kwargs)
199 client_config = json.load(json_file)
200
--> 201 return cls.from_client_config(client_config, scopes=scopes, **kwargs)
202
203 @property
/usr/local/lib/python3.10/dist-packages/google_auth_oauthlib/flow.py in from_client_config(cls, client_config, scopes, **kwargs)
157 client_type = "installed"
158 else:
--> 159 raise ValueError("Client secrets must be for a web or installed app.")
160
161 # these args cannot be passed to requests_oauthlib.OAuth2Session
ValueError: Client secrets must be for a web or installed app.
GoogleAPIの認証がうまく通っていないようです
コード
こちらの記事を参考にしました。
# パッケージのインストール
!pip install llama-index
import os
os.environ["OPENAI_API_KEY"] = "hogehoge"
import logging
import sys
from llama_index import GPTSimpleVectorIndex, SimpleDirectoryReader, download_loader
GoogleSheetsReader = download_loader('GoogleSheetsReader')
gdoc_ids = ['1zwhogehoge']
loader = GoogleSheetsReader()
documents = loader.load_data(gdoc_ids)
自分で試したこと
GoogleCloudConsoleにてサービスアカウントを作成し、新しい鍵を作成しJson形式でダウンロード。
実行ファイルと同じディレクトリに、credentials.json
ファイルとして設置しました。
credentials.json
{
"type": "service_account",
"project_id": "hogehoge",
"private_key_id": "1h2o3g4e",
"private_key": "-----BEGIN PRIVATE KEY-----\nHogEhOge=\n-----END PRIVATE KEY-----\n",
"client_email": "service-account-1@hoge1234.iam.gserviceaccount.com",
"client_id": "hoge1234",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/service-account-1%hoge1234.iam.gserviceaccount.com"
}
0 likes