Skip to content

feat(modelarmor): Added create template samples for modelarmor #10068

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

rudrakhsha-crest
Copy link

@rudrakhsha-crest rudrakhsha-crest commented Apr 11, 2025

Description

Added code samples for creating Model Armor templates.

Checklist

  • I have followed Sample Format Guide
  • pom.xml parent set to latest shared-configuration
  • Appropriate changes to README are included in PR
  • These samples need a new API enabled in testing projects to pass (let us know which ones)
  • These samples need a new/updated env vars in testing projects set to pass (let us know which ones)
  • Tests pass: mvn clean verify required
  • Lint passes: mvn -P lint checkstyle:check required
  • Static Analysis: mvn -P lint clean compile pmd:cpd-check spotbugs:check advisory only
  • This sample adds a new sample directory, and I updated the CODEOWNERS file with the codeowners for this sample
  • This sample adds a new Product API, and I updated the Blunderbuss issue/PR auto-assigner with the codeowners for this sample
  • Please merge this PR for me once it is approved

@rudrakhsha-crest rudrakhsha-crest requested review from yoshi-approver and a team as code owners April 11, 2025 12:31
@product-auto-label product-auto-label bot added the samples Issues that are directly related to samples. label Apr 11, 2025
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @rudrakhsha-crest, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

This pull request introduces sample code snippets for the Model Armor API using the Google Java API Client Libraries. It includes examples for creating templates with different configurations, such as basic SDP, labels, and metadata. The PR also includes a README file with instructions on how to enable the API, grant permissions, and set environment variables, as well as integration tests for the new samples.

Highlights

  • New samples: Added four new Java samples demonstrating how to create Model Armor templates with different configurations: basic, with SDP, with labels, and with metadata.
  • README update: The README.md file was updated with instructions on how to enable the Model Armor API, grant necessary permissions, and set the required environment variables.
  • Integration tests: Added integration tests to verify the functionality of the new sample code snippets.

Changelog

Click here to see the changelog
  • modelarmor/README.md
    • Added a README file with prerequisites and instructions for using the Model Armor samples, including enabling the API, granting permissions, and setting environment variables (lines 1-29).
  • modelarmor/pom.xml
    • Added dependencies for google-cloud-modelarmor, google-cloud-dlp, protobuf-java-util, and lombok (lines 53-74).
    • Added test dependencies for junit and truth (lines 77-88).
    • Configured the maven-compiler-plugin to use Java 11 and enable annotation processing for Lombok (lines 91-108).
  • modelarmor/src/main/java/modelarmor/CreateTemplate.java
    • Created a sample for creating a basic Model Armor template with a dangerous RAI filter and high confidence level (lines 1-80).
  • modelarmor/src/main/java/modelarmor/CreateTemplateWithBasicSdp.java
    • Created a sample for creating a Model Armor template with basic SDP settings, including a dangerous RAI filter with high confidence (lines 1-81).
  • modelarmor/src/main/java/modelarmor/CreateTemplateWithLabels.java
    • Created a sample for creating a Model Armor template with labels (key1=value1, key2=value2) and a dangerous RAI filter with high confidence (lines 1-87).
  • modelarmor/src/main/java/modelarmor/CreateTemplateWithMetadata.java
    • Created a sample for creating a Model Armor template with metadata (ignorePartialInvocationFailures=true, logSanitizeOperations=true) and a dangerous RAI filter with high confidence (lines 1-85).
  • modelarmor/src/test/java/modelarmor/SnippetsIT.java
    • Added integration tests for the new create template samples, verifying that they create templates successfully and that the output contains the expected messages (lines 1-108).
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


Model Armor stands,
A shield for language models,
Protecting AI.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request introduces new samples for creating Model Armor templates with different configurations. The code is generally well-structured and easy to follow. However, there are a few areas that could be improved for clarity and maintainability.

Summary of Findings

  • Missing DeleteTemplate Samples: The pull request adds samples for creating Model Armor templates but lacks corresponding samples for deleting them. This could lead to resource accumulation and make it difficult for users to clean up their test environments. It would be helpful to add samples for deleting the created templates.
  • Duplicated Code: The code for creating templates is very similar across the different samples (basic, with labels, with metadata). Consider refactoring the common parts into a shared utility function to reduce code duplication and improve maintainability.
  • Hardcoded Location: The location is hardcoded as us-central1 in the test file. It would be better to use an environment variable or a configuration parameter to allow users to test in different regions.

Merge Readiness

The pull request is almost ready for merging. Before merging, I recommend adding samples for deleting the created templates and addressing the code duplication issue. The hardcoded location in the test file should also be addressed. I am unable to approve this pull request, and recommend that others review and approve this code before merging.

@telpirion telpirion assigned telpirion and unassigned telpirion and Mukamik Apr 11, 2025
@rudrakhsha-crest rudrakhsha-crest marked this pull request as ready for review April 15, 2025 13:46
Copy link

snippet-bot bot commented Apr 15, 2025

Here is the summary of changes.

You are about to add 5 region tags.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@harshnasitcrest
Copy link

@telpirion Thanks for the review! All the comments have been addressed. Please review and let us know your feedback.

@harshnasitcrest harshnasitcrest requested a review from a team as a code owner April 16, 2025 13:53
Copy link

@utsav1810 utsav1810 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved on behalf of the Model Armor team.

@gptSanyam gptSanyam added kokoro:run Add this label to force Kokoro to re-run the tests. kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Apr 17, 2025
@kokoro-team kokoro-team removed kokoro:run Add this label to force Kokoro to re-run the tests. kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Apr 17, 2025
@gptSanyam gptSanyam added kokoro:run Add this label to force Kokoro to re-run the tests. kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Apr 18, 2025
@kokoro-team kokoro-team removed kokoro:run Add this label to force Kokoro to re-run the tests. kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Apr 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
samples Issues that are directly related to samples.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants