Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authentication via VertexAI #728

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/vanna/google/gemini_chat.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os

from ..base import VannaBase


Expand Down Expand Up @@ -30,8 +31,25 @@ def __init__(self, config=None):
self.chat_model = genai.GenerativeModel(model_name)
else:
# Authenticate using VertexAI
import google.auth
import vertexai
from vertexai.generative_models import GenerativeModel
self.chat_model = GenerativeModel(model_name)

json_file_path = config.get("google_credentials") # Assuming the JSON file path is provided in the config

if not json_file_path or not os.path.exists(json_file_path):
raise FileNotFoundError(f"JSON credentials file not found at: {json_file_path}")

try:
# Validate and set the JSON file path for GOOGLE_APPLICATION_CREDENTIALS
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = json_file_path

# Initialize VertexAI with the credentials
credentials, _ = google.auth.default()
vertexai.init(credentials=credentials)
self.chat_model = GenerativeModel(model_name)
except Exception as e:
raise RuntimeError(f"Failed to authenticate using JSON file: {e}")

def system_message(self, message: str) -> any:
return message
Expand Down