public class VertexAI implements AutoCloseable
This class holds default settings and credentials to make Vertex AI API calls.
Note: The VertexAI instance will start a service client when the first API call is made. Please close the VertexAI instance after making any API calls so that clients get closed as well.
try (VertexAI vertexAi = new VertexAI("my-project", "us-central1"); ) {
GenerativeModel model = new GenerativeModel("gemini-pro", vertexAi)
// Do something with the model.
}
Implements
AutoCloseableConstructors
VertexAI(String projectId, String location, GoogleCredentials credentials)
public VertexAI(String projectId, String location, GoogleCredentials credentials)
Construct a VertexAI instance with custom credentials.
Parameters | |
---|---|
Name | Description |
projectId |
String the default project to use when making API calls |
location |
String the default location to use when making API calls |
credentials |
com.google.auth.oauth2.GoogleCredentials the custom credentials to use when making API calls |
VertexAI(String projectId, String location, Transport transport, GoogleCredentials credentials)
public VertexAI(String projectId, String location, Transport transport, GoogleCredentials credentials)
Construct a VertexAI instance with default transport layer and custom credentials.
Parameters | |
---|---|
Name | Description |
projectId |
String the default project to use when making API calls |
location |
String the default location to use when making API calls |
transport |
Transport the default Transport layer to use to send API requests |
credentials |
com.google.auth.oauth2.GoogleCredentials the default custom credentials to use when making API calls |
VertexAI(String projectId, String location, Transport transport, String[] scopes)
public VertexAI(String projectId, String location, Transport transport, String[] scopes)
Construct a VertexAI instance with default transport layer and application default credentials.
Parameters | |
---|---|
Name | Description |
projectId |
String the default project to use when making API calls |
location |
String the default location to use when making API calls |
transport |
Transport the default Transport layer to use to send API requests |
scopes |
String[] collection of scopes in the default credentials |
VertexAI(String projectId, String location, String[] scopes)
public VertexAI(String projectId, String location, String[] scopes)
Construct a VertexAI instance with application default credentials.
Parameters | |
---|---|
Name | Description |
projectId |
String the default project to use when making API calls |
location |
String the default location to use when making API calls |
scopes |
String[] collection of scopes in the default credentials |
Methods
close()
public void close()
Closes the VertexAI instance together with all its instantiated clients.
getCredentials()
public GoogleCredentials getCredentials()
Returns the default credentials to use when making API calls.
Returns | |
---|---|
Type | Description |
com.google.auth.oauth2.GoogleCredentials |
getLocation()
public String getLocation()
Returns the default location to use when making API calls.
Returns | |
---|---|
Type | Description |
String |
getPredictionServiceClient()
public PredictionServiceClient getPredictionServiceClient()
Returns the PredictionServiceClient with GRPC. The client will be instantiated when the first prediction API call is made.
Returns | |
---|---|
Type | Description |
PredictionServiceClient |
Exceptions | |
---|---|
Type | Description |
IOException |
getPredictionServiceRestClient()
public PredictionServiceClient getPredictionServiceRestClient()
Returns the PredictionServiceClient with REST. The client will be instantiated when the first prediction API call is made.
Returns | |
---|---|
Type | Description |
PredictionServiceClient |
Exceptions | |
---|---|
Type | Description |
IOException |
getProjectId()
public String getProjectId()
Returns the default project to use when making API calls.
Returns | |
---|---|
Type | Description |
String |
getTransport()
public Transport getTransport()
Returns the default Transport layer to use to send API requests.
Returns | |
---|---|
Type | Description |
Transport |
setTransport(Transport transport)
public void setTransport(Transport transport)
Sets the value for #getTransport().
Parameter | |
---|---|
Name | Description |
transport |
Transport |