@Generated(value="by gapic-generator-java") public class GroundedGenerationServiceClient extends Object implements com.google.api.gax.core.BackgroundResource
This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (GroundedGenerationServiceClient groundedGenerationServiceClient =
GroundedGenerationServiceClient.create()) {
GenerateGroundedContentRequest request =
GenerateGroundedContentRequest.newBuilder()
.setLocation(LocationName.of("[PROJECT]", "[LOCATION]").toString())
.setSystemInstruction(GroundedGenerationContent.newBuilder().build())
.addAllContents(new ArrayList<GroundedGenerationContent>())
.setGenerationSpec(GenerateGroundedContentRequest.GenerationSpec.newBuilder().build())
.setGroundingSpec(GenerateGroundedContentRequest.GroundingSpec.newBuilder().build())
.putAllUserLabels(new HashMap<String, String>())
.build();
GenerateGroundedContentResponse response =
groundedGenerationServiceClient.generateGroundedContent(request);
}
Note: close() needs to be called on the GroundedGenerationServiceClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().
| Method | Description | Method Variants |
|---|---|---|
StreamGenerateGroundedContent |
Generates grounded content in a streaming fashion. |
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
GenerateGroundedContent |
Generates grounded content. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
CheckGrounding |
Performs a grounding check. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
See the individual methods for example code.
Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parse method to extract the individual identifiers contained within names that are returned.
This class can be customized by passing in a custom instance of GroundedGenerationServiceSettings to create(). For example:
To customize credentials:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
GroundedGenerationServiceSettings groundedGenerationServiceSettings =
GroundedGenerationServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
GroundedGenerationServiceClient groundedGenerationServiceClient =
GroundedGenerationServiceClient.create(groundedGenerationServiceSettings);
To customize the endpoint:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
GroundedGenerationServiceSettings groundedGenerationServiceSettings =
GroundedGenerationServiceSettings.newBuilder().setEndpoint(myEndpoint).build();
GroundedGenerationServiceClient groundedGenerationServiceClient =
GroundedGenerationServiceClient.create(groundedGenerationServiceSettings);
To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over the wire:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
GroundedGenerationServiceSettings groundedGenerationServiceSettings =
GroundedGenerationServiceSettings.newHttpJsonBuilder().build();
GroundedGenerationServiceClient groundedGenerationServiceClient =
GroundedGenerationServiceClient.create(groundedGenerationServiceSettings);
Please refer to the GitHub repository's samples for more quickstart code snippets.
| Modifier | Constructor and Description |
|---|---|
protected |
GroundedGenerationServiceClient(GroundedGenerationServiceSettings settings)
Constructs an instance of GroundedGenerationServiceClient, using the given settings.
|
protected |
GroundedGenerationServiceClient(GroundedGenerationServiceStub stub) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
awaitTermination(long duration,
TimeUnit unit) |
CheckGroundingResponse |
checkGrounding(CheckGroundingRequest request)
Performs a grounding check.
|
com.google.api.gax.rpc.UnaryCallable<CheckGroundingRequest,CheckGroundingResponse> |
checkGroundingCallable()
Performs a grounding check.
|
void |
close() |
static GroundedGenerationServiceClient |
create()
Constructs an instance of GroundedGenerationServiceClient with default settings.
|
static GroundedGenerationServiceClient |
create(GroundedGenerationServiceSettings settings)
Constructs an instance of GroundedGenerationServiceClient, using the given settings.
|
static GroundedGenerationServiceClient |
create(GroundedGenerationServiceStub stub)
Constructs an instance of GroundedGenerationServiceClient, using the given stub for making
calls.
|
GenerateGroundedContentResponse |
generateGroundedContent(GenerateGroundedContentRequest request)
Generates grounded content.
|
com.google.api.gax.rpc.UnaryCallable<GenerateGroundedContentRequest,GenerateGroundedContentResponse> |
generateGroundedContentCallable()
Generates grounded content.
|
GroundedGenerationServiceSettings |
getSettings() |
GroundedGenerationServiceStub |
getStub() |
boolean |
isShutdown() |
boolean |
isTerminated() |
void |
shutdown() |
void |
shutdownNow() |
com.google.api.gax.rpc.BidiStreamingCallable<GenerateGroundedContentRequest,GenerateGroundedContentResponse> |
streamGenerateGroundedContentCallable()
Generates grounded content in a streaming fashion.
|
protected GroundedGenerationServiceClient(GroundedGenerationServiceSettings settings) throws IOException
IOExceptionprotected GroundedGenerationServiceClient(GroundedGenerationServiceStub stub)
public static final GroundedGenerationServiceClient create() throws IOException
IOExceptionpublic static final GroundedGenerationServiceClient create(GroundedGenerationServiceSettings settings) throws IOException
IOExceptionpublic static final GroundedGenerationServiceClient create(GroundedGenerationServiceStub stub)
public final GroundedGenerationServiceSettings getSettings()
public GroundedGenerationServiceStub getStub()
public final com.google.api.gax.rpc.BidiStreamingCallable<GenerateGroundedContentRequest,GenerateGroundedContentResponse> streamGenerateGroundedContentCallable()
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (GroundedGenerationServiceClient groundedGenerationServiceClient =
GroundedGenerationServiceClient.create()) {
BidiStream<GenerateGroundedContentRequest, GenerateGroundedContentResponse> bidiStream =
groundedGenerationServiceClient.streamGenerateGroundedContentCallable().call();
GenerateGroundedContentRequest request =
GenerateGroundedContentRequest.newBuilder()
.setLocation(LocationName.of("[PROJECT]", "[LOCATION]").toString())
.setSystemInstruction(GroundedGenerationContent.newBuilder().build())
.addAllContents(new ArrayList<GroundedGenerationContent>())
.setGenerationSpec(GenerateGroundedContentRequest.GenerationSpec.newBuilder().build())
.setGroundingSpec(GenerateGroundedContentRequest.GroundingSpec.newBuilder().build())
.putAllUserLabels(new HashMap<String, String>())
.build();
bidiStream.send(request);
for (GenerateGroundedContentResponse response : bidiStream) {
// Do something when a response is received.
}
}
public final GenerateGroundedContentResponse generateGroundedContent(GenerateGroundedContentRequest request)
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (GroundedGenerationServiceClient groundedGenerationServiceClient =
GroundedGenerationServiceClient.create()) {
GenerateGroundedContentRequest request =
GenerateGroundedContentRequest.newBuilder()
.setLocation(LocationName.of("[PROJECT]", "[LOCATION]").toString())
.setSystemInstruction(GroundedGenerationContent.newBuilder().build())
.addAllContents(new ArrayList<GroundedGenerationContent>())
.setGenerationSpec(GenerateGroundedContentRequest.GenerationSpec.newBuilder().build())
.setGroundingSpec(GenerateGroundedContentRequest.GroundingSpec.newBuilder().build())
.putAllUserLabels(new HashMap<String, String>())
.build();
GenerateGroundedContentResponse response =
groundedGenerationServiceClient.generateGroundedContent(request);
}
request - The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException - if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<GenerateGroundedContentRequest,GenerateGroundedContentResponse> generateGroundedContentCallable()
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (GroundedGenerationServiceClient groundedGenerationServiceClient =
GroundedGenerationServiceClient.create()) {
GenerateGroundedContentRequest request =
GenerateGroundedContentRequest.newBuilder()
.setLocation(LocationName.of("[PROJECT]", "[LOCATION]").toString())
.setSystemInstruction(GroundedGenerationContent.newBuilder().build())
.addAllContents(new ArrayList<GroundedGenerationContent>())
.setGenerationSpec(GenerateGroundedContentRequest.GenerationSpec.newBuilder().build())
.setGroundingSpec(GenerateGroundedContentRequest.GroundingSpec.newBuilder().build())
.putAllUserLabels(new HashMap<String, String>())
.build();
ApiFuture<GenerateGroundedContentResponse> future =
groundedGenerationServiceClient.generateGroundedContentCallable().futureCall(request);
// Do something.
GenerateGroundedContentResponse response = future.get();
}
public final CheckGroundingResponse checkGrounding(CheckGroundingRequest request)
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (GroundedGenerationServiceClient groundedGenerationServiceClient =
GroundedGenerationServiceClient.create()) {
CheckGroundingRequest request =
CheckGroundingRequest.newBuilder()
.setGroundingConfig(
GroundingConfigName.of("[PROJECT]", "[LOCATION]", "[GROUNDING_CONFIG]")
.toString())
.setAnswerCandidate("answerCandidate-292402331")
.addAllFacts(new ArrayList<GroundingFact>())
.setGroundingSpec(CheckGroundingSpec.newBuilder().build())
.putAllUserLabels(new HashMap<String, String>())
.build();
CheckGroundingResponse response = groundedGenerationServiceClient.checkGrounding(request);
}
request - The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException - if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<CheckGroundingRequest,CheckGroundingResponse> checkGroundingCallable()
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (GroundedGenerationServiceClient groundedGenerationServiceClient =
GroundedGenerationServiceClient.create()) {
CheckGroundingRequest request =
CheckGroundingRequest.newBuilder()
.setGroundingConfig(
GroundingConfigName.of("[PROJECT]", "[LOCATION]", "[GROUNDING_CONFIG]")
.toString())
.setAnswerCandidate("answerCandidate-292402331")
.addAllFacts(new ArrayList<GroundingFact>())
.setGroundingSpec(CheckGroundingSpec.newBuilder().build())
.putAllUserLabels(new HashMap<String, String>())
.build();
ApiFuture<CheckGroundingResponse> future =
groundedGenerationServiceClient.checkGroundingCallable().futureCall(request);
// Do something.
CheckGroundingResponse response = future.get();
}
public final void close()
close in interface AutoCloseablepublic void shutdown()
shutdown in interface com.google.api.gax.core.BackgroundResourcepublic boolean isShutdown()
isShutdown in interface com.google.api.gax.core.BackgroundResourcepublic boolean isTerminated()
isTerminated in interface com.google.api.gax.core.BackgroundResourcepublic void shutdownNow()
shutdownNow in interface com.google.api.gax.core.BackgroundResourcepublic boolean awaitTermination(long duration,
TimeUnit unit)
throws InterruptedException
awaitTermination in interface com.google.api.gax.core.BackgroundResourceInterruptedExceptionCopyright © 2025 Google LLC. All rights reserved.