@BetaApi @Generated(value="by gapic-generator-java") public class ModelArmorClient 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 (ModelArmorClient modelArmorClient = ModelArmorClient.create()) {
TemplateName name = TemplateName.of("[PROJECT]", "[LOCATION]", "[TEMPLATE]");
Template response = modelArmorClient.getTemplate(name);
}
Note: close() needs to be called on the ModelArmorClient 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 |
|---|---|---|
ListTemplates |
Lists Templates in a given project and location. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
GetTemplate |
Gets details of a single Template. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
CreateTemplate |
Creates a new Template in a given project and location. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
UpdateTemplate |
Updates the parameters of a single Template. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
DeleteTemplate |
Deletes a single Template. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
GetFloorSetting |
Gets details of a single floor setting of a project |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
UpdateFloorSetting |
Updates the parameters of a single floor setting of a project |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
SanitizeUserPrompt |
Sanitizes User Prompt. |
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.
|
SanitizeModelResponse |
Sanitizes Model Response. |
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.
|
ListLocations |
Lists information about the supported locations for this service. |
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.
|
GetLocation |
Gets information about a location. |
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 ModelArmorSettings 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
ModelArmorSettings modelArmorSettings =
ModelArmorSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
ModelArmorClient modelArmorClient = ModelArmorClient.create(modelArmorSettings);
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
ModelArmorSettings modelArmorSettings =
ModelArmorSettings.newBuilder().setEndpoint(myEndpoint).build();
ModelArmorClient modelArmorClient = ModelArmorClient.create(modelArmorSettings);
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
ModelArmorSettings modelArmorSettings = ModelArmorSettings.newHttpJsonBuilder().build();
ModelArmorClient modelArmorClient = ModelArmorClient.create(modelArmorSettings);
Please refer to the GitHub repository's samples for more quickstart code snippets.
| Modifier and Type | Class and Description |
|---|---|
static class |
ModelArmorClient.ListLocationsFixedSizeCollection |
static class |
ModelArmorClient.ListLocationsPage |
static class |
ModelArmorClient.ListLocationsPagedResponse |
static class |
ModelArmorClient.ListTemplatesFixedSizeCollection |
static class |
ModelArmorClient.ListTemplatesPage |
static class |
ModelArmorClient.ListTemplatesPagedResponse |
| Modifier | Constructor and Description |
|---|---|
protected |
ModelArmorClient(ModelArmorSettings settings)
Constructs an instance of ModelArmorClient, using the given settings.
|
protected |
ModelArmorClient(ModelArmorStub stub) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
awaitTermination(long duration,
TimeUnit unit) |
void |
close() |
static ModelArmorClient |
create()
Constructs an instance of ModelArmorClient with default settings.
|
static ModelArmorClient |
create(ModelArmorSettings settings)
Constructs an instance of ModelArmorClient, using the given settings.
|
static ModelArmorClient |
create(ModelArmorStub stub)
Constructs an instance of ModelArmorClient, using the given stub for making calls.
|
Template |
createTemplate(CreateTemplateRequest request)
Creates a new Template in a given project and location.
|
Template |
createTemplate(LocationName parent,
Template template,
String templateId)
Creates a new Template in a given project and location.
|
Template |
createTemplate(String parent,
Template template,
String templateId)
Creates a new Template in a given project and location.
|
com.google.api.gax.rpc.UnaryCallable<CreateTemplateRequest,Template> |
createTemplateCallable()
Creates a new Template in a given project and location.
|
void |
deleteTemplate(DeleteTemplateRequest request)
Deletes a single Template.
|
void |
deleteTemplate(String name)
Deletes a single Template.
|
void |
deleteTemplate(TemplateName name)
Deletes a single Template.
|
com.google.api.gax.rpc.UnaryCallable<DeleteTemplateRequest,com.google.protobuf.Empty> |
deleteTemplateCallable()
Deletes a single Template.
|
FloorSetting |
getFloorSetting(FloorSettingName name)
Gets details of a single floor setting of a project
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 (ModelArmorClient modelArmorClient = ModelArmorClient.create()) {
FloorSettingName name = FloorSettingName.ofProjectLocationName("[PROJECT]", "[LOCATION]");
FloorSetting response = modelArmorClient.getFloorSetting(name);
}
|
FloorSetting |
getFloorSetting(GetFloorSettingRequest request)
Gets details of a single floor setting of a project
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 (ModelArmorClient modelArmorClient = ModelArmorClient.create()) {
GetFloorSettingRequest request =
GetFloorSettingRequest.newBuilder()
.setName(FloorSettingName.ofProjectLocationName("[PROJECT]", "[LOCATION]").toString())
.build();
FloorSetting response = modelArmorClient.getFloorSetting(request);
}
|
FloorSetting |
getFloorSetting(String name)
Gets details of a single floor setting of a project
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 (ModelArmorClient modelArmorClient = ModelArmorClient.create()) {
String name = FloorSettingName.ofProjectLocationName("[PROJECT]", "[LOCATION]").toString();
FloorSetting response = modelArmorClient.getFloorSetting(name);
}
|
com.google.api.gax.rpc.UnaryCallable<GetFloorSettingRequest,FloorSetting> |
getFloorSettingCallable()
Gets details of a single floor setting of a project
Sample code:
{@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 (ModelArmorClient modelArmorClient = ModelArmorClient.create()) {
GetFloorSettingRequest request =
GetFloorSettingRequest.newBuilder()
.setName(FloorSettingName.ofProjectLocationName("[PROJECT]", "[LOCATION]").toString())
.build();
ApiFuture
|
com.google.cloud.location.Location |
getLocation(com.google.cloud.location.GetLocationRequest request)
Gets information about a location.
|
com.google.api.gax.rpc.UnaryCallable<com.google.cloud.location.GetLocationRequest,com.google.cloud.location.Location> |
getLocationCallable()
Gets information about a location.
|
ModelArmorSettings |
getSettings() |
ModelArmorStub |
getStub() |
Template |
getTemplate(GetTemplateRequest request)
Gets details of a single Template.
|
Template |
getTemplate(String name)
Gets details of a single Template.
|
Template |
getTemplate(TemplateName name)
Gets details of a single Template.
|
com.google.api.gax.rpc.UnaryCallable<GetTemplateRequest,Template> |
getTemplateCallable()
Gets details of a single Template.
|
boolean |
isShutdown() |
boolean |
isTerminated() |
ModelArmorClient.ListLocationsPagedResponse |
listLocations(com.google.cloud.location.ListLocationsRequest request)
Lists information about the supported locations for this service.
|
com.google.api.gax.rpc.UnaryCallable<com.google.cloud.location.ListLocationsRequest,com.google.cloud.location.ListLocationsResponse> |
listLocationsCallable()
Lists information about the supported locations for this service.
|
com.google.api.gax.rpc.UnaryCallable<com.google.cloud.location.ListLocationsRequest,ModelArmorClient.ListLocationsPagedResponse> |
listLocationsPagedCallable()
Lists information about the supported locations for this service.
|
ModelArmorClient.ListTemplatesPagedResponse |
listTemplates(ListTemplatesRequest request)
Lists Templates in a given project and location.
|
ModelArmorClient.ListTemplatesPagedResponse |
listTemplates(LocationName parent)
Lists Templates in a given project and location.
|
ModelArmorClient.ListTemplatesPagedResponse |
listTemplates(String parent)
Lists Templates in a given project and location.
|
com.google.api.gax.rpc.UnaryCallable<ListTemplatesRequest,ListTemplatesResponse> |
listTemplatesCallable()
Lists Templates in a given project and location.
|
com.google.api.gax.rpc.UnaryCallable<ListTemplatesRequest,ModelArmorClient.ListTemplatesPagedResponse> |
listTemplatesPagedCallable()
Lists Templates in a given project and location.
|
SanitizeModelResponseResponse |
sanitizeModelResponse(SanitizeModelResponseRequest request)
Sanitizes Model Response.
|
com.google.api.gax.rpc.UnaryCallable<SanitizeModelResponseRequest,SanitizeModelResponseResponse> |
sanitizeModelResponseCallable()
Sanitizes Model Response.
|
SanitizeUserPromptResponse |
sanitizeUserPrompt(SanitizeUserPromptRequest request)
Sanitizes User Prompt.
|
com.google.api.gax.rpc.UnaryCallable<SanitizeUserPromptRequest,SanitizeUserPromptResponse> |
sanitizeUserPromptCallable()
Sanitizes User Prompt.
|
void |
shutdown() |
void |
shutdownNow() |
FloorSetting |
updateFloorSetting(FloorSetting floorSetting,
com.google.protobuf.FieldMask updateMask)
Updates the parameters of a single floor setting of a project
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 (ModelArmorClient modelArmorClient = ModelArmorClient.create()) {
FloorSetting floorSetting = FloorSetting.newBuilder().build();
FieldMask updateMask = FieldMask.newBuilder().build();
FloorSetting response = modelArmorClient.updateFloorSetting(floorSetting, updateMask);
}
|
FloorSetting |
updateFloorSetting(UpdateFloorSettingRequest request)
Updates the parameters of a single floor setting of a project
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 (ModelArmorClient modelArmorClient = ModelArmorClient.create()) {
UpdateFloorSettingRequest request =
UpdateFloorSettingRequest.newBuilder()
.setFloorSetting(FloorSetting.newBuilder().build())
.setUpdateMask(FieldMask.newBuilder().build())
.build();
FloorSetting response = modelArmorClient.updateFloorSetting(request);
}
|
com.google.api.gax.rpc.UnaryCallable<UpdateFloorSettingRequest,FloorSetting> |
updateFloorSettingCallable()
Updates the parameters of a single floor setting of a project
Sample code:
{@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 (ModelArmorClient modelArmorClient = ModelArmorClient.create()) {
UpdateFloorSettingRequest request =
UpdateFloorSettingRequest.newBuilder()
.setFloorSetting(FloorSetting.newBuilder().build())
.setUpdateMask(FieldMask.newBuilder().build())
.build();
ApiFuture
|
Template |
updateTemplate(Template template,
com.google.protobuf.FieldMask updateMask)
Updates the parameters of a single Template.
|
Template |
updateTemplate(UpdateTemplateRequest request)
Updates the parameters of a single Template.
|
com.google.api.gax.rpc.UnaryCallable<UpdateTemplateRequest,Template> |
updateTemplateCallable()
Updates the parameters of a single Template.
|
protected ModelArmorClient(ModelArmorSettings settings) throws IOException
IOExceptionprotected ModelArmorClient(ModelArmorStub stub)
public static final ModelArmorClient create() throws IOException
IOExceptionpublic static final ModelArmorClient create(ModelArmorSettings settings) throws IOException
IOExceptionpublic static final ModelArmorClient create(ModelArmorStub stub)
public final ModelArmorSettings getSettings()
public ModelArmorStub getStub()
public final ModelArmorClient.ListTemplatesPagedResponse listTemplates(LocationName parent)
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 (ModelArmorClient modelArmorClient = ModelArmorClient.create()) {
LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
for (Template element : modelArmorClient.listTemplates(parent).iterateAll()) {
// doThingsWith(element);
}
}
parent - Required. Parent value for ListTemplatesRequestcom.google.api.gax.rpc.ApiException - if the remote call failspublic final ModelArmorClient.ListTemplatesPagedResponse listTemplates(String parent)
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 (ModelArmorClient modelArmorClient = ModelArmorClient.create()) {
String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString();
for (Template element : modelArmorClient.listTemplates(parent).iterateAll()) {
// doThingsWith(element);
}
}
parent - Required. Parent value for ListTemplatesRequestcom.google.api.gax.rpc.ApiException - if the remote call failspublic final ModelArmorClient.ListTemplatesPagedResponse listTemplates(ListTemplatesRequest 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 (ModelArmorClient modelArmorClient = ModelArmorClient.create()) {
ListTemplatesRequest request =
ListTemplatesRequest.newBuilder()
.setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
.setPageSize(883849137)
.setPageToken("pageToken873572522")
.setFilter("filter-1274492040")
.setOrderBy("orderBy-1207110587")
.build();
for (Template element : modelArmorClient.listTemplates(request).iterateAll()) {
// doThingsWith(element);
}
}
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<ListTemplatesRequest,ModelArmorClient.ListTemplatesPagedResponse> listTemplatesPagedCallable()
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 (ModelArmorClient modelArmorClient = ModelArmorClient.create()) {
ListTemplatesRequest request =
ListTemplatesRequest.newBuilder()
.setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
.setPageSize(883849137)
.setPageToken("pageToken873572522")
.setFilter("filter-1274492040")
.setOrderBy("orderBy-1207110587")
.build();
ApiFuture<Template> future =
modelArmorClient.listTemplatesPagedCallable().futureCall(request);
// Do something.
for (Template element : future.get().iterateAll()) {
// doThingsWith(element);
}
}
public final com.google.api.gax.rpc.UnaryCallable<ListTemplatesRequest,ListTemplatesResponse> listTemplatesCallable()
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 (ModelArmorClient modelArmorClient = ModelArmorClient.create()) {
ListTemplatesRequest request =
ListTemplatesRequest.newBuilder()
.setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
.setPageSize(883849137)
.setPageToken("pageToken873572522")
.setFilter("filter-1274492040")
.setOrderBy("orderBy-1207110587")
.build();
while (true) {
ListTemplatesResponse response = modelArmorClient.listTemplatesCallable().call(request);
for (Template element : response.getTemplatesList()) {
// doThingsWith(element);
}
String nextPageToken = response.getNextPageToken();
if (!Strings.isNullOrEmpty(nextPageToken)) {
request = request.toBuilder().setPageToken(nextPageToken).build();
} else {
break;
}
}
}
public final Template getTemplate(TemplateName name)
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 (ModelArmorClient modelArmorClient = ModelArmorClient.create()) {
TemplateName name = TemplateName.of("[PROJECT]", "[LOCATION]", "[TEMPLATE]");
Template response = modelArmorClient.getTemplate(name);
}
name - Required. Name of the resourcecom.google.api.gax.rpc.ApiException - if the remote call failspublic final Template getTemplate(String name)
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 (ModelArmorClient modelArmorClient = ModelArmorClient.create()) {
String name = TemplateName.of("[PROJECT]", "[LOCATION]", "[TEMPLATE]").toString();
Template response = modelArmorClient.getTemplate(name);
}
name - Required. Name of the resourcecom.google.api.gax.rpc.ApiException - if the remote call failspublic final Template getTemplate(GetTemplateRequest 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 (ModelArmorClient modelArmorClient = ModelArmorClient.create()) {
GetTemplateRequest request =
GetTemplateRequest.newBuilder()
.setName(TemplateName.of("[PROJECT]", "[LOCATION]", "[TEMPLATE]").toString())
.build();
Template response = modelArmorClient.getTemplate(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<GetTemplateRequest,Template> getTemplateCallable()
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 (ModelArmorClient modelArmorClient = ModelArmorClient.create()) {
GetTemplateRequest request =
GetTemplateRequest.newBuilder()
.setName(TemplateName.of("[PROJECT]", "[LOCATION]", "[TEMPLATE]").toString())
.build();
ApiFuture<Template> future = modelArmorClient.getTemplateCallable().futureCall(request);
// Do something.
Template response = future.get();
}
public final Template createTemplate(LocationName parent, Template template, String templateId)
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 (ModelArmorClient modelArmorClient = ModelArmorClient.create()) {
LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
Template template = Template.newBuilder().build();
String templateId = "templateId1304010549";
Template response = modelArmorClient.createTemplate(parent, template, templateId);
}
parent - Required. Value for parent.template - Required. The resource being createdtemplateId - Required. Id of the requesting object If auto-generating Id server-side,
remove this field and template_id from the method_signature of Create RPCcom.google.api.gax.rpc.ApiException - if the remote call failspublic final Template createTemplate(String parent, Template template, String templateId)
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 (ModelArmorClient modelArmorClient = ModelArmorClient.create()) {
String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString();
Template template = Template.newBuilder().build();
String templateId = "templateId1304010549";
Template response = modelArmorClient.createTemplate(parent, template, templateId);
}
parent - Required. Value for parent.template - Required. The resource being createdtemplateId - Required. Id of the requesting object If auto-generating Id server-side,
remove this field and template_id from the method_signature of Create RPCcom.google.api.gax.rpc.ApiException - if the remote call failspublic final Template createTemplate(CreateTemplateRequest 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 (ModelArmorClient modelArmorClient = ModelArmorClient.create()) {
CreateTemplateRequest request =
CreateTemplateRequest.newBuilder()
.setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
.setTemplateId("templateId1304010549")
.setTemplate(Template.newBuilder().build())
.setRequestId("requestId693933066")
.build();
Template response = modelArmorClient.createTemplate(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<CreateTemplateRequest,Template> createTemplateCallable()
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 (ModelArmorClient modelArmorClient = ModelArmorClient.create()) {
CreateTemplateRequest request =
CreateTemplateRequest.newBuilder()
.setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
.setTemplateId("templateId1304010549")
.setTemplate(Template.newBuilder().build())
.setRequestId("requestId693933066")
.build();
ApiFuture<Template> future = modelArmorClient.createTemplateCallable().futureCall(request);
// Do something.
Template response = future.get();
}
public final Template updateTemplate(Template template, com.google.protobuf.FieldMask updateMask)
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 (ModelArmorClient modelArmorClient = ModelArmorClient.create()) {
Template template = Template.newBuilder().build();
FieldMask updateMask = FieldMask.newBuilder().build();
Template response = modelArmorClient.updateTemplate(template, updateMask);
}
template - Required. The resource being updatedupdateMask - Required. Field mask is used to specify the fields to be overwritten in the
Template resource by the update. The fields specified in the update_mask are relative to
the resource, not the full request. A field will be overwritten if it is in the mask. If
the user does not provide a mask then all fields will be overwritten.com.google.api.gax.rpc.ApiException - if the remote call failspublic final Template updateTemplate(UpdateTemplateRequest 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 (ModelArmorClient modelArmorClient = ModelArmorClient.create()) {
UpdateTemplateRequest request =
UpdateTemplateRequest.newBuilder()
.setUpdateMask(FieldMask.newBuilder().build())
.setTemplate(Template.newBuilder().build())
.setRequestId("requestId693933066")
.build();
Template response = modelArmorClient.updateTemplate(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<UpdateTemplateRequest,Template> updateTemplateCallable()
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 (ModelArmorClient modelArmorClient = ModelArmorClient.create()) {
UpdateTemplateRequest request =
UpdateTemplateRequest.newBuilder()
.setUpdateMask(FieldMask.newBuilder().build())
.setTemplate(Template.newBuilder().build())
.setRequestId("requestId693933066")
.build();
ApiFuture<Template> future = modelArmorClient.updateTemplateCallable().futureCall(request);
// Do something.
Template response = future.get();
}
public final void deleteTemplate(TemplateName name)
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 (ModelArmorClient modelArmorClient = ModelArmorClient.create()) {
TemplateName name = TemplateName.of("[PROJECT]", "[LOCATION]", "[TEMPLATE]");
modelArmorClient.deleteTemplate(name);
}
name - Required. Name of the resourcecom.google.api.gax.rpc.ApiException - if the remote call failspublic final void deleteTemplate(String name)
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 (ModelArmorClient modelArmorClient = ModelArmorClient.create()) {
String name = TemplateName.of("[PROJECT]", "[LOCATION]", "[TEMPLATE]").toString();
modelArmorClient.deleteTemplate(name);
}
name - Required. Name of the resourcecom.google.api.gax.rpc.ApiException - if the remote call failspublic final void deleteTemplate(DeleteTemplateRequest 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 (ModelArmorClient modelArmorClient = ModelArmorClient.create()) {
DeleteTemplateRequest request =
DeleteTemplateRequest.newBuilder()
.setName(TemplateName.of("[PROJECT]", "[LOCATION]", "[TEMPLATE]").toString())
.setRequestId("requestId693933066")
.build();
modelArmorClient.deleteTemplate(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<DeleteTemplateRequest,com.google.protobuf.Empty> deleteTemplateCallable()
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 (ModelArmorClient modelArmorClient = ModelArmorClient.create()) {
DeleteTemplateRequest request =
DeleteTemplateRequest.newBuilder()
.setName(TemplateName.of("[PROJECT]", "[LOCATION]", "[TEMPLATE]").toString())
.setRequestId("requestId693933066")
.build();
ApiFuture<Empty> future = modelArmorClient.deleteTemplateCallable().futureCall(request);
// Do something.
future.get();
}
public final FloorSetting getFloorSetting(FloorSettingName name)
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 (ModelArmorClient modelArmorClient = ModelArmorClient.create()) {
FloorSettingName name = FloorSettingName.ofProjectLocationName("[PROJECT]", "[LOCATION]");
FloorSetting response = modelArmorClient.getFloorSetting(name);
}
name - Required. The name of the floor setting to get, example projects/123/floorsetting.com.google.api.gax.rpc.ApiException - if the remote call failspublic final FloorSetting getFloorSetting(String name)
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 (ModelArmorClient modelArmorClient = ModelArmorClient.create()) {
String name = FloorSettingName.ofProjectLocationName("[PROJECT]", "[LOCATION]").toString();
FloorSetting response = modelArmorClient.getFloorSetting(name);
}
name - Required. The name of the floor setting to get, example projects/123/floorsetting.com.google.api.gax.rpc.ApiException - if the remote call failspublic final FloorSetting getFloorSetting(GetFloorSettingRequest 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 (ModelArmorClient modelArmorClient = ModelArmorClient.create()) {
GetFloorSettingRequest request =
GetFloorSettingRequest.newBuilder()
.setName(FloorSettingName.ofProjectLocationName("[PROJECT]", "[LOCATION]").toString())
.build();
FloorSetting response = modelArmorClient.getFloorSetting(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<GetFloorSettingRequest,FloorSetting> getFloorSettingCallable()
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 (ModelArmorClient modelArmorClient = ModelArmorClient.create()) {
GetFloorSettingRequest request =
GetFloorSettingRequest.newBuilder()
.setName(FloorSettingName.ofProjectLocationName("[PROJECT]", "[LOCATION]").toString())
.build();
ApiFuture<FloorSetting> future =
modelArmorClient.getFloorSettingCallable().futureCall(request);
// Do something.
FloorSetting response = future.get();
}
public final FloorSetting updateFloorSetting(FloorSetting floorSetting, com.google.protobuf.FieldMask updateMask)
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 (ModelArmorClient modelArmorClient = ModelArmorClient.create()) {
FloorSetting floorSetting = FloorSetting.newBuilder().build();
FieldMask updateMask = FieldMask.newBuilder().build();
FloorSetting response = modelArmorClient.updateFloorSetting(floorSetting, updateMask);
}
floorSetting - Required. The floor setting being updated.updateMask - Optional. Field mask is used to specify the fields to be overwritten in the
FloorSetting resource by the update. The fields specified in the update_mask are relative
to the resource, not the full request. A field will be overwritten if it is in the mask. If
the user does not provide a mask then all fields will be overwritten.com.google.api.gax.rpc.ApiException - if the remote call failspublic final FloorSetting updateFloorSetting(UpdateFloorSettingRequest 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 (ModelArmorClient modelArmorClient = ModelArmorClient.create()) {
UpdateFloorSettingRequest request =
UpdateFloorSettingRequest.newBuilder()
.setFloorSetting(FloorSetting.newBuilder().build())
.setUpdateMask(FieldMask.newBuilder().build())
.build();
FloorSetting response = modelArmorClient.updateFloorSetting(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<UpdateFloorSettingRequest,FloorSetting> updateFloorSettingCallable()
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 (ModelArmorClient modelArmorClient = ModelArmorClient.create()) {
UpdateFloorSettingRequest request =
UpdateFloorSettingRequest.newBuilder()
.setFloorSetting(FloorSetting.newBuilder().build())
.setUpdateMask(FieldMask.newBuilder().build())
.build();
ApiFuture<FloorSetting> future =
modelArmorClient.updateFloorSettingCallable().futureCall(request);
// Do something.
FloorSetting response = future.get();
}
public final SanitizeUserPromptResponse sanitizeUserPrompt(SanitizeUserPromptRequest 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 (ModelArmorClient modelArmorClient = ModelArmorClient.create()) {
SanitizeUserPromptRequest request =
SanitizeUserPromptRequest.newBuilder()
.setName(TemplateName.of("[PROJECT]", "[LOCATION]", "[TEMPLATE]").toString())
.setUserPromptData(DataItem.newBuilder().build())
.setMultiLanguageDetectionMetadata(
MultiLanguageDetectionMetadata.newBuilder().build())
.build();
SanitizeUserPromptResponse response = modelArmorClient.sanitizeUserPrompt(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<SanitizeUserPromptRequest,SanitizeUserPromptResponse> sanitizeUserPromptCallable()
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 (ModelArmorClient modelArmorClient = ModelArmorClient.create()) {
SanitizeUserPromptRequest request =
SanitizeUserPromptRequest.newBuilder()
.setName(TemplateName.of("[PROJECT]", "[LOCATION]", "[TEMPLATE]").toString())
.setUserPromptData(DataItem.newBuilder().build())
.setMultiLanguageDetectionMetadata(
MultiLanguageDetectionMetadata.newBuilder().build())
.build();
ApiFuture<SanitizeUserPromptResponse> future =
modelArmorClient.sanitizeUserPromptCallable().futureCall(request);
// Do something.
SanitizeUserPromptResponse response = future.get();
}
public final SanitizeModelResponseResponse sanitizeModelResponse(SanitizeModelResponseRequest 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 (ModelArmorClient modelArmorClient = ModelArmorClient.create()) {
SanitizeModelResponseRequest request =
SanitizeModelResponseRequest.newBuilder()
.setName(TemplateName.of("[PROJECT]", "[LOCATION]", "[TEMPLATE]").toString())
.setModelResponseData(DataItem.newBuilder().build())
.setUserPrompt("userPrompt1504308495")
.setMultiLanguageDetectionMetadata(
MultiLanguageDetectionMetadata.newBuilder().build())
.build();
SanitizeModelResponseResponse response = modelArmorClient.sanitizeModelResponse(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<SanitizeModelResponseRequest,SanitizeModelResponseResponse> sanitizeModelResponseCallable()
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 (ModelArmorClient modelArmorClient = ModelArmorClient.create()) {
SanitizeModelResponseRequest request =
SanitizeModelResponseRequest.newBuilder()
.setName(TemplateName.of("[PROJECT]", "[LOCATION]", "[TEMPLATE]").toString())
.setModelResponseData(DataItem.newBuilder().build())
.setUserPrompt("userPrompt1504308495")
.setMultiLanguageDetectionMetadata(
MultiLanguageDetectionMetadata.newBuilder().build())
.build();
ApiFuture<SanitizeModelResponseResponse> future =
modelArmorClient.sanitizeModelResponseCallable().futureCall(request);
// Do something.
SanitizeModelResponseResponse response = future.get();
}
public final ModelArmorClient.ListLocationsPagedResponse listLocations(com.google.cloud.location.ListLocationsRequest 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 (ModelArmorClient modelArmorClient = ModelArmorClient.create()) {
ListLocationsRequest request =
ListLocationsRequest.newBuilder()
.setName("name3373707")
.setFilter("filter-1274492040")
.setPageSize(883849137)
.setPageToken("pageToken873572522")
.build();
for (Location element : modelArmorClient.listLocations(request).iterateAll()) {
// doThingsWith(element);
}
}
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<com.google.cloud.location.ListLocationsRequest,ModelArmorClient.ListLocationsPagedResponse> listLocationsPagedCallable()
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 (ModelArmorClient modelArmorClient = ModelArmorClient.create()) {
ListLocationsRequest request =
ListLocationsRequest.newBuilder()
.setName("name3373707")
.setFilter("filter-1274492040")
.setPageSize(883849137)
.setPageToken("pageToken873572522")
.build();
ApiFuture<Location> future =
modelArmorClient.listLocationsPagedCallable().futureCall(request);
// Do something.
for (Location element : future.get().iterateAll()) {
// doThingsWith(element);
}
}
public final com.google.api.gax.rpc.UnaryCallable<com.google.cloud.location.ListLocationsRequest,com.google.cloud.location.ListLocationsResponse> listLocationsCallable()
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 (ModelArmorClient modelArmorClient = ModelArmorClient.create()) {
ListLocationsRequest request =
ListLocationsRequest.newBuilder()
.setName("name3373707")
.setFilter("filter-1274492040")
.setPageSize(883849137)
.setPageToken("pageToken873572522")
.build();
while (true) {
ListLocationsResponse response = modelArmorClient.listLocationsCallable().call(request);
for (Location element : response.getLocationsList()) {
// doThingsWith(element);
}
String nextPageToken = response.getNextPageToken();
if (!Strings.isNullOrEmpty(nextPageToken)) {
request = request.toBuilder().setPageToken(nextPageToken).build();
} else {
break;
}
}
}
public final com.google.cloud.location.Location getLocation(com.google.cloud.location.GetLocationRequest 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 (ModelArmorClient modelArmorClient = ModelArmorClient.create()) {
GetLocationRequest request = GetLocationRequest.newBuilder().setName("name3373707").build();
Location response = modelArmorClient.getLocation(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<com.google.cloud.location.GetLocationRequest,com.google.cloud.location.Location> getLocationCallable()
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 (ModelArmorClient modelArmorClient = ModelArmorClient.create()) {
GetLocationRequest request = GetLocationRequest.newBuilder().setName("name3373707").build();
ApiFuture<Location> future = modelArmorClient.getLocationCallable().futureCall(request);
// Do something.
Location 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 © 2026 Google LLC. All rights reserved.