-
Notifications
You must be signed in to change notification settings - Fork 2k
feat(modelarmor): Added snippets for sanitization #4051
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 snippets for sanitization #4051
Conversation
Here is the summary of changes. You are about to add 4 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.
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 snippets for sanitizing user prompts and model responses using the Model Armor API. It includes code for creating templates with various configurations, such as RAI filters, SDP settings, labels, and metadata. The snippets demonstrate how to sanitize user prompts and model responses, including PDF content, and how to manage templates (create, delete, get, list, update). The changes also include updates to the .github/blunderbuss.yml
and CODEOWNERS
files to include the model-armor
API.
Highlights
- New snippets: Adds new snippets for creating Model Armor templates with RAI filters, SDP settings, labels, and metadata.
- Sanitization: Introduces snippets for sanitizing user prompts and model responses, including PDF content, using Model Armor templates.
- Template management: Provides snippets for managing Model Armor templates (create, delete, get, list, update).
- Configuration: Updates
.github/blunderbuss.yml
andCODEOWNERS
to include themodel-armor
API.
Changelog
Click here to see the changelog
- .github/blunderbuss.yml
- Adds
api: modelarmor
to the issue and PR auto-assigner, associating it with theGoogleCloudPlatform/cloud-modelarmor-team
.
- Adds
- CODEOWNERS
- Adds
model-armor
to the CODEOWNERS file, assigning ownership to@GoogleCloudPlatform/nodejs-samples-reviewers
,@GoogleCloudPlatform/cloud-samples-reviewers
, and@GoogleCloudPlatform/cloud-modelarmor-team
.
- Adds
- model-armor/package.json
- Creates a
package.json
file for themodel-armor
samples, defining dependencies, scripts, and metadata.
- Creates a
- model-armor/snippets/createTemplate.js
- Adds a snippet for creating a Model Armor template with Responsible AI (RAI) filters.
- model-armor/snippets/createTemplateWithAdvancedSdp.js
- Adds a snippet for creating a Model Armor template with advanced SDP settings enabled.
- model-armor/snippets/createTemplateWithBasicSdp.js
- Adds a snippet for creating a Model Armor template with basic SDP settings enabled.
- model-armor/snippets/createTemplateWithLabels.js
- Adds a snippet for creating a Model Armor template with Responsible AI (RAI) filters and custom labels.
- model-armor/snippets/createTemplateWithMetadata.js
- Adds a snippet for creating a Model Armor template with template metadata.
- model-armor/snippets/deleteTemplate.js
- Adds a snippet for deleting a Model Armor template.
- model-armor/snippets/getTemplate.js
- Adds a snippet for retrieving a Model Armor template by its ID.
- model-armor/snippets/listTemplates.js
- Adds a snippet for listing all Model Armor templates in a specified project and location.
- model-armor/snippets/listTemplatesWithFilter.js
- Adds a snippet for listing Model Armor templates that match a specific filter criteria.
- model-armor/snippets/sanitizeModelResponse.js
- Adds a snippet for sanitizing a model response using Model Armor filters.
- model-armor/snippets/sanitizeModelResponseWithUserPrompt.js
- Adds a snippet for sanitizing a model response with context from the original user prompt.
- model-armor/snippets/sanitizeUserPrompt.js
- Adds a snippet for sanitizing a user prompt using Model Armor filters.
- model-armor/snippets/screenPdfFile.js
- Adds a snippet for sanitizing/screening PDF content using the Model Armor API.
- model-armor/snippets/updateTemplate.js
- Adds a snippet for updating an existing Model Armor template.
- model-armor/snippets/updateTemplateLabels.js
- Adds a snippet for updating the labels of an existing Model Armor template.
- model-armor/snippets/updateTemplateMetadata.js
- Adds a snippet for updating the metadata of an existing Model Armor template.
- model-armor/snippets/updateTemplateWithMaskConfiguration.js
- Adds a snippet for updating an existing Model Armor template with a specific update mask.
- model-armor/test/.eslintrc.yml
- Adds an
.eslintrc.yml
file for themodel-armor
tests, configuring the environment for Mocha.
- Adds an
- model-armor/test/modelarmor.test.js
- Adds a test suite for the Model Armor snippets, covering user prompt sanitization, model response sanitization, and PDF sanitization.
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.
Did you know?
The concept of using filters to sanitize content dates back to ancient libraries, where librarians would curate and restrict access to certain texts based on their content.
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
This pull request introduces snippets for user prompt and model response sanitization using the Model Armor API. The changes include adding new files for various sanitization scenarios and updating the blunderbuss configuration and CODEOWNERS file. Overall, the code seems well-structured and addresses the intended functionality. However, there are a few areas that could be improved for clarity and maintainability.
Summary of Findings
- Missing Error Handling: The code lacks explicit error handling for API calls and other operations, which could lead to unhandled exceptions and unexpected behavior. It's important to add error handling to ensure the application is robust and provides informative error messages.
- Copyright Year: The copyright year is set to 2025 in all the new files. Please confirm if this is the correct year, or if it should be updated to the current year.
- TODO comments: The code contains TODO comments that should be addressed before merging. These comments indicate areas where the code needs further implementation or clarification.
Merge Readiness
The pull request is not quite ready for merging. There are a few issues that need to be addressed before merging, including adding error handling, confirming the copyright year, and addressing the TODO comments. I am unable to approve this pull request, and recommend that another reviewer also take a look at this code before merging.
…hsha-crest/nodejs-docs-samples into model-armor-sanitization-snippets
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.
See internal discussion.
765ab68
to
7ebf8e9
Compare
…oudPlatform#4055) * chore(cloud-sql): migrate mysql, postgres samples to new CI * rename to match postgres version * acquireTimeout warns in mysql2, remove * mysql2 query returns [results, fields], so only return fields * remove unused test scripts * revert bot-suggested rename: would cause excessive region tag change
* chore(compute): Migrate region tag * chore(compute): Rename region tag
overriding failure as this is jsut removing the region tag.
* feat: support testing on forked repos * add pull_request to test on PR * remove prod suffix * decode json on matrix paths * add experimental to check names * add experimental to job names * run test only if paths is not empty * test explicitly against empty array * move experimental as a prefix * success check if no paths are found * always set check to done * remove pull_request trigger * rearrange if check * add more comments
* feat: support testing on forked repos * add pull_request to test on PR * remove prod suffix * decode json on matrix paths * add experimental to check names * add experimental to job names * run test only if paths is not empty * test explicitly against empty array * move experimental as a prefix * success check if no paths are found * always set check to done * remove pull_request trigger * rearrange if check * add more comments * fix: add id-token to workflows
7ebf8e9
to
342078f
Compare
…hsha-crest/nodejs-docs-samples into model-armor-sanitization-snippets
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.
Please make sure there the prompts are exactly same as in the python samples repo. I have highlighted a couple of differences here. Please double check other prompts as well.
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.
LGTM ✅
Verified that all user prompts and model responses are sourced from Python samples.
|
||
--- | ||
env: | ||
mocha: true |
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.
nit: add new line at bottom of file.
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.
Looking much better! Thank you so much.
I left a couple of small comments for your next pass--accept or reject as you see fit. Once I see your acknowledgement of those comments, I will manage merging this PR for you.
|
||
module.exports = sanitizeModelResponse; | ||
|
||
// TODO(developer): Uncomment below lines before running the sample. |
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.
nit: I would cut this. Although this is a nice-to-have for developers who might want to run this sample as main, it's a little unsightly to have this commented out.
Up to you whether to keep or cut.
|
||
module.exports = sanitizeModelResponseWithUserPrompt; | ||
|
||
// TODO(developer): Uncomment below lines before running the sample. |
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.
nit: same as previous.
|
||
module.exports = sanitizeUserPrompt; | ||
|
||
// TODO(developer): Uncomment below lines before running the sample. |
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.
nit: same as previous.
Description
Created samples for user prompt and model response sanitation using model armor APIs.
Checklist
npm test
(see Testing)npm run lint
(see Style)Model Armor API
GoogleCloudPlatform/nodejs-docs-samples
. Not a fork.