-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
base: main
Are you sure you want to change the base?
feat(modelarmor): Added code samples to update model armor templates #10069
Conversation
There was a problem hiding this 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 aFieldMask
to update only thefilter_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
andUpdateTemplateRequest
with aFieldMask
targeting thelabels
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
andlogSanitizeOperations
in the template metadata. - The
UpdateTemplateRequest
is constructed without aFieldMask
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 thefilter_config.rai_settings
using aFieldMask
. - 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
-
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. ↩
There was a problem hiding this 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 theUpdateMask
, 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.
modelarmor/src/main/java/modelarmor/UpdateTemplateMetadata.java
Outdated
Show resolved
Hide resolved
modelarmor/src/main/java/modelarmor/UpdateTemplateMetadata.java
Outdated
Show resolved
Hide resolved
modelarmor/src/main/java/modelarmor/UpdateTemplateWithMaskConfiguration.java
Outdated
Show resolved
Hide resolved
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! |
Here is the summary of changes. You are about to add 7 region tags.
This comment is generated by snippet-bot.
|
There was a problem hiding this 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:"); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Description
Added code samples to update Model Armor templates
Checklist
pom.xml
parent set to latestshared-configuration
mvn clean verify
requiredmvn -P lint checkstyle:check
requiredmvn -P lint clean compile pmd:cpd-check spotbugs:check
advisory only