Skip to content

Commit 6421180

Browse files
authored
Fixed Spelling Error in _bytes_from_gsc() (#35)
- Also simplified Blob Retrieval code
1 parent 137fced commit 6421180

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

libs/vertexai/langchain_google_vertexai/_image_utils.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def load_bytes(self, image_string: str) -> bytes:
4646
"""
4747

4848
if image_string.startswith("gs://"):
49-
return self._bytes_from_gsc(image_string)
49+
return self._bytes_from_gcs(image_string)
5050

5151
if image_string.startswith("data:image/"):
5252
return self._bytes_from_b64(image_string)
@@ -115,8 +115,8 @@ def _bytes_from_url(self, url: str) -> bytes:
115115

116116
return response.content
117117

118-
def _bytes_from_gsc(self, gcs_uri: str) -> bytes:
119-
"""Gets image bytes from a google cloud storage uri.
118+
def _bytes_from_gcs(self, gcs_uri: str) -> bytes:
119+
"""Gets image bytes from a Google Cloud Storage uri.
120120
121121
Args:
122122
gcs_uri: Valid gcs uri.
@@ -129,15 +129,7 @@ def _bytes_from_gsc(self, gcs_uri: str) -> bytes:
129129
"""
130130

131131
gcs_client = storage.Client(project=self._project)
132-
133-
pieces = gcs_uri.split("/")
134-
135-
blobs = list(gcs_client.list_blobs(pieces[2], prefix="/".join(pieces[3:])))
136-
137-
if len(blobs) > 1:
138-
raise ValueError(f"Found more than one candidate for {gcs_uri}!")
139-
140-
return blobs[0].download_as_bytes()
132+
return storage.Blob.from_string(gcs_uri, gcs_client).download_as_bytes()
141133

142134
def _is_url(self, url_string: str) -> bool:
143135
"""Checks if a url is valid.

0 commit comments

Comments
 (0)