Skip to content

Commit

Permalink
[vertexai]: Use one gcs client in Imageutils (#609)
Browse files Browse the repository at this point in the history
  • Loading branch information
david-gang authored Nov 27, 2024
1 parent 69be452 commit ef44612
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from pydantic import BaseModel

if TYPE_CHECKING:
from anthropic.types import RawMessageStreamEvent # type: ignore
from anthropic.types import RawMessageStreamEvent

_message_type_lookups = {
"human": "user",
Expand Down
7 changes: 6 additions & 1 deletion libs/vertexai/langchain_google_vertexai/_image_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import re
from enum import Enum
from functools import cached_property
from typing import Dict, Optional, Union
from urllib.parse import urlparse

Expand Down Expand Up @@ -43,6 +44,10 @@ def __init__(
"""
self._project = project

@cached_property
def _storage_client(self):
return storage.Client(project=self._project)

def load_bytes(self, image_string: str) -> bytes:
"""Routes to the correct loader based on the image_string.
Expand Down Expand Up @@ -198,7 +203,7 @@ def _blob_from_gcs(self, gcs_uri: str) -> storage.Blob:
storage.Blob
"""

gcs_client = storage.Client(project=self._project)
gcs_client = self._storage_client
blob = storage.Blob.from_string(gcs_uri, gcs_client)
blob.reload(client=gcs_client)
return blob
Expand Down
2 changes: 1 addition & 1 deletion libs/vertexai/langchain_google_vertexai/model_garden.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def __init__(self, **kwargs: Any) -> None:

@model_validator(mode="after")
def validate_environment(self) -> Self:
from anthropic import ( # type: ignore
from anthropic import (
AnthropicVertex,
AsyncAnthropicVertex,
)
Expand Down

0 comments on commit ef44612

Please sign in to comment.