Class TextSuggestionsServiceClient (0.2.0)

GitHub RepositoryProduct Reference

Service Description: Service that exposes Generative AI (GenAI) endpoints for creating and enhancing product text content, such as titles, descriptions, etc.

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 (TextSuggestionsServiceClient textSuggestionsServiceClient =
     TextSuggestionsServiceClient.create()) {
   String name = "name3373707";
   GenerateProductTextSuggestionsResponse response =
       textSuggestionsServiceClient.generateProductTextSuggestions(name);
 }
 

Note: close() needs to be called on the TextSuggestionsServiceClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().

Methods
Method Description Method Variants

GenerateProductTextSuggestions

GenerateProductTextSuggestions generates a set of candidate text completions (e.g., product titles, descriptions) based on provided product information. This endpoint leverages GenAI models to create suggestions for improving existing product text or generating new content.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • generateProductTextSuggestions(GenerateProductTextSuggestionsRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • generateProductTextSuggestions(String name)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • generateProductTextSuggestionsCallable()

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 TextSuggestionsServiceSettings 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
 TextSuggestionsServiceSettings textSuggestionsServiceSettings =
     TextSuggestionsServiceSettings.newBuilder()
         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
         .build();
 TextSuggestionsServiceClient textSuggestionsServiceClient =
     TextSuggestionsServiceClient.create(textSuggestionsServiceSettings);
 

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
 TextSuggestionsServiceSettings textSuggestionsServiceSettings =
     TextSuggestionsServiceSettings.newBuilder().setEndpoint(myEndpoint).build();
 TextSuggestionsServiceClient textSuggestionsServiceClient =
     TextSuggestionsServiceClient.create(textSuggestionsServiceSettings);
 

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
 TextSuggestionsServiceSettings textSuggestionsServiceSettings =
     TextSuggestionsServiceSettings.newHttpJsonBuilder().build();
 TextSuggestionsServiceClient textSuggestionsServiceClient =
     TextSuggestionsServiceClient.create(textSuggestionsServiceSettings);
 

Please refer to the GitHub repository's samples for more quickstart code snippets.

Inheritance

java.lang.Object > TextSuggestionsServiceClient

Static Methods

create()

public static final TextSuggestionsServiceClient create()

Constructs an instance of TextSuggestionsServiceClient with default settings.

Returns
Type Description
TextSuggestionsServiceClient
Exceptions
Type Description
IOException

create(TextSuggestionsServiceSettings settings)

public static final TextSuggestionsServiceClient create(TextSuggestionsServiceSettings settings)

Constructs an instance of TextSuggestionsServiceClient, using the given settings. The channels are created based on the settings passed in, or defaults for any settings that are not set.

Parameter
Name Description
settings TextSuggestionsServiceSettings
Returns
Type Description
TextSuggestionsServiceClient
Exceptions
Type Description
IOException

create(TextSuggestionsServiceStub stub)

public static final TextSuggestionsServiceClient create(TextSuggestionsServiceStub stub)

Constructs an instance of TextSuggestionsServiceClient, using the given stub for making calls. This is for advanced usage - prefer using create(TextSuggestionsServiceSettings).

Parameter
Name Description
stub TextSuggestionsServiceStub
Returns
Type Description
TextSuggestionsServiceClient

Constructors

TextSuggestionsServiceClient(TextSuggestionsServiceSettings settings)

protected TextSuggestionsServiceClient(TextSuggestionsServiceSettings settings)

Constructs an instance of TextSuggestionsServiceClient, using the given settings. This is protected so that it is easy to make a subclass, but otherwise, the static factory methods should be preferred.

Parameter
Name Description
settings TextSuggestionsServiceSettings

TextSuggestionsServiceClient(TextSuggestionsServiceStub stub)

protected TextSuggestionsServiceClient(TextSuggestionsServiceStub stub)
Parameter
Name Description
stub TextSuggestionsServiceStub

Methods

awaitTermination(long duration, TimeUnit unit)

public boolean awaitTermination(long duration, TimeUnit unit)
Parameters
Name Description
duration long
unit TimeUnit
Returns
Type Description
boolean
Exceptions
Type Description
InterruptedException

close()

public final void close()

generateProductTextSuggestions(GenerateProductTextSuggestionsRequest request)

public final GenerateProductTextSuggestionsResponse generateProductTextSuggestions(GenerateProductTextSuggestionsRequest request)

GenerateProductTextSuggestions generates a set of candidate text completions (e.g., product titles, descriptions) based on provided product information. This endpoint leverages GenAI models to create suggestions for improving existing product text or generating new content.

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 (TextSuggestionsServiceClient textSuggestionsServiceClient =
     TextSuggestionsServiceClient.create()) {
   GenerateProductTextSuggestionsRequest request =
       GenerateProductTextSuggestionsRequest.newBuilder()
           .setName("name3373707")
           .setProductInfo(ProductInfo.newBuilder().build())
           .setOutputSpec(OutputSpec.newBuilder().build())
           .addAllTitleExamples(new ArrayList<TitleExample>())
           .build();
   GenerateProductTextSuggestionsResponse response =
       textSuggestionsServiceClient.generateProductTextSuggestions(request);
 }
 
Parameter
Name Description
request GenerateProductTextSuggestionsRequest

The request object containing all of the parameters for the API call.

Returns
Type Description
GenerateProductTextSuggestionsResponse

generateProductTextSuggestions(String name)

public final GenerateProductTextSuggestionsResponse generateProductTextSuggestions(String name)

GenerateProductTextSuggestions generates a set of candidate text completions (e.g., product titles, descriptions) based on provided product information. This endpoint leverages GenAI models to create suggestions for improving existing product text or generating new content.

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 (TextSuggestionsServiceClient textSuggestionsServiceClient =
     TextSuggestionsServiceClient.create()) {
   String name = "name3373707";
   GenerateProductTextSuggestionsResponse response =
       textSuggestionsServiceClient.generateProductTextSuggestions(name);
 }
 
Parameter
Name Description
name String

Required. The name of the account to generate text suggestions for. This acts as a container for the request and does not affect the generation itself, as this is a stateless API. Format: accounts/{account}

Returns
Type Description
GenerateProductTextSuggestionsResponse

generateProductTextSuggestionsCallable()

public final UnaryCallable<GenerateProductTextSuggestionsRequest,GenerateProductTextSuggestionsResponse> generateProductTextSuggestionsCallable()

GenerateProductTextSuggestions generates a set of candidate text completions (e.g., product titles, descriptions) based on provided product information. This endpoint leverages GenAI models to create suggestions for improving existing product text or generating new content.

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 (TextSuggestionsServiceClient textSuggestionsServiceClient =
     TextSuggestionsServiceClient.create()) {
   GenerateProductTextSuggestionsRequest request =
       GenerateProductTextSuggestionsRequest.newBuilder()
           .setName("name3373707")
           .setProductInfo(ProductInfo.newBuilder().build())
           .setOutputSpec(OutputSpec.newBuilder().build())
           .addAllTitleExamples(new ArrayList<TitleExample>())
           .build();
   ApiFuture<GenerateProductTextSuggestionsResponse> future =
       textSuggestionsServiceClient.generateProductTextSuggestionsCallable().futureCall(request);
   // Do something.
   GenerateProductTextSuggestionsResponse response = future.get();
 }
 
Returns
Type Description
UnaryCallable<GenerateProductTextSuggestionsRequest,GenerateProductTextSuggestionsResponse>

getSettings()

public final TextSuggestionsServiceSettings getSettings()
Returns
Type Description
TextSuggestionsServiceSettings

getStub()

public TextSuggestionsServiceStub getStub()
Returns
Type Description
TextSuggestionsServiceStub

isShutdown()

public boolean isShutdown()
Returns
Type Description
boolean

isTerminated()

public boolean isTerminated()
Returns
Type Description
boolean

shutdown()

public void shutdown()

shutdownNow()

public void shutdownNow()