Skip to content

Commit e8994c7

Browse files
BREAKING_CHANGE: [vertexai] make client getters in VertexAI private (#10550)
PiperOrigin-RevId: 616185850 Co-authored-by: Jaycee Li <jayceeli@google.com>
1 parent 840df96 commit e8994c7

File tree

2 files changed

+51
-34
lines changed

2 files changed

+51
-34
lines changed

java-vertexai/google-cloud-vertexai/src/main/java/com/google/cloud/vertexai/VertexAI.java

+42-6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.google.cloud.vertexai;
1818

19+
import com.google.api.core.InternalApi;
1920
import com.google.api.gax.core.CredentialsProvider;
2021
import com.google.api.gax.core.FixedCredentialsProvider;
2122
import com.google.api.gax.core.GaxProperties;
@@ -220,11 +221,30 @@ public void setApiEndpoint(String apiEndpoint) {
220221
}
221222
}
222223

224+
/**
225+
* Returns the {@link PredictionServiceClient} with GRPC or REST, based on the Transport type. The
226+
* client will be instantiated when the first prediction API call is made.
227+
*
228+
* @return {@link PredictionServiceClient} that send requests to the backing service through
229+
* method calls that map to the API methods.
230+
*/
231+
@InternalApi
232+
public PredictionServiceClient getPredictionServiceClient() throws IOException {
233+
if (this.transport == Transport.GRPC) {
234+
return getPredictionServiceGrpcClient();
235+
} else {
236+
return getPredictionServiceRestClient();
237+
}
238+
}
239+
223240
/**
224241
* Returns the {@link PredictionServiceClient} with GRPC. The client will be instantiated when the
225242
* first prediction API call is made.
243+
*
244+
* @return {@link PredictionServiceClient} that send GRPC requests to the backing service through
245+
* method calls that map to the API methods.
226246
*/
227-
public PredictionServiceClient getPredictionServiceClient() throws IOException {
247+
private PredictionServiceClient getPredictionServiceGrpcClient() throws IOException {
228248
if (predictionServiceClient == null) {
229249
PredictionServiceSettings.Builder settingsBuilder = PredictionServiceSettings.newBuilder();
230250
settingsBuilder.setEndpoint(String.format("%s:443", this.apiEndpoint));
@@ -257,7 +277,7 @@ public PredictionServiceClient getPredictionServiceClient() throws IOException {
257277
* @return {@link PredictionServiceClient} that send REST requests to the backing service through
258278
* method calls that map to the API methods.
259279
*/
260-
public PredictionServiceClient getPredictionServiceRestClient() throws IOException {
280+
private PredictionServiceClient getPredictionServiceRestClient() throws IOException {
261281
if (predictionServiceRestClient == null) {
262282
PredictionServiceSettings.Builder settingsBuilder =
263283
PredictionServiceSettings.newHttpJsonBuilder();
@@ -284,14 +304,30 @@ public PredictionServiceClient getPredictionServiceRestClient() throws IOExcepti
284304
return predictionServiceRestClient;
285305
}
286306

307+
/**
308+
* Returns the {@link LlmUtilityServiceClient} with GRPC or REST, based on the Transport type. The
309+
* client will be instantiated when the first API call is made.
310+
*
311+
* @return {@link LlmUtilityServiceClient} that makes calls to the backing service through method
312+
* calls that map to the API methods.
313+
*/
314+
@InternalApi
315+
public LlmUtilityServiceClient getLlmUtilityClient() throws IOException {
316+
if (this.transport == Transport.GRPC) {
317+
return getLlmUtilityGrpcClient();
318+
} else {
319+
return getLlmUtilityRestClient();
320+
}
321+
}
322+
287323
/**
288324
* Returns the {@link LlmUtilityServiceClient} with GRPC. The client will be instantiated when the
289-
* first prediction API call is made.
325+
* first API call is made.
290326
*
291327
* @return {@link LlmUtilityServiceClient} that makes gRPC calls to the backing service through
292328
* method calls that map to the API methods.
293329
*/
294-
public LlmUtilityServiceClient getLlmUtilityClient() throws IOException {
330+
private LlmUtilityServiceClient getLlmUtilityGrpcClient() throws IOException {
295331
if (llmUtilityClient == null) {
296332
LlmUtilityServiceSettings.Builder settingsBuilder = LlmUtilityServiceSettings.newBuilder();
297333
settingsBuilder.setEndpoint(String.format("%s:443", this.apiEndpoint));
@@ -319,12 +355,12 @@ public LlmUtilityServiceClient getLlmUtilityClient() throws IOException {
319355

320356
/**
321357
* Returns the {@link LlmUtilityServiceClient} with REST. The client will be instantiated when the
322-
* first prediction API call is made.
358+
* first API call is made.
323359
*
324360
* @return {@link LlmUtilityServiceClient} that makes REST requests to the backing service through
325361
* method calls that map to the API methods.
326362
*/
327-
public LlmUtilityServiceClient getLlmUtilityRestClient() throws IOException {
363+
private LlmUtilityServiceClient getLlmUtilityRestClient() throws IOException {
328364
if (llmUtilityRestClient == null) {
329365
LlmUtilityServiceSettings.Builder settingsBuilder =
330366
LlmUtilityServiceSettings.newHttpJsonBuilder();

java-vertexai/google-cloud-vertexai/src/main/java/com/google/cloud/vertexai/generativeai/GenerativeModel.java

+9-28
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package com.google.cloud.vertexai.generativeai;
1818

1919
import com.google.api.core.BetaApi;
20-
import com.google.cloud.vertexai.Transport;
2120
import com.google.cloud.vertexai.VertexAI;
2221
import com.google.cloud.vertexai.api.Content;
2322
import com.google.cloud.vertexai.api.CountTokensRequest;
@@ -289,11 +288,7 @@ public CountTokensResponse countTokens(List<Content> contents) throws IOExceptio
289288
@BetaApi
290289
private CountTokensResponse countTokensFromRequest(CountTokensRequest request)
291290
throws IOException {
292-
if (vertexAi.getTransport() == Transport.REST) {
293-
return vertexAi.getLlmUtilityRestClient().countTokens(request);
294-
} else {
295-
return vertexAi.getLlmUtilityClient().countTokens(request);
296-
}
291+
return vertexAi.getLlmUtilityClient().countTokens(request);
297292
}
298293

299294
/**
@@ -520,11 +515,7 @@ public GenerateContentResponse generateContent(
520515
*/
521516
private GenerateContentResponse generateContent(GenerateContentRequest request)
522517
throws IOException {
523-
if (vertexAi.getTransport() == Transport.REST) {
524-
return vertexAi.getPredictionServiceRestClient().generateContentCallable().call(request);
525-
} else {
526-
return vertexAi.getPredictionServiceClient().generateContentCallable().call(request);
527-
}
518+
return vertexAi.getPredictionServiceClient().generateContentCallable().call(request);
528519
}
529520

530521
/**
@@ -932,23 +923,13 @@ public ResponseStream<GenerateContentResponse> generateContentStream(
932923
*/
933924
private ResponseStream<GenerateContentResponse> generateContentStream(
934925
GenerateContentRequest request) throws IOException {
935-
if (vertexAi.getTransport() == Transport.REST) {
936-
return new ResponseStream(
937-
new ResponseStreamIteratorWithHistory(
938-
vertexAi
939-
.getPredictionServiceRestClient()
940-
.streamGenerateContentCallable()
941-
.call(request)
942-
.iterator()));
943-
} else {
944-
return new ResponseStream(
945-
new ResponseStreamIteratorWithHistory(
946-
vertexAi
947-
.getPredictionServiceClient()
948-
.streamGenerateContentCallable()
949-
.call(request)
950-
.iterator()));
951-
}
926+
return new ResponseStream(
927+
new ResponseStreamIteratorWithHistory(
928+
vertexAi
929+
.getPredictionServiceClient()
930+
.streamGenerateContentCallable()
931+
.call(request)
932+
.iterator()));
952933
}
953934

954935
/**

0 commit comments

Comments
 (0)