Skip to content

Commit

Permalink
Merge branch 'main' into release1
Browse files Browse the repository at this point in the history
  • Loading branch information
lkuligin authored Feb 27, 2024
2 parents 028ea48 + 6421180 commit 7bd9a2d
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions libs/vertexai/langchain_google_vertexai/_image_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def load_bytes(self, image_string: str) -> bytes:
"""

if image_string.startswith("gs://"):
return self._bytes_from_gsc(image_string)
return self._bytes_from_gcs(image_string)

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

return response.content

def _bytes_from_gsc(self, gcs_uri: str) -> bytes:
"""Gets image bytes from a google cloud storage uri.
def _bytes_from_gcs(self, gcs_uri: str) -> bytes:
"""Gets image bytes from a Google Cloud Storage uri.
Args:
gcs_uri: Valid gcs uri.
Expand All @@ -129,15 +129,7 @@ def _bytes_from_gsc(self, gcs_uri: str) -> bytes:
"""

gcs_client = storage.Client(project=self._project)

pieces = gcs_uri.split("/")

blobs = list(gcs_client.list_blobs(pieces[2], prefix="/".join(pieces[3:])))

if len(blobs) > 1:
raise ValueError(f"Found more than one candidate for {gcs_uri}!")

return blobs[0].download_as_bytes()
return storage.Blob.from_string(gcs_uri, gcs_client).download_as_bytes()

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

0 comments on commit 7bd9a2d

Please sign in to comment.