-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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): created samples for model armor #13187
base: main
Are you sure you want to change the base?
feat(modelarmor): created samples for model armor #13187
Conversation
Here is the summary of changes. You are about to add 24 region tags.
You are about to delete 6 region tags.
This comment is generated by snippet-bot.
|
f5102cb
to
1e3606c
Compare
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 from the "tests pass and follows styleguide" standpoint. Team added to repo, so CODEOWNERS is now valid.
However, this needs subject matter expert approval (from @GoogleCloudPlatform/cloud-modelarmor-team who I have manually assigned to this PR, since this PR adds the automation that would assign them automatically)
Do not merge until subject matter approval has been done.
assert template_id in str(templates) | ||
|
||
|
||
def test_user_prompt( |
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.
This looks like a generic use case of testing user prompt. We should add 1 test case per each filter i.e. a case where malicious_uri is filtered, a case where some pi_jb attempt is filtered, etc.
Suggestion -
There should be 2 templates - empty_template with empty filter config (i.e. all filters disabled) and all_filters_template with all filters enabled. Then test for each filter against both templates -> assert that MATCH_FOUND = false for empty_template and MATCH_FOUND = true for all_filters_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.
Added test cases for screening test cases along with existing screening test cases.
- user prompt screening with empty filter template
- user prompt screening with all filter template
- test_sanitize_model_response_with_empty_template
- test_sanitize_model_response_with_user_prompt_with_empty_filters
Also added individual assertion if specific filter match is expected.
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 see that you have added cases where rai (dangerous) and malicious_uri filters result in MATCH_FOUND. What about rai (other sub filters - hate_pseech, sexually_explicit, harrasment) & pi_and_jailbreak cases? Please add those as well. Also add cases for csam
, this filter result is returned in every response irrespective of the template filter_config.
…sic CRUD test cases.
c07c32d
to
273d12d
Compare
) | ||
|
||
# Define the prompt. | ||
user_prompt = ( |
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.
This should also come an an input argument to the method.
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.
Same for sanitize_model_response as well.
assert template_id in str(templates) | ||
|
||
|
||
def test_user_prompt( |
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 see that you have added cases where rai (dangerous) and malicious_uri filters result in MATCH_FOUND. What about rai (other sub filters - hate_pseech, sexually_explicit, harrasment) & pi_and_jailbreak cases? Please add those as well. Also add cases for csam
, this filter result is returned in every response irrespective of the template filter_config.
Description
Added more Model Armor code samples for following use cases:
Quickstart
Create a template and sanitize user prompt and model response using it.
Floor Settings
Get Floor Settings of given Folder, Organization & Project
Update Floor Settings of given Folder, Organization & Project
Disable Floor Settings of given Folder, Organization & Project
Template CRUD
Create a template with labels
Create Template with template metadata
Create a template with Basic Sensitive Data Protection configuration
Create a template with Advanced Sensitive Data Protection configuration
List all available templates in given project and location
List all available templates with filter in given project and location
View template with given template_id
Update template configuration for given template_id
Update template with Mask Configuration
Update template metadata
Update labels of a template
Delete template with given template_id
User Prompt Sanitization
Sanitize the user prompt based on the given template configuration
Scan a PDF file based on the given template configuration
Model Response Sanitization
Sanitize the model response based on the given template configuration
Sanitize the model response along with user prompt
Checklist
nox -s py-3.9
(see Test Environment Setup)nox -s lint
(see Test Environment Setup)