Skip to content

Commit

Permalink
update var name
Browse files Browse the repository at this point in the history
  • Loading branch information
cyyeh committed Oct 1, 2024
1 parent bb05a5a commit 85535e9
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions wren-ai-service/src/providers/llm/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,23 @@ def __init__(
)

# check if the model is actually Vertex AI model
self.vertexai_creds = None
self._vertexai_creds = None
if model.startswith("google/"):
self.vertexai_creds, _ = google.auth.default(
self._vertexai_creds, _ = google.auth.default(
scopes=["https://www.googleapis.com/auth/cloud-platform"]
)

def __getattr__(self, name: str) -> Any:
# dealing with auto-refreshing expired credential
# https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/call-vertex-using-openai-library#refresh_your_credentials
if self.vertexai_creds and not self.vertexai_creds.valid:
if self._vertexai_creds and not self._vertexai_creds.valid:
auth_req = google.auth.transport.requests.Request()
self.vertexai_creds.refresh(auth_req)
self._vertexai_creds.refresh(auth_req)

if not self.vertexai_creds.valid:
if not self._vertexai_creds.valid:
raise RuntimeError("Unable to refresh auth")

self.client.api_key = self.vertexai_creds.token
self.client.api_key = self._vertexai_creds.token
return getattr(self.client, name)

@component.output_types(replies=List[str], meta=List[Dict[str, Any]])
Expand Down

0 comments on commit 85535e9

Please sign in to comment.