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
AutoCloseableInherited Members
Constructors
VertexAI()
public VertexAI()
Constructs a VertexAI instance.
Note: SDK infers location from runtime environment first. If there is no location
inferred from runtime environment, SDK will default location to us-central1
.
SDK will infer projectId from runtime environment and GoogleCredentials.
VertexAI(String projectId, String location)
public VertexAI(String projectId, String location)
Constructs a VertexAI instance.
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 |
Methods
close()
public void close()
Closes the VertexAI instance together with all its instantiated clients.
getApiEndpoint()
public String getApiEndpoint()
Returns the default endpoint to use when making API calls.
Returns | |
---|---|
Type | Description |
String |
API endpoint in string format. |
getCredentials()
public Credentials getCredentials()
Returns the default credentials to use when making API calls.
Returns | |
---|---|
Type | Description |
com.google.auth.Credentials |
Credentials to use when making API calls. |
Exceptions | |
---|---|
Type | Description |
IOException |
getHeaders()
public Map<String,String> getHeaders()
Returns the headers to use when making API calls.
getLlmUtilityClient()
public LlmUtilityServiceClient getLlmUtilityClient()
Returns the LlmUtilityServiceClient with GRPC or REST, based on the Transport type. The client will be instantiated when the first API call is made.
Returns | |
---|---|
Type | Description |
LlmUtilityServiceClient |
LlmUtilityServiceClient that makes calls to the backing service through method calls that map to the API methods. |
getLocation()
public String getLocation()
Returns the default location to use when making API calls.
Returns | |
---|---|
Type | Description |
String |
Location in string format. |
getPredictionServiceClient()
public PredictionServiceClient getPredictionServiceClient()
Returns the PredictionServiceClient with GRPC or REST, based on the Transport type. The client will be instantiated when the first prediction API call is made.
Returns | |
---|---|
Type | Description |
PredictionServiceClient |
PredictionServiceClient that send requests to the backing service through method calls that map to the API methods. |
getProjectId()
public String getProjectId()
Returns the default project to use when making API calls.
Returns | |
---|---|
Type | Description |
String |
Project ID in string format. |
getTransport()
public Transport getTransport()
Returns the default Transport layer to use to send API requests.