File tree Expand file tree Collapse file tree 1 file changed +23
-1
lines changed Expand file tree Collapse file tree 1 file changed +23
-1
lines changed Original file line number Diff line number Diff line change 11import os
2+
23from ..base import VannaBase
34
45
@@ -30,8 +31,29 @@ def __init__(self, config=None):
3031 self .chat_model = genai .GenerativeModel (model_name )
3132 else :
3233 # Authenticate using VertexAI
34+ import google .auth
35+ import vertexai
3336 from vertexai .generative_models import GenerativeModel
34- self .chat_model = GenerativeModel (model_name )
37+
38+ json_file_path = config .get ("google_credentials" ) # Assuming the JSON file path is provided in the config
39+
40+ if not json_file_path or not os .path .exists (json_file_path ):
41+ raise FileNotFoundError (f"JSON credentials file not found at: { json_file_path } " )
42+
43+ try :
44+ # Validate and set the JSON file path for GOOGLE_APPLICATION_CREDENTIALS
45+ os .environ ['GOOGLE_APPLICATION_CREDENTIALS' ] = json_file_path
46+
47+ # Initialize VertexAI with the credentials
48+ credentials , _ = google .auth .default ()
49+ vertexai .init (credentials = credentials )
50+ self .chat_model = GenerativeModel (model_name )
51+ except google .auth .exceptions .DefaultCredentialsError as e :
52+ raise RuntimeError (f"Default credentials error: { e } " )
53+ except google .auth .exceptions .TransportError as e :
54+ raise RuntimeError (f"Transport error during authentication: { e } " )
55+ except Exception as e :
56+ raise RuntimeError (f"Failed to authenticate using JSON file: { e } " )
3557
3658 def system_message (self , message : str ) -> any :
3759 return message
You can’t perform that action at this time.
0 commit comments