public class VertexAI implements AutoCloseableThis 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, Credentials credentials)
public VertexAI(String projectId, String location, Credentials credentials)Construct a VertexAI instance with custom credentials.
| Parameters | |
|---|---|
| Name | Description |
projectId |
Stringthe default project to use when making API calls |
location |
Stringthe default location to use when making API calls |
credentials |
com.google.auth.Credentialsthe custom credentials to use when making API calls |
VertexAI(String projectId, String location, Transport transport, Credentials credentials)
public VertexAI(String projectId, String location, Transport transport, Credentials credentials)Construct a VertexAI instance with default transport layer and custom credentials.
| Parameters | |
|---|---|
| Name | Description |
projectId |
Stringthe default project to use when making API calls |
location |
Stringthe default location to use when making API calls |
transport |
Transportthe default Transport layer to use to send API requests |
credentials |
com.google.auth.Credentialsthe 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 |
Stringthe default project to use when making API calls |
location |
Stringthe default location to use when making API calls |
transport |
Transportthe 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 |
Stringthe default project to use when making API calls |
location |
Stringthe default location to use when making API calls |
scopes |
String[]collection of scopes in the default credentials. Make sure you have specified "https://www.googleapis.com/auth/cloud-platform" scope to access resources on Vertex AI. |
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 |
|
getCredentials()
public Credentials getCredentials()Returns the default credentials to use when making API calls.
| Returns | |
|---|---|
| Type | Description |
com.google.auth.Credentials |
|
| Exceptions | |
|---|---|
| Type | Description |
IOException |
|
getLlmUtilityClient()
public LlmUtilityServiceClient getLlmUtilityClient()Returns the PredictionServiceClient with GRPC. The client will be instantiated when the first prediction API call is made.
| Returns | |
|---|---|
| Type | Description |
LlmUtilityServiceClient |
|
| Exceptions | |
|---|---|
| Type | Description |
IOException |
|
getLlmUtilityRestClient()
public LlmUtilityServiceClient getLlmUtilityRestClient()Returns the PredictionServiceClient with GRPC. The client will be instantiated when the first prediction API call is made.
| Returns | |
|---|---|
| Type | Description |
LlmUtilityServiceClient |
|
| Exceptions | |
|---|---|
| Type | Description |
IOException |
|
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 |
|
setApiEndpoint(String apiEndpoint)
public void setApiEndpoint(String apiEndpoint)Sets the value for #getApiEndpoint().
| Parameter | |
|---|---|
| Name | Description |
apiEndpoint |
String |
setTransport(Transport transport)
public void setTransport(Transport transport)Sets the value for #getTransport().
| Parameter | |
|---|---|
| Name | Description |
transport |
Transport |