Skip to content

Commit e2a7888

Browse files
kotamatkotamatcrazywoola
authored
Fix: setup google-storage client (langgenius#4296)
Co-authored-by: kotamat <[email protected]> Co-authored-by: crazywoola <[email protected]>
1 parent 5d6d0e6 commit e2a7888

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

api/extensions/storage/google_storage.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import base64
2+
import io
23
from collections.abc import Generator
34
from contextlib import closing
45

@@ -15,14 +16,19 @@ def __init__(self, app: Flask):
1516
super().__init__(app)
1617
app_config = self.app.config
1718
self.bucket_name = app_config.get('GOOGLE_STORAGE_BUCKET_NAME')
18-
service_account_json = base64.b64decode(app_config.get('GOOGLE_STORAGE_SERVICE_ACCOUNT_JSON_BASE64')).decode(
19-
'utf-8')
20-
self.client = GoogleCloudStorage.Client().from_service_account_json(service_account_json)
19+
service_account_json_str = app_config.get('GOOGLE_STORAGE_SERVICE_ACCOUNT_JSON_BASE64')
20+
# if service_account_json_str is empty, use Application Default Credentials
21+
if service_account_json_str:
22+
service_account_json = base64.b64decode(service_account_json_str).decode('utf-8')
23+
self.client = GoogleCloudStorage.Client.from_service_account_info(service_account_json)
24+
else:
25+
self.client = GoogleCloudStorage.Client()
2126

2227
def save(self, filename, data):
2328
bucket = self.client.get_bucket(self.bucket_name)
2429
blob = bucket.blob(filename)
25-
blob.upload_from_file(data)
30+
with io.BytesIO(data) as stream:
31+
blob.upload_from_file(stream)
2632

2733
def load_once(self, filename: str) -> bytes:
2834
bucket = self.client.get_bucket(self.bucket_name)

docker/docker-compose.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ services:
8888
AZURE_BLOB_ACCOUNT_URL: 'https://<your_account_name>.blob.core.windows.net'
8989
# The Google storage configurations, only available when STORAGE_TYPE is `google-storage`.
9090
GOOGLE_STORAGE_BUCKET_NAME: 'yout-bucket-name'
91+
# if you want to use Application Default Credentials, you can leave GOOGLE_STORAGE_SERVICE_ACCOUNT_JSON_BASE64 empty.
9192
GOOGLE_STORAGE_SERVICE_ACCOUNT_JSON_BASE64: 'your-google-service-account-json-base64-string'
9293
# The type of vector store to use. Supported values are `weaviate`, `qdrant`, `milvus`, `relyt`.
9394
VECTOR_STORE: weaviate
@@ -226,6 +227,7 @@ services:
226227
AZURE_BLOB_ACCOUNT_URL: 'https://<your_account_name>.blob.core.windows.net'
227228
# The Google storage configurations, only available when STORAGE_TYPE is `google-storage`.
228229
GOOGLE_STORAGE_BUCKET_NAME: 'yout-bucket-name'
230+
# if you want to use Application Default Credentials, you can leave GOOGLE_STORAGE_SERVICE_ACCOUNT_JSON_BASE64 empty.
229231
GOOGLE_STORAGE_SERVICE_ACCOUNT_JSON_BASE64: 'your-google-service-account-json-base64-string'
230232
# The type of vector store to use. Supported values are `weaviate`, `qdrant`, `milvus`, `relyt`, `pgvector`.
231233
VECTOR_STORE: weaviate

0 commit comments

Comments
 (0)