29
29
import com .google .cloud .vertexai .api .PredictionServiceSettings ;
30
30
import java .io .IOException ;
31
31
import java .util .Arrays ;
32
+ import java .util .List ;
32
33
import java .util .logging .Level ;
33
34
import java .util .logging .Logger ;
34
35
@@ -60,16 +61,38 @@ public class VertexAI implements AutoCloseable {
60
61
private LlmUtilityServiceClient llmUtilityRestClient = null ;
61
62
62
63
/**
63
- * Construct a VertexAI instance with custom credentials .
64
+ * Construct a VertexAI instance.
64
65
*
65
66
* @param projectId the default project to use when making API calls
66
67
* @param location the default location to use when making API calls
67
- * @param credentials the custom credentials to use when making API calls
68
68
*/
69
- public VertexAI (String projectId , String location , Credentials credentials ) {
69
+ public VertexAI (String projectId , String location ) {
70
70
this .projectId = projectId ;
71
71
this .location = location ;
72
72
this .apiEndpoint = String .format ("%s-aiplatform.googleapis.com" , this .location );
73
+ }
74
+
75
+ /**
76
+ * Construct a VertexAI instance with default transport layer.
77
+ *
78
+ * @param projectId the default project to use when making API calls
79
+ * @param location the default location to use when making API calls
80
+ * @param transport the default {@link Transport} layer to use to send API requests
81
+ */
82
+ public VertexAI (String projectId , String location , Transport transport ) {
83
+ this (projectId , location );
84
+ this .transport = transport ;
85
+ }
86
+
87
+ /**
88
+ * Construct a VertexAI instance with custom credentials.
89
+ *
90
+ * @param projectId the default project to use when making API calls
91
+ * @param location the default location to use when making API calls
92
+ * @param credentials the custom credentials to use when making API calls
93
+ */
94
+ public VertexAI (String projectId , String location , Credentials credentials ) {
95
+ this (projectId , location );
73
96
this .credentialsProvider = FixedCredentialsProvider .create (credentials );
74
97
}
75
98
@@ -91,9 +114,47 @@ public VertexAI(String projectId, String location, Transport transport, Credenti
91
114
*
92
115
* @param projectId the default project to use when making API calls
93
116
* @param location the default location to use when making API calls
117
+ * @param scopes List of scopes in the default credentials. Make sure you have specified
118
+ * "https://www.googleapis.com/auth/cloud-platform" scope to access resources on Vertex AI.
119
+ */
120
+ public VertexAI (String projectId , String location , List <String > scopes ) throws IOException {
121
+ this (projectId , location );
122
+
123
+ CredentialsProvider credentialsProvider =
124
+ scopes .size () == 0
125
+ ? null
126
+ : GoogleCredentialsProvider .newBuilder ()
127
+ .setScopesToApply (scopes )
128
+ .setUseJwtAccessWithScope (true )
129
+ .build ();
130
+ this .credentialsProvider = credentialsProvider ;
131
+ }
132
+
133
+ /**
134
+ * Construct a VertexAI instance with default transport layer and application default credentials.
135
+ *
136
+ * @param projectId the default project to use when making API calls
137
+ * @param location the default location to use when making API calls
138
+ * @param transport the default {@link Transport} layer to use to send API requests
139
+ * @param scopes List of scopes in the default credentials. Make sure you have specified
140
+ * "https://www.googleapis.com/auth/cloud-platform" scope to access resources on Vertex AI.
141
+ */
142
+ public VertexAI (String projectId , String location , Transport transport , List <String > scopes )
143
+ throws IOException {
144
+ this (projectId , location , scopes );
145
+ this .transport = transport ;
146
+ }
147
+
148
+ /**
149
+ * Construct a VertexAI instance with application default credentials.
150
+ *
151
+ * @deprecated Use {@link #VertexAI(String, String, List<String>)} instead.
152
+ * @param projectId the default project to use when making API calls
153
+ * @param location the default location to use when making API calls
94
154
* @param scopes collection of scopes in the default credentials. Make sure you have specified
95
155
* "https://www.googleapis.com/auth/cloud-platform" scope to access resources on Vertex AI.
96
156
*/
157
+ @ Deprecated
97
158
public VertexAI (String projectId , String location , String ... scopes ) throws IOException {
98
159
CredentialsProvider credentialsProvider =
99
160
scopes .length == 0
@@ -112,11 +173,13 @@ public VertexAI(String projectId, String location, String... scopes) throws IOEx
112
173
/**
113
174
* Construct a VertexAI instance with default transport layer and application default credentials.
114
175
*
176
+ * @deprecated Use {@link #VertexAI(String, String, Transport, List<String>)} instead.
115
177
* @param projectId the default project to use when making API calls
116
178
* @param location the default location to use when making API calls
117
179
* @param transport the default {@link Transport} layer to use to send API requests
118
180
* @param scopes collection of scopes in the default credentials
119
181
*/
182
+ @ Deprecated
120
183
public VertexAI (String projectId , String location , Transport transport , String ... scopes )
121
184
throws IOException {
122
185
this (projectId , location , scopes );
0 commit comments