-
Notifications
You must be signed in to change notification settings - Fork 6.5k
fix: refactor model_armor #13305
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
fix: refactor model_armor #13305
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 @glasnt, 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 focuses on refactoring the model_armor snippets, specifically addressing the quickstart and screen_pdf_file examples, and updating the snippets tests. The primary goal is to improve the examples and tests by using more generic and safe content, as well as updating the screen_pdf_file function to accept a filename instead of base64 encoded content.
Highlights
- Quickstart Example Update: The quickstart example has been updated to use more generic and safe content for both user prompts and model responses, replacing potentially harmful examples with placeholders like "Unsafe user prompt" and "Unsanitized model output."
- Screen PDF File Refactor: The
screen_pdf_file
function now accepts a PDF filename instead of base64 encoded content. This change simplifies the function's usage and improves readability by handling the base64 encoding within the function. - Snippets Tests Update: The snippets tests have been updated to reflect the changes in the examples, including removing potentially harmful test cases and updating assertions to match the new generic content. Also, a fixture for
pdf_content_base64
was removed.
Changelog
Click here to see the changelog
- model_armor/snippets/quickstart.py
- Updated user prompt example to "Unsafe user prompt".
- Updated model response example to "Unsanitized model output".
- model_armor/snippets/screen_pdf_file.py
- Refactored the
screen_pdf_file
function to accept a filename instead of base64 encoded content. - Added base64 encoding of the PDF file within the function.
- Added import statement for the
base64
module.
- Refactored the
- model_armor/snippets/snippets_test.py
- Removed
RAI_FILTER_PROMPT_TEST_CASES
,RAI_FILTER_RESPONSE_TEST_CASES
, andRAI_TEST_CASE_IDS
. - Removed the
pdf_content_base64
fixture. - Updated
test_sanitize_user_prompt_with_malicious_url_template
to remove the potentially harmful phrase. - Updated
test_sanitize_user_prompt_with_csam_template
to use a safe user prompt and assertNO_MATCH_FOUND
. - Updated
test_sanitize_user_prompt_with_jail_break_template
to use a safer user prompt. - Removed
test_sanitize_user_prompt_with_rai_filters
. - Updated
test_sanitize_user_prompt_with_empty_template
to remove the potentially harmful phrase. - Updated
test_sanitize_model_response_with_malicious_url_template
to use a safer model response. - Updated
test_sanitize_model_response_with_csam_template
to use a safe model response and assertNO_MATCH_FOUND
. - Removed
test_sanitize_model_response_with_rai_filters
. - Updated
test_screen_pdf_file
to use a filename and assertNO_MATCH_FOUND
. - Corrected a typo in
test_sanitize_model_response_with_user_prompt_with_empty_template
.
- Removed
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 file's content,
From base64 set free,
Filename's new path.
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 aims to refactor the model_armor snippets, focusing on improving the examples and tests. The changes include updating user prompts and model responses to be more generic, modifying the screen_pdf_file function to accept a filename instead of base64 encoded content, and removing some test cases. Overall, the changes seem reasonable, but there are a few areas that could be improved.
Summary of Findings
- Test case updates: Several test cases have been updated with less specific or potentially non-offensive prompts and responses. While this reduces the risk of triggering filters during testing, it may also reduce the effectiveness of the tests. It's important to ensure that the tests still adequately cover the intended functionality.
- PDF screening: The screen_pdf_file function has been modified to accept a filename instead of base64 encoded content. This simplifies the function's interface and makes it easier to use. However, it also introduces a dependency on the local filesystem. Consider adding a comment to indicate that the file must be accessible to the process.
- Test case removal: The RAI_FILTER_PROMPT_TEST_CASES and RAI_FILTER_RESPONSE_TEST_CASES have been removed. This reduces the test coverage for RAI filters. It's important to ensure that the remaining tests adequately cover the functionality of these filters.
Merge Readiness
The pull request introduces some useful refactoring, but also removes some test cases and makes some test cases less specific. I would recommend addressing these before merging. I am unable to directly approve the pull request, and that users should have others review and approve this code before merging.
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.
needs to be fixed so that linting passes but otherwise looks good. thanks.
Description