File tree 1 file changed +23
-1
lines changed
1 file changed +23
-1
lines changed Original file line number Diff line number Diff line change 1
1
import os
2
+
2
3
from ..base import VannaBase
3
4
4
5
@@ -30,8 +31,29 @@ def __init__(self, config=None):
30
31
self .chat_model = genai .GenerativeModel (model_name )
31
32
else :
32
33
# Authenticate using VertexAI
34
+ import google .auth
35
+ import vertexai
33
36
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 } " )
35
57
36
58
def system_message (self , message : str ) -> any :
37
59
return message
You can’t perform that action at this time.
0 commit comments