-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(modelarmor): Added sanitization modelarmor code snippets #5267
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
feat(modelarmor): Added sanitization modelarmor code snippets #5267
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 @tirthrajsinh-zala-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 new code snippets for sanitizing user prompts, model responses, and PDF files using the Model Armor API. It includes a new file for creating Model Armor templates, along with corresponding tests and necessary module updates. The changes aim to provide examples of how to use Model Armor to protect against harmful content in user inputs and model outputs.
Highlights
- New Functionality: Adds code snippets for sanitizing model responses with and without user prompts, as well as for screening PDF files.
- Template Creation: Introduces a function to create Model Armor templates with predefined filters for PI, jailbreak attempts, and malicious URIs.
- Testing: Includes comprehensive tests for the new sanitization and screening functionalities, ensuring proper integration and functionality.
- Module Updates: Updates the
go.mod
andgo.sum
files to include the necessary dependencies for the Model Armor API.
Changelog
Click here to see the changelog
- modelarmor/create_template.go
- Introduces a new function
createModelArmorTemplate
to create Model Armor templates with specified filters. - Includes example usage and documentation for creating templates.
- Introduces a new function
- modelarmor/go.mod
- Adds dependencies for
cloud.google.com/go/modelarmor
,github.com/google/uuid
,google.golang.org/api
,google.golang.org/grpc
, andgoogle.golang.org/protobuf
. - Updates the Go module version to 1.23.0.
- Adds dependencies for
- modelarmor/go.sum
- Adds checksums for the new dependencies introduced in
go.mod
.
- Adds checksums for the new dependencies introduced in
- modelarmor/modelarmor_test.go
- Adds tests for sanitizing model responses, user prompts, and screening PDF files.
- Includes helper functions for creating and cleaning up Model Armor templates.
- Uses
testutil.SystemTest
for integration testing with the Google Cloud environment.
- modelarmor/sanitize_model_response.go
- Introduces a new function
sanitizeModelResponse
to sanitize model responses using a Model Armor template. - Includes example usage and documentation for sanitizing model responses.
- Introduces a new function
- modelarmor/sanitize_model_response_with_user_prompt.go
- Introduces a new function
sanitizeModelResponseWithUserPrompt
to sanitize model responses with a user prompt using a Model Armor template. - Includes example usage and documentation for sanitizing model responses with user prompts.
- Introduces a new function
- modelarmor/sanitize_user_prompt.go
- Introduces a new function
sanitizeUserPrompt
to sanitize user prompts using a Model Armor template. - Includes example usage and documentation for sanitizing user prompts.
- Introduces a new function
- modelarmor/screen_pdf_file.go
- Introduces a new function
screenPDFFile
to screen PDF file content using a Model Armor template. - Includes example usage and documentation for screening PDF files.
- Introduces a new function
- modelarmor/testdata/env/test.env
- Adds environment variables for
GOLANG_SAMPLES_ORGANIZATION_ID
andGOLANG_SAMPLES_FOLDER_ID
.
- Adds environment variables for
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 born,
Filters rise, armor is sworn,
To guard the model.
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 new functionalities for sanitizing model responses, user prompts, and screening PDF files using the Model Armor API. The code includes examples for creating Model Armor templates and performing sanitization tasks. Overall, the code is well-structured and easy to follow. However, there are some areas that could be improved for better error handling and code clarity.
Summary of Findings
- Error Handling: The code uses
fmt.Errorf
for error wrapping, which is good. However, consider adding more context to the error messages to provide better debugging information. - Test Environment: The test suite relies on environment variables and external files. Ensure that these dependencies are properly documented and handled to avoid test failures in different environments.
- Redundant Imports: The
modelarmor_test.go
file contains a commented-out import statement formodelarmorpb
. Remove this unused import to reduce clutter.
Merge Readiness
The pull request is almost ready for merging. Before merging, address the high and medium severity issues to ensure the code is robust and maintainable. I am unable to directly approve this pull request, and users should have others review and approve this code before merging.
Here is the summary of changes. You are about to add 5 region tags.
This comment is generated by snippet-bot.
|
Please split this PR into multiple PRs of <= 500 LoC each. Thank you. |
Description
Created samples for user prompt and model response sanitation using model armor APIs.
Checklist
go test -v ./..
(see Testing)gofmt
(see Formatting)go vet
(see Formatting)