From 53e4eb9ce01f449884d234075a6e5da61eb6e64c Mon Sep 17 00:00:00 2001 From: tirthrajsinh-zala-crest Date: Thu, 10 Apr 2025 15:01:37 +0530 Subject: [PATCH 1/2] feat(modelarmor): Added create, update, delete, list modelarmor code snippets --- modelarmor/README.md | 29 +++ modelarmor/pom.xml | 112 ++++++++++++ .../main/java/modelarmor/CreateTemplate.java | 82 +++++++++ .../CreateTemplateWithBasicSdp.java | 81 +++++++++ .../modelarmor/CreateTemplateWithLabels.java | 87 +++++++++ .../CreateTemplateWithMetadata.java | 85 +++++++++ .../main/java/modelarmor/DeleteTemplate.java | 45 +++++ .../src/main/java/modelarmor/GetTemplate.java | 48 +++++ .../main/java/modelarmor/ListTemplates.java | 49 +++++ .../modelarmor/ListTemplatesWithFilter.java | 53 ++++++ .../main/java/modelarmor/UpdateTemplate.java | 81 +++++++++ .../java/modelarmor/UpdateTemplateLabels.java | 65 +++++++ .../modelarmor/UpdateTemplateMetadata.java | 85 +++++++++ .../UpdateTemplateWithMaskConfiguration.java | 84 +++++++++ .../src/test/java/modelarmor/SnippetsIT.java | 172 ++++++++++++++++++ 15 files changed, 1158 insertions(+) create mode 100644 modelarmor/README.md create mode 100644 modelarmor/pom.xml create mode 100644 modelarmor/src/main/java/modelarmor/CreateTemplate.java create mode 100644 modelarmor/src/main/java/modelarmor/CreateTemplateWithBasicSdp.java create mode 100644 modelarmor/src/main/java/modelarmor/CreateTemplateWithLabels.java create mode 100644 modelarmor/src/main/java/modelarmor/CreateTemplateWithMetadata.java create mode 100644 modelarmor/src/main/java/modelarmor/DeleteTemplate.java create mode 100644 modelarmor/src/main/java/modelarmor/GetTemplate.java create mode 100644 modelarmor/src/main/java/modelarmor/ListTemplates.java create mode 100644 modelarmor/src/main/java/modelarmor/ListTemplatesWithFilter.java create mode 100644 modelarmor/src/main/java/modelarmor/UpdateTemplate.java create mode 100644 modelarmor/src/main/java/modelarmor/UpdateTemplateLabels.java create mode 100644 modelarmor/src/main/java/modelarmor/UpdateTemplateMetadata.java create mode 100644 modelarmor/src/main/java/modelarmor/UpdateTemplateWithMaskConfiguration.java create mode 100644 modelarmor/src/test/java/modelarmor/SnippetsIT.java diff --git a/modelarmor/README.md b/modelarmor/README.md new file mode 100644 index 00000000000..0c8113a9377 --- /dev/null +++ b/modelarmor/README.md @@ -0,0 +1,29 @@ +# Google Model Armor + + +Open in Cloud Shell + +Google Model Armor is a fully managed Google Cloud service that enhances the security and safety of AI applications by screening LLM prompts and responses for various security and safety risks. [More Details](https://cloud.google.com/security-command-center/docs/model-armor-overview) + +These sample Java code snippets demonstrate how to access the Model Armor API using the Google Java API Client Libraries. + +## Prerequisites + +### Enable the API + +The following page details the permissions required for Model Armor and provides instructions for enabling and disabling Model Armor: +[Enable Model Armor API](https://cloud.google.com/security-command-center/docs/get-started-model-armor#enable-model-armor) + +### Grant Permissions +You must ensure that the [user account or service account](https://cloud.google.com/iam/docs/service-accounts#differences_between_a_service_account_and_a_user_account) you used to authorize your gcloud session has the proper permissions to edit Secret Manager resources for your project. In the Cloud Console under IAM, add the following roles to the project whose service account you're using to test: +* Model Armor Admin (roles/modelarmor.admin) +* Floor Settings Admin (modelarmor.floorSettingsAdmin) + +More information can be found in the [Model Armor Docs](https://cloud.google.com/security-command-center/docs/get-started-model-armor#required_permissions) + +### Set Environment Variables + +You must set your project ID to run the tests: +```shell +export GOOGLE_CLOUD_PROJECT= +``` \ No newline at end of file diff --git a/modelarmor/pom.xml b/modelarmor/pom.xml new file mode 100644 index 00000000000..a23e8770bfa --- /dev/null +++ b/modelarmor/pom.xml @@ -0,0 +1,112 @@ + + + + 4.0.0 + com.example.modelarmor + modelarmor-samples + jar + + + + com.google.cloud.samples + shared-configuration + 1.2.0 + + + + UTF-8 + 11 + 11 + + + + + + com.google.cloud + libraries-bom + 26.59.0 + pom + import + + + + + + + com.google.cloud + google-cloud-modelarmor + + + + com.google.cloud + google-cloud-dlp + + + + com.google.protobuf + protobuf-java-util + + + + org.projectlombok + lombok + 1.18.30 + provided + + + + + junit + junit + 4.13.2 + test + + + com.google.truth + truth + 1.4.0 + test + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.12.1 + + 11 + 11 + + + org.projectlombok + lombok + 1.18.30 + + + + + + + + diff --git a/modelarmor/src/main/java/modelarmor/CreateTemplate.java b/modelarmor/src/main/java/modelarmor/CreateTemplate.java new file mode 100644 index 00000000000..f8391be7766 --- /dev/null +++ b/modelarmor/src/main/java/modelarmor/CreateTemplate.java @@ -0,0 +1,82 @@ +/* + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package modelarmor; + +// TODO(nasit): Add region tags in all snippets. +import com.google.cloud.modelarmor.v1.CreateTemplateRequest; +import com.google.cloud.modelarmor.v1.DetectionConfidenceLevel; +import com.google.cloud.modelarmor.v1.FilterConfig; +import com.google.cloud.modelarmor.v1.LocationName; +import com.google.cloud.modelarmor.v1.ModelArmorClient; +import com.google.cloud.modelarmor.v1.ModelArmorSettings; +import com.google.cloud.modelarmor.v1.RaiFilterSettings; +import com.google.cloud.modelarmor.v1.RaiFilterSettings.RaiFilter; +import com.google.cloud.modelarmor.v1.RaiFilterType; +import com.google.cloud.modelarmor.v1.Template; +import com.google.protobuf.util.JsonFormat; +import java.util.Arrays; +import java.util.List; + +public class CreateTemplate { + + public static void main(String[] args) throws Exception { + // TODO(developer): Replace these variables before running the sample. + String projectId = "your-project-id"; + String locationId = "your-location-id"; + String templateId = "your-template-id"; + + createTemplate(projectId, locationId, templateId); + } + + public static Template createTemplate(String projectId, String locationId, String templateId) + throws Exception { + String apiEndpoint = String.format("modelarmor.%s.rep.googleapis.com:443", locationId); + ModelArmorSettings modelArmorSettings = + ModelArmorSettings.newBuilder().setEndpoint(apiEndpoint).build(); + + try (ModelArmorClient client = ModelArmorClient.create(modelArmorSettings)) { + String parent = LocationName.of(projectId, locationId).toString(); + + Template template = + Template.newBuilder() + .setFilterConfig( + FilterConfig.newBuilder() + .setRaiSettings( + RaiFilterSettings.newBuilder() + .addAllRaiFilters( + List.of( + RaiFilter.newBuilder() + .setFilterType(RaiFilterType.DANGEROUS) + .setConfidenceLevel(DetectionConfidenceLevel.HIGH) + .build())) + .build()) + .build()) + .build(); + + CreateTemplateRequest request = + CreateTemplateRequest.newBuilder() + .setParent(parent) + .setTemplateId(templateId) + .setTemplate(template) + .build(); + + Template createdTemplate = client.createTemplate(request); + System.out.println("Created template: " + JsonFormat.printer().print(createdTemplate)); + return createdTemplate; + } + } +} diff --git a/modelarmor/src/main/java/modelarmor/CreateTemplateWithBasicSdp.java b/modelarmor/src/main/java/modelarmor/CreateTemplateWithBasicSdp.java new file mode 100644 index 00000000000..708aafbb395 --- /dev/null +++ b/modelarmor/src/main/java/modelarmor/CreateTemplateWithBasicSdp.java @@ -0,0 +1,81 @@ +/* + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package modelarmor; + +import com.google.cloud.modelarmor.v1.CreateTemplateRequest; +import com.google.cloud.modelarmor.v1.DetectionConfidenceLevel; +import com.google.cloud.modelarmor.v1.FilterConfig; +import com.google.cloud.modelarmor.v1.LocationName; +import com.google.cloud.modelarmor.v1.ModelArmorClient; +import com.google.cloud.modelarmor.v1.ModelArmorSettings; +import com.google.cloud.modelarmor.v1.RaiFilterSettings; +import com.google.cloud.modelarmor.v1.RaiFilterSettings.RaiFilter; +import com.google.cloud.modelarmor.v1.RaiFilterType; +import com.google.cloud.modelarmor.v1.Template; +import com.google.protobuf.util.JsonFormat; +import java.util.Arrays; +import java.util.List; + +public class CreateTemplateWithBasicSdp { + + public static void main(String[] args) throws Exception { + // TODO(developer): Replace these variables before running the sample. + String projectId = "your-project-id"; + String locationId = "your-location-id"; + String templateId = "your-template-id"; + + createTemplateWithBasicSdp(projectId, locationId, templateId); + } + + public static void createTemplateWithBasicSdp( + String projectId, String locationId, String templateId) throws Exception { + String apiEndpoint = String.format("modelarmor.%s.rep.googleapis.com:443", locationId); + ModelArmorSettings modelArmorSettings = + ModelArmorSettings.newBuilder().setEndpoint(apiEndpoint).build(); + + try (ModelArmorClient client = ModelArmorClient.create(modelArmorSettings)) { + String parent = LocationName.of(projectId, locationId).toString(); + + Template template = + Template.newBuilder() + .setFilterConfig( + FilterConfig.newBuilder() + .setRaiSettings( + RaiFilterSettings.newBuilder() + .addAllRaiFilters( + List.of( + RaiFilter.newBuilder() + .setFilterType(RaiFilterType.DANGEROUS) + .setConfidenceLevel(DetectionConfidenceLevel.HIGH) + .build())) + .build()) + .build()) + .build(); + + CreateTemplateRequest request = + CreateTemplateRequest.newBuilder() + .setParent(parent) + .setTemplateId(templateId) + .setTemplate(template) + .build(); + + Template createdTemplate = client.createTemplate(request); + System.out.println( + "Created template with basic sdp: " + JsonFormat.printer().print(createdTemplate)); + } + } +} diff --git a/modelarmor/src/main/java/modelarmor/CreateTemplateWithLabels.java b/modelarmor/src/main/java/modelarmor/CreateTemplateWithLabels.java new file mode 100644 index 00000000000..7951a97a35e --- /dev/null +++ b/modelarmor/src/main/java/modelarmor/CreateTemplateWithLabels.java @@ -0,0 +1,87 @@ +/* + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package modelarmor; + +import com.google.cloud.modelarmor.v1.CreateTemplateRequest; +import com.google.cloud.modelarmor.v1.DetectionConfidenceLevel; +import com.google.cloud.modelarmor.v1.FilterConfig; +import com.google.cloud.modelarmor.v1.LocationName; +import com.google.cloud.modelarmor.v1.ModelArmorClient; +import com.google.cloud.modelarmor.v1.ModelArmorSettings; +import com.google.cloud.modelarmor.v1.RaiFilterSettings; +import com.google.cloud.modelarmor.v1.RaiFilterSettings.RaiFilter; +import com.google.cloud.modelarmor.v1.RaiFilterType; +import com.google.cloud.modelarmor.v1.Template; +import com.google.protobuf.util.JsonFormat; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class CreateTemplateWithLabels { + + public static void main(String[] args) throws Exception { + // TODO(developer): Replace these variables before running the sample. + String projectId = "your-project-id"; + String locationId = "your-location-id"; + String templateId = "your-template-id"; + + createTemplateWithLabels(projectId, locationId, templateId); + } + + public static void createTemplateWithLabels( + String projectId, String locationId, String templateId) throws Exception { + String apiEndpoint = String.format("modelarmor.%s.rep.googleapis.com:443", locationId); + ModelArmorSettings modelArmorSettings = + ModelArmorSettings.newBuilder().setEndpoint(apiEndpoint).build(); + + try (ModelArmorClient client = ModelArmorClient.create(modelArmorSettings)) { + String parent = LocationName.of(projectId, locationId).toString(); + + Map labels = new HashMap<>(); + labels.put("key1", "value1"); + labels.put("key2", "value2"); + + Template template = + Template.newBuilder() + .putAllLabels(labels) + .setFilterConfig( + FilterConfig.newBuilder() + .setRaiSettings( + RaiFilterSettings.newBuilder() + .addAllRaiFilters( + List.of( + RaiFilter.newBuilder() + .setFilterType(RaiFilterType.DANGEROUS) + .setConfidenceLevel(DetectionConfidenceLevel.HIGH) + .build())) + .build()) + .build()) + .build(); + + CreateTemplateRequest request = + CreateTemplateRequest.newBuilder() + .setParent(parent) + .setTemplateId(templateId) + .setTemplate(template) + .build(); + + Template createdTemplate = client.createTemplate(request); + System.out.println( + "Created template with labels: " + JsonFormat.printer().print(createdTemplate)); + } + } +} diff --git a/modelarmor/src/main/java/modelarmor/CreateTemplateWithMetadata.java b/modelarmor/src/main/java/modelarmor/CreateTemplateWithMetadata.java new file mode 100644 index 00000000000..52de3843a1f --- /dev/null +++ b/modelarmor/src/main/java/modelarmor/CreateTemplateWithMetadata.java @@ -0,0 +1,85 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package modelarmor; + +import com.google.cloud.modelarmor.v1.CreateTemplateRequest; +import com.google.cloud.modelarmor.v1.DetectionConfidenceLevel; +import com.google.cloud.modelarmor.v1.FilterConfig; +import com.google.cloud.modelarmor.v1.LocationName; +import com.google.cloud.modelarmor.v1.ModelArmorClient; +import com.google.cloud.modelarmor.v1.ModelArmorSettings; +import com.google.cloud.modelarmor.v1.RaiFilterSettings; +import com.google.cloud.modelarmor.v1.RaiFilterSettings.RaiFilter; +import com.google.cloud.modelarmor.v1.RaiFilterType; +import com.google.cloud.modelarmor.v1.Template; +import com.google.protobuf.util.JsonFormat; +import java.util.Arrays; +import java.util.List; + +public class CreateTemplateWithMetadata { + + public static void main(String[] args) throws Exception { + // TODO(developer): Replace these variables before running the sample. + String projectId = "your-project-id"; + String locationId = "your-location-id"; + String templateId = "your-template-id"; + + createTemplateWithMetadata(projectId, locationId, templateId); + } + + public static void createTemplateWithMetadata( + String projectId, String locationId, String templateId) throws Exception { + String apiEndpoint = String.format("modelarmor.%s.rep.googleapis.com:443", locationId); + ModelArmorSettings modelArmorSettings = + ModelArmorSettings.newBuilder().setEndpoint(apiEndpoint).build(); + + try (ModelArmorClient client = ModelArmorClient.create(modelArmorSettings)) { + String parent = LocationName.of(projectId, locationId).toString(); + + Template template = + Template.newBuilder() + .setTemplateMetadata( + Template.TemplateMetadata.newBuilder() + .setIgnorePartialInvocationFailures(true) + .setLogSanitizeOperations(true)) + .setFilterConfig( + FilterConfig.newBuilder() + .setRaiSettings( + RaiFilterSettings.newBuilder() + .addAllRaiFilters( + List.of( + RaiFilter.newBuilder() + .setFilterType(RaiFilterType.DANGEROUS) + .setConfidenceLevel(DetectionConfidenceLevel.HIGH) + .build())) + .build()) + .build()) + .build(); + + CreateTemplateRequest request = + CreateTemplateRequest.newBuilder() + .setParent(parent) + .setTemplateId(templateId) + .setTemplate(template) + .build(); + + Template createdTemplate = client.createTemplate(request); + System.out.println( + "Created template with metadata: " + JsonFormat.printer().print(createdTemplate)); + } + } +} diff --git a/modelarmor/src/main/java/modelarmor/DeleteTemplate.java b/modelarmor/src/main/java/modelarmor/DeleteTemplate.java new file mode 100644 index 00000000000..7e2f2f49529 --- /dev/null +++ b/modelarmor/src/main/java/modelarmor/DeleteTemplate.java @@ -0,0 +1,45 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package modelarmor; + +import com.google.cloud.modelarmor.v1.ModelArmorClient; +import com.google.cloud.modelarmor.v1.ModelArmorSettings; +import com.google.cloud.modelarmor.v1.TemplateName; + +public class DeleteTemplate { + + public static void main(String[] args) throws Exception { + // TODO(developer): Replace these variables before running the sample. + String projectId = "your-project-id"; + String locationId = "your-location-id"; + String templateId = "your-template-id"; + + deleteTemplate(projectId, locationId, templateId); + } + + public static void deleteTemplate(String projectId, String locationId, String templateId) + throws Exception { + String apiEndpoint = String.format("modelarmor.%s.rep.googleapis.com:443", locationId); + ModelArmorSettings modelArmorSettings = + ModelArmorSettings.newBuilder().setEndpoint(apiEndpoint).build(); + try (ModelArmorClient client = ModelArmorClient.create(modelArmorSettings)) { + String name = TemplateName.of(projectId, locationId, templateId).toString(); + client.deleteTemplate(name); + System.out.println("Deleted template: " + name); + } + } +} diff --git a/modelarmor/src/main/java/modelarmor/GetTemplate.java b/modelarmor/src/main/java/modelarmor/GetTemplate.java new file mode 100644 index 00000000000..0909cd80879 --- /dev/null +++ b/modelarmor/src/main/java/modelarmor/GetTemplate.java @@ -0,0 +1,48 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package modelarmor; + +import com.google.cloud.modelarmor.v1.ModelArmorClient; +import com.google.cloud.modelarmor.v1.ModelArmorSettings; +import com.google.cloud.modelarmor.v1.Template; +import com.google.cloud.modelarmor.v1.TemplateName; +import com.google.protobuf.util.JsonFormat; + +public class GetTemplate { + + public static void main(String[] args) throws Exception { + // TODO(developer): Replace these variables before running the sample. + String projectId = "your-project-id"; + String locationId = "your-location-id"; + String templateId = "your-template-id"; + + getTemplate(projectId, locationId, templateId); + } + + public static void getTemplate(String projectId, String locationId, String templateId) + throws Exception { + String apiEndpoint = String.format("modelarmor.%s.rep.googleapis.com:443", locationId); + ModelArmorSettings modelArmorSettings = + ModelArmorSettings.newBuilder().setEndpoint(apiEndpoint).build(); + + try (ModelArmorClient client = ModelArmorClient.create(modelArmorSettings)) { + String name = TemplateName.of(projectId, locationId, templateId).toString(); + Template template = client.getTemplate(name); + System.out.println("Retrieved template: " + JsonFormat.printer().print(template)); + } + } +} diff --git a/modelarmor/src/main/java/modelarmor/ListTemplates.java b/modelarmor/src/main/java/modelarmor/ListTemplates.java new file mode 100644 index 00000000000..c58eb046be8 --- /dev/null +++ b/modelarmor/src/main/java/modelarmor/ListTemplates.java @@ -0,0 +1,49 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package modelarmor; + +import com.google.cloud.modelarmor.v1.ListTemplatesRequest; +import com.google.cloud.modelarmor.v1.LocationName; +import com.google.cloud.modelarmor.v1.ModelArmorClient; +import com.google.cloud.modelarmor.v1.ModelArmorSettings; +import com.google.cloud.modelarmor.v1.Template; +import com.google.protobuf.util.JsonFormat; + +public class ListTemplates { + + public static void main(String[] args) throws Exception { + // TODO(developer): Replace these variables before running the sample. + String projectId = "your-project-id"; + String locationId = "your-location-id"; + + listTemplates(projectId, locationId); + } + + public static void listTemplates(String projectId, String locationId) throws Exception { + String apiEndpoint = String.format("modelarmor.%s.rep.googleapis.com:443", locationId); + ModelArmorSettings modelArmorSettings = + ModelArmorSettings.newBuilder().setEndpoint(apiEndpoint).build(); + + try (ModelArmorClient client = ModelArmorClient.create(modelArmorSettings)) { + String parent = LocationName.of(projectId, locationId).toString(); + ListTemplatesRequest request = ListTemplatesRequest.newBuilder().setParent(parent).build(); + for (Template template : client.listTemplates(request).iterateAll()) { + System.out.println("Retrived Templates: " + JsonFormat.printer().print(template)); + } + } + } +} diff --git a/modelarmor/src/main/java/modelarmor/ListTemplatesWithFilter.java b/modelarmor/src/main/java/modelarmor/ListTemplatesWithFilter.java new file mode 100644 index 00000000000..590ef9b4f29 --- /dev/null +++ b/modelarmor/src/main/java/modelarmor/ListTemplatesWithFilter.java @@ -0,0 +1,53 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package modelarmor; + +import com.google.cloud.modelarmor.v1.ListTemplatesRequest; +import com.google.cloud.modelarmor.v1.LocationName; +import com.google.cloud.modelarmor.v1.ModelArmorClient; +import com.google.cloud.modelarmor.v1.ModelArmorSettings; +import com.google.cloud.modelarmor.v1.Template; +import com.google.protobuf.util.JsonFormat; + +public class ListTemplatesWithFilter { + + public static void main(String[] args) throws Exception { + // TODO(developer): Replace these variables before running the sample. + String projectId = "your-project-id"; + String locationId = "your-location-id"; + String templateId = "your-template-id"; + + listTemplatesWithFilter(projectId, locationId, templateId); + } + + public static void listTemplatesWithFilter(String projectId, String locationId, String templateId) + throws Exception { + String apiEndpoint = String.format("modelarmor.%s.rep.googleapis.com:443", locationId); + ModelArmorSettings modelArmorSettings = + ModelArmorSettings.newBuilder().setEndpoint(apiEndpoint).build(); + + try (ModelArmorClient client = ModelArmorClient.create(modelArmorSettings)) { + String parent = LocationName.of(projectId, locationId).toString(); + String filter = String.format("name=\"%s/templates/%s\"", parent, templateId); + ListTemplatesRequest request = + ListTemplatesRequest.newBuilder().setParent(parent).setFilter(filter).build(); + for (Template template : client.listTemplates(request).iterateAll()) { + System.out.println("Template with filter: " + JsonFormat.printer().print(template)); + } + } + } +} diff --git a/modelarmor/src/main/java/modelarmor/UpdateTemplate.java b/modelarmor/src/main/java/modelarmor/UpdateTemplate.java new file mode 100644 index 00000000000..64d5eb06e45 --- /dev/null +++ b/modelarmor/src/main/java/modelarmor/UpdateTemplate.java @@ -0,0 +1,81 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package modelarmor; + +import com.google.cloud.modelarmor.v1.DetectionConfidenceLevel; +import com.google.cloud.modelarmor.v1.FilterConfig; +import com.google.cloud.modelarmor.v1.ModelArmorClient; +import com.google.cloud.modelarmor.v1.ModelArmorSettings; +import com.google.cloud.modelarmor.v1.RaiFilterSettings; +import com.google.cloud.modelarmor.v1.RaiFilterSettings.RaiFilter; +import com.google.cloud.modelarmor.v1.RaiFilterType; +import com.google.cloud.modelarmor.v1.Template; +import com.google.cloud.modelarmor.v1.TemplateName; +import com.google.cloud.modelarmor.v1.UpdateTemplateRequest; +import com.google.protobuf.FieldMask; +import com.google.protobuf.util.JsonFormat; +import java.util.List; + +public class UpdateTemplate { + + public static void main(String[] args) throws Exception { + // TODO(developer): Replace these variables before running the sample. + String projectId = "your-project-id"; + String locationId = "your-location-id"; + String templateId = "your-template-id"; + + updateTemplate(projectId, locationId, templateId); + } + + public static void updateTemplate(String projectId, String locationId, String templateId) + throws Exception { + String apiEndpoint = String.format("modelarmor.%s.rep.googleapis.com:443", locationId); + ModelArmorSettings modelArmorSettings = + ModelArmorSettings.newBuilder().setEndpoint(apiEndpoint).build(); + + try (ModelArmorClient client = ModelArmorClient.create(modelArmorSettings)) { + String name = TemplateName.of(projectId, locationId, templateId).toString(); + + Template template = + Template.newBuilder() + .setName(name) + .setFilterConfig( + FilterConfig.newBuilder() + .setRaiSettings( + RaiFilterSettings.newBuilder() + .addAllRaiFilters( + List.of( + RaiFilter.newBuilder() + .setFilterType(RaiFilterType.HARASSMENT) + .setConfidenceLevel( + DetectionConfidenceLevel.MEDIUM_AND_ABOVE) + .build())) + .build()) + .build()) + .build(); + + UpdateTemplateRequest request = + UpdateTemplateRequest.newBuilder() + .setTemplate(template) + .setUpdateMask(FieldMask.newBuilder().addPaths("filter_config").build()) + .build(); + + Template updatedTemplate = client.updateTemplate(request); + System.out.println("Updated template: " + JsonFormat.printer().print(updatedTemplate)); + } + } +} diff --git a/modelarmor/src/main/java/modelarmor/UpdateTemplateLabels.java b/modelarmor/src/main/java/modelarmor/UpdateTemplateLabels.java new file mode 100644 index 00000000000..c07c8c5c470 --- /dev/null +++ b/modelarmor/src/main/java/modelarmor/UpdateTemplateLabels.java @@ -0,0 +1,65 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package modelarmor; + +import com.google.cloud.modelarmor.v1.ModelArmorClient; +import com.google.cloud.modelarmor.v1.ModelArmorSettings; +import com.google.cloud.modelarmor.v1.Template; +import com.google.cloud.modelarmor.v1.TemplateName; +import com.google.cloud.modelarmor.v1.UpdateTemplateRequest; +import com.google.protobuf.FieldMask; +import com.google.protobuf.util.JsonFormat; +import java.util.HashMap; +import java.util.Map; + +public class UpdateTemplateLabels { + + public static void main(String[] args) throws Exception { + // TODO(developer): Replace these variables before running the sample. + String projectId = "your-project-id"; + String locationId = "your-location-id"; + String templateId = "your-template-id"; + + updateTemplateLabels(projectId, locationId, templateId); + } + + public static void updateTemplateLabels(String projectId, String locationId, String templateId) + throws Exception { + String apiEndpoint = String.format("modelarmor.%s.rep.googleapis.com:443", locationId); + ModelArmorSettings modelArmorSettings = + ModelArmorSettings.newBuilder().setEndpoint(apiEndpoint).build(); + + try (ModelArmorClient client = ModelArmorClient.create(modelArmorSettings)) { + String name = TemplateName.of(projectId, locationId, templateId).toString(); + + Map labels = new HashMap<>(); + labels.put("key3", "value3"); + labels.put("key4", "value4"); + + Template template = Template.newBuilder().setName(name).putAllLabels(labels).build(); + + UpdateTemplateRequest request = + UpdateTemplateRequest.newBuilder() + .setTemplate(template) + .setUpdateMask(FieldMask.newBuilder().addPaths("labels").build()) + .build(); + + Template updatedTemplate = client.updateTemplate(request); + System.out.println("Updated template labels: " + JsonFormat.printer().print(updatedTemplate)); + } + } +} diff --git a/modelarmor/src/main/java/modelarmor/UpdateTemplateMetadata.java b/modelarmor/src/main/java/modelarmor/UpdateTemplateMetadata.java new file mode 100644 index 00000000000..bfbea5522a0 --- /dev/null +++ b/modelarmor/src/main/java/modelarmor/UpdateTemplateMetadata.java @@ -0,0 +1,85 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package modelarmor; + +import com.google.cloud.modelarmor.v1.DetectionConfidenceLevel; +import com.google.cloud.modelarmor.v1.FilterConfig; +import com.google.cloud.modelarmor.v1.ModelArmorClient; +import com.google.cloud.modelarmor.v1.ModelArmorSettings; +import com.google.cloud.modelarmor.v1.RaiFilterSettings; +import com.google.cloud.modelarmor.v1.RaiFilterSettings.RaiFilter; +import com.google.cloud.modelarmor.v1.RaiFilterType; +import com.google.cloud.modelarmor.v1.Template; +import com.google.cloud.modelarmor.v1.TemplateName; +import com.google.cloud.modelarmor.v1.UpdateTemplateRequest; +import com.google.protobuf.util.JsonFormat; +import java.util.List; + +public class UpdateTemplateMetadata { + + public static void main(String[] args) throws Exception { + // TODO(developer): Replace these variables before running the sample. + String projectId = "your-project-id"; + String locationId = "your-location-id"; + String templateId = "your-template-id"; + + updateTemplateMetadata(projectId, locationId, templateId); + } + + public static void updateTemplateMetadata(String projectId, String locationId, String templateId) + throws Exception { + String apiEndpoint = String.format("modelarmor.%s.rep.googleapis.com:443", locationId); + ModelArmorSettings modelArmorSettings = + ModelArmorSettings.newBuilder().setEndpoint(apiEndpoint).build(); + + try (ModelArmorClient client = ModelArmorClient.create(modelArmorSettings)) { + String name = TemplateName.of(projectId, locationId, templateId).toString(); + + Template template = + Template.newBuilder() + .setName(name) + // Ensure the rest of the template is correctly populated as needed. + .setTemplateMetadata( + Template.TemplateMetadata.newBuilder() + .setIgnorePartialInvocationFailures(true) + .setLogSanitizeOperations(true)) + .setFilterConfig( + FilterConfig.newBuilder() + .setRaiSettings( + RaiFilterSettings.newBuilder() + .addAllRaiFilters( + List.of( + RaiFilter.newBuilder() + .setFilterType(RaiFilterType.DANGEROUS) + .setConfidenceLevel(DetectionConfidenceLevel.HIGH) + .build())) + .build()) + .build()) + .build(); + + UpdateTemplateRequest request = + UpdateTemplateRequest.newBuilder() + .setTemplate(template) + // Removed the setUpdateMask line to attempt a full update. + .build(); + + Template updatedTemplate = client.updateTemplate(request); + System.out.println( + "Updated template metadata: " + JsonFormat.printer().print(updatedTemplate)); + } + } +} diff --git a/modelarmor/src/main/java/modelarmor/UpdateTemplateWithMaskConfiguration.java b/modelarmor/src/main/java/modelarmor/UpdateTemplateWithMaskConfiguration.java new file mode 100644 index 00000000000..39375e9542e --- /dev/null +++ b/modelarmor/src/main/java/modelarmor/UpdateTemplateWithMaskConfiguration.java @@ -0,0 +1,84 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package modelarmor; + +import com.google.cloud.modelarmor.v1.DetectionConfidenceLevel; +import com.google.cloud.modelarmor.v1.FilterConfig; +import com.google.cloud.modelarmor.v1.ModelArmorClient; +import com.google.cloud.modelarmor.v1.ModelArmorSettings; +import com.google.cloud.modelarmor.v1.RaiFilterSettings; +import com.google.cloud.modelarmor.v1.RaiFilterSettings.RaiFilter; +import com.google.cloud.modelarmor.v1.RaiFilterType; +import com.google.cloud.modelarmor.v1.Template; +import com.google.cloud.modelarmor.v1.TemplateName; +import com.google.cloud.modelarmor.v1.UpdateTemplateRequest; +import com.google.protobuf.FieldMask; +import com.google.protobuf.util.JsonFormat; +import java.util.List; + +public class UpdateTemplateWithMaskConfiguration { + + public static void main(String[] args) throws Exception { + // TODO(developer): Replace these variables before running the sample. + String projectId = "your-project-id"; + String locationId = "your-location-id"; + String templateId = "your-template-id"; + + updateTemplateWithMaskConfiguration(projectId, locationId, templateId); + } + + public static void updateTemplateWithMaskConfiguration( + String projectId, String locationId, String templateId) throws Exception { + String apiEndpoint = String.format("modelarmor.%s.rep.googleapis.com:443", locationId); + ModelArmorSettings modelArmorSettings = + ModelArmorSettings.newBuilder().setEndpoint(apiEndpoint).build(); + + try (ModelArmorClient client = ModelArmorClient.create(modelArmorSettings)) { + String name = TemplateName.of(projectId, locationId, templateId).toString(); + + Template template = + Template.newBuilder() + .setName(name) + .setFilterConfig( + FilterConfig.newBuilder() + .setRaiSettings( + RaiFilterSettings.newBuilder() + .addAllRaiFilters( + List.of( + RaiFilter.newBuilder() + .setFilterType(RaiFilterType.HARASSMENT) + .setConfidenceLevel( + DetectionConfidenceLevel.MEDIUM_AND_ABOVE) + .build())) + .build()) + .build()) + .build(); + + UpdateTemplateRequest request = + UpdateTemplateRequest.newBuilder() + .setTemplate(template) + .setUpdateMask( + FieldMask.newBuilder().addPaths("filter_config.rai_settings.rai_filters").build()) + .build(); + + Template updatedTemplate = client.updateTemplate(request); + System.out.println( + "Updated template with mask configuration: " + + JsonFormat.printer().print(updatedTemplate)); + } + } +} diff --git a/modelarmor/src/test/java/modelarmor/SnippetsIT.java b/modelarmor/src/test/java/modelarmor/SnippetsIT.java new file mode 100644 index 00000000000..8ebb58abfb7 --- /dev/null +++ b/modelarmor/src/test/java/modelarmor/SnippetsIT.java @@ -0,0 +1,172 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package modelarmor; + +import static com.google.common.truth.Truth.assertThat; + +import com.google.cloud.modelarmor.v1.Template; +import com.google.common.base.Strings; +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import java.util.UUID; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** Integration (system) tests for {@link Snippets}. */ +@RunWith(JUnit4.class) +@SuppressWarnings("checkstyle:AbbreviationAsWordInName") +public class SnippetsIT { + + private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); + private static final String LOCATION = "us-central1"; + private static final String MA_REGIONAL_ENDPOINT = + String.format("modelarmor.%s.rep.googleapis.com:443", LOCATION); + private static final String DLP_REGIONAL_ENDPOINT = + String.format("dlp.%s.rep.googleapis.com:443", LOCATION); + private static final String INSPECT_TEMPLATE_ID = + "model-armour-inspect-template-" + UUID.randomUUID().toString(); + private static final String DEIDENTIFY_TEMPLATE_ID = + "model-armour-deidentify-template-" + UUID.randomUUID().toString(); + private static Template TEST_MODELARMOR_TEMPLATE; + private static Template TEST_MODELARMOR_TEMPLATE_NAME; + private static String TEMPLATE_ID; + + private ByteArrayOutputStream stdOut; + + @BeforeClass + public static void beforeAll() throws Exception { + Assert.assertFalse("missing GOOGLE_CLOUD_PROJECT", Strings.isNullOrEmpty(PROJECT_ID)); + Assert.assertFalse("missing GOOGLE_CLOUD_PROJECT_LOCATION", Strings.isNullOrEmpty(LOCATION)); + } + + @AfterClass + public static void afterAll() throws Exception { + Assert.assertFalse("missing GOOGLE_CLOUD_PROJECT", Strings.isNullOrEmpty(PROJECT_ID)); + } + + @Before + public void beforeEach() { + stdOut = new ByteArrayOutputStream(); + System.setOut(new PrintStream(stdOut)); + + TEMPLATE_ID = "test-model-armor-" + UUID.randomUUID().toString(); + } + + @After + public void afterEach() throws Exception { + stdOut = null; + System.setOut(null); + } + + @Test + public void testCreateModelArmorTemplate() throws Exception { + CreateTemplate.createTemplate(PROJECT_ID, LOCATION, TEMPLATE_ID); + assertThat(stdOut.toString()).contains("Created template"); + DeleteTemplate.deleteTemplate(PROJECT_ID, LOCATION, TEMPLATE_ID); + } + + @Test + public void testCreateModelArmorTemplateWithBasicSDP() throws Exception { + CreateTemplateWithBasicSdp.createTemplateWithBasicSdp(PROJECT_ID, LOCATION, TEMPLATE_ID); + assertThat(stdOut.toString()).contains("Created template with basic sdp: "); + DeleteTemplate.deleteTemplate(PROJECT_ID, LOCATION, TEMPLATE_ID); + } + + @Test + public void testCreateModelArmorTemplateWithLabels() throws Exception { + CreateTemplateWithLabels.createTemplateWithLabels(PROJECT_ID, LOCATION, TEMPLATE_ID); + assertThat(stdOut.toString()).contains("Created template with labels"); + DeleteTemplate.deleteTemplate(PROJECT_ID, LOCATION, TEMPLATE_ID); + } + + @Test + public void testCreateModelArmorTemplateWithMetadata() throws Exception { + CreateTemplateWithMetadata.createTemplateWithMetadata(PROJECT_ID, LOCATION, TEMPLATE_ID); + assertThat(stdOut.toString()).contains("Created template with metadata"); + DeleteTemplate.deleteTemplate(PROJECT_ID, LOCATION, TEMPLATE_ID); + } + + @Test + public void testDeleteModelArmorTemplate() throws Exception { + CreateTemplate.createTemplate(PROJECT_ID, LOCATION, TEMPLATE_ID); + DeleteTemplate.deleteTemplate(PROJECT_ID, LOCATION, TEMPLATE_ID); + assertThat(stdOut.toString()).contains("Deleted template"); + } + + @Test + public void testGetModelArmorTemplate() throws Exception { + CreateTemplate.createTemplate(PROJECT_ID, LOCATION, TEMPLATE_ID); + GetTemplate.getTemplate(PROJECT_ID, LOCATION, TEMPLATE_ID); + assertThat(stdOut.toString()).contains("Retrieved template"); + DeleteTemplate.deleteTemplate(PROJECT_ID, LOCATION, TEMPLATE_ID); + } + + @Test + public void testListModelArmorTemplates() throws Exception { + CreateTemplate.createTemplate(PROJECT_ID, LOCATION, TEMPLATE_ID); + ListTemplates.listTemplates(PROJECT_ID, LOCATION); + assertThat(stdOut.toString()).contains("Retrived Templates"); + DeleteTemplate.deleteTemplate(PROJECT_ID, LOCATION, TEMPLATE_ID); + } + + @Test + public void testListTemplatesWithFilter() throws Exception { + CreateTemplate.createTemplate(PROJECT_ID, LOCATION, TEMPLATE_ID); + ListTemplatesWithFilter.listTemplatesWithFilter(PROJECT_ID, LOCATION, TEMPLATE_ID); + assertThat(stdOut.toString()).contains("Template with filter"); + DeleteTemplate.deleteTemplate(PROJECT_ID, LOCATION, TEMPLATE_ID); + } + + @Test + public void testUpdateModelArmorTemplate() throws Exception { + CreateTemplate.createTemplate(PROJECT_ID, LOCATION, TEMPLATE_ID); + UpdateTemplate.updateTemplate(PROJECT_ID, LOCATION, TEMPLATE_ID); + assertThat(stdOut.toString()).contains("Updated template"); + DeleteTemplate.deleteTemplate(PROJECT_ID, LOCATION, TEMPLATE_ID); + } + + @Test + public void testUpdateModelArmorTemplateWithLabels() throws Exception { + CreateTemplate.createTemplate(PROJECT_ID, LOCATION, TEMPLATE_ID); + UpdateTemplateLabels.updateTemplateLabels(PROJECT_ID, LOCATION, TEMPLATE_ID); + assertThat(stdOut.toString()).contains("Updated template labels"); + DeleteTemplate.deleteTemplate(PROJECT_ID, LOCATION, TEMPLATE_ID); + } + + @Test + public void testUpdateModelArmorTemplateWithMetadata() throws Exception { + CreateTemplate.createTemplate(PROJECT_ID, LOCATION, TEMPLATE_ID); + UpdateTemplateMetadata.updateTemplateMetadata(PROJECT_ID, LOCATION, TEMPLATE_ID); + assertThat(stdOut.toString()).contains("Updated template metadata"); + DeleteTemplate.deleteTemplate(PROJECT_ID, LOCATION, TEMPLATE_ID); + } + + @Test + public void testUpdateModelArmorTemplateWithMaskConfiguration() throws Exception { + CreateTemplate.createTemplate(PROJECT_ID, LOCATION, TEMPLATE_ID); + UpdateTemplateWithMaskConfiguration.updateTemplateWithMaskConfiguration( + PROJECT_ID, LOCATION, TEMPLATE_ID); + assertThat(stdOut.toString()).contains("Updated template with mask configuration"); + DeleteTemplate.deleteTemplate(PROJECT_ID, LOCATION, TEMPLATE_ID); + } +} From 0fed40f590199d74a64787d8d53a364649f4b17b Mon Sep 17 00:00:00 2001 From: tirthrajsinh-zala-crest Date: Thu, 10 Apr 2025 15:05:05 +0530 Subject: [PATCH 2/2] feat(modelarmor):update licence version --- modelarmor/src/main/java/modelarmor/CreateTemplate.java | 4 +--- .../src/main/java/modelarmor/CreateTemplateWithBasicSdp.java | 2 +- .../src/main/java/modelarmor/CreateTemplateWithLabels.java | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/modelarmor/src/main/java/modelarmor/CreateTemplate.java b/modelarmor/src/main/java/modelarmor/CreateTemplate.java index f8391be7766..3d3e0b44c3d 100644 --- a/modelarmor/src/main/java/modelarmor/CreateTemplate.java +++ b/modelarmor/src/main/java/modelarmor/CreateTemplate.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 Google LLC + * Copyright 2025 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,6 @@ package modelarmor; -// TODO(nasit): Add region tags in all snippets. import com.google.cloud.modelarmor.v1.CreateTemplateRequest; import com.google.cloud.modelarmor.v1.DetectionConfidenceLevel; import com.google.cloud.modelarmor.v1.FilterConfig; @@ -28,7 +27,6 @@ import com.google.cloud.modelarmor.v1.RaiFilterType; import com.google.cloud.modelarmor.v1.Template; import com.google.protobuf.util.JsonFormat; -import java.util.Arrays; import java.util.List; public class CreateTemplate { diff --git a/modelarmor/src/main/java/modelarmor/CreateTemplateWithBasicSdp.java b/modelarmor/src/main/java/modelarmor/CreateTemplateWithBasicSdp.java index 708aafbb395..1649773a082 100644 --- a/modelarmor/src/main/java/modelarmor/CreateTemplateWithBasicSdp.java +++ b/modelarmor/src/main/java/modelarmor/CreateTemplateWithBasicSdp.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 Google LLC + * Copyright 2025 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/modelarmor/src/main/java/modelarmor/CreateTemplateWithLabels.java b/modelarmor/src/main/java/modelarmor/CreateTemplateWithLabels.java index 7951a97a35e..6b40947e9db 100644 --- a/modelarmor/src/main/java/modelarmor/CreateTemplateWithLabels.java +++ b/modelarmor/src/main/java/modelarmor/CreateTemplateWithLabels.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 Google LLC + * Copyright 2025 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.