Skip to content

feat(modelarmor): Added code samples to update model armor templates #10069

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 5 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 to update 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:35
@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 adds code samples to update Model Armor templates. It includes four new Java files: UpdateTemplate.java, UpdateTemplateLabels.java, UpdateTemplateMetadata.java, and UpdateTemplateWithMaskConfiguration.java. Each file demonstrates a different way to update a Model Armor template, such as updating the filter configuration, labels, metadata, or using a field mask. Additionally, it adds integration tests to verify the functionality of these new samples.

Highlights

  • New Samples: Four new Java files are added to demonstrate different update scenarios for Model Armor templates.
  • Update Template Functionality: The samples cover updating filter configurations, labels, metadata, and using field masks for partial updates.
  • Integration Tests: Integration tests are included to verify the functionality of the new update template samples.

Changelog

Click here to see the changelog
  • modelarmor/src/main/java/modelarmor/UpdateTemplate.java
    • Added a new sample to update the filter configuration of a Model Armor template, specifically setting a harassment filter with a medium and above confidence level.
    • Uses UpdateTemplateRequest with a FieldMask to update only the filter_config field.
  • modelarmor/src/main/java/modelarmor/UpdateTemplateLabels.java
    • Added a new sample to update the labels of a Model Armor template.
    • Demonstrates how to add or modify labels using a HashMap and UpdateTemplateRequest with a FieldMask targeting the labels field.
  • modelarmor/src/main/java/modelarmor/UpdateTemplateMetadata.java
    • Added a new sample to update the metadata of a Model Armor template.
    • Shows how to set ignorePartialInvocationFailures and logSanitizeOperations in the template metadata.
    • The UpdateTemplateRequest is constructed without a FieldMask to perform a full update.
  • modelarmor/src/main/java/modelarmor/UpdateTemplateWithMaskConfiguration.java
    • Added a new sample to update a Model Armor template using a more specific field mask.
    • Demonstrates updating the rai_filters within the filter_config.rai_settings using a FieldMask.
    • Sets a harassment filter with a medium and above confidence level.
  • modelarmor/src/test/java/modelarmor/SnippetsIT.java
    • Added integration tests for the new update template samples.
    • Each test creates a template, updates it using one of the new samples, and then deletes the template.
    • Verifies that the update operation is successful by checking the output stream for specific messages.
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.


A template's form,
Mutable, it can transform,
With updates applied,
Its purpose defined,
A digital work of art born.

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 code samples for updating Model Armor templates, covering different aspects like filter configuration, labels, and metadata. The samples seem well-structured and provide a good starting point for users to understand how to update templates. However, there are a few areas that could be improved for clarity and completeness.

Summary of Findings

  • Missing UpdateMask in UpdateTemplateMetadata: The UpdateTemplateMetadata sample intentionally removes the UpdateMask, but this could lead to unintended consequences if other fields in the template are not properly set. It's important to highlight this behavior and provide guidance on when and why a full update might be necessary, as well as the risks involved.
  • TODO comments: The TODO comments in the main methods of each sample should be addressed before merging. While they serve as placeholders, they should be replaced with actual instructions or removed if no longer relevant.

Merge Readiness

The code is almost ready to be merged, but there are a few issues that need to be addressed first. Specifically, the TODO comments should be resolved, and the potential implications of removing the UpdateMask in UpdateTemplateMetadata should be clarified. 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 Mukamik Apr 11, 2025
@telpirion
Copy link
Contributor

This PR has the same global issues as #10068 . Please re-open once all global issues are addressed.

@telpirion telpirion marked this pull request as draft April 11, 2025 19:41
@harshnasitcrest
Copy link

harshnasitcrest commented Apr 15, 2025

This PR has the same global issues as #10068 . Please re-open once all global issues are addressed.

Thanks for the review! All global issues have been addressed in this PR. Note that create templates and delete template snippet have been added just to pass tests. Please ignore its review. They're present in #10068

@rudrakhsha-crest Please update the PR description, update checklist and open the PR for review.

@rudrakhsha-crest
Copy link
Author

This PR has the same global issues as #10068 . Please re-open once all global issues are addressed.

Thanks for the review! All global issues have been addressed in this PR. Note that create templates and delete template snippet have been added just to pass tests. Please ignore its review. They're present in #10068

@rudrakhsha-crest Please update the PR description, update checklist and open the PR for review.

Done!

@rudrakhsha-crest rudrakhsha-crest marked this pull request as ready for review April 16, 2025 05:41
Copy link

snippet-bot bot commented Apr 16, 2025

Here is the summary of changes.

You are about to add 7 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

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.

Template updatedTemplate = UpdateTemplate.updateTemplate(PROJECT_ID, LOCATION_ID,
TEST_TEMPLATE_ID);

assertThat(stdOut.toString()).contains("Updated template:");

Choose a reason for hiding this comment

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

I don't see the value addition of doing an assert on the stdOut. We are asserting on the updateTemplate.getName() which should be a good enough indication that the update was successful. Please remove if this is not needed.

Same for others.

Choose a reason for hiding this comment

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

Done.

@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
harshnasitcrest added a commit to tirthrajsinh-zala-crest/java-docs-samples that referenced this pull request Apr 18, 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 the kokoro:run Add this label to force Kokoro to re-run the tests. label Apr 18, 2025
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label 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