Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 48a8fc5

Browse filesBrowse files
feat(modelarmor): created samples for model armor (GoogleCloudPlatform#13187)
* Added code snippets for Model Armor * Fixed `bluderbuss` syntax * Removed test data textfile * Fixed test data lint formatting * Updated organization floor settings test cases configurations * Remove org/folder test cases (due to permission issue). Refactored basic CRUD test cases. * Enabled org floor settings update with new org id * minor refactoring * Added refined cases for screening test cases * Enabled Folder floor settings test cases * Removed the unnecessary skip tests * Updated test case ordering and coverage for sanitization test cases
1 parent f2cf4eb commit 48a8fc5
Copy full SHA for 48a8fc5
Expand file treeCollapse file tree

36 files changed

+3399
-319
lines changed

‎.github/CODEOWNERS

Copy file name to clipboardExpand all lines: .github/CODEOWNERS
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@
2525
/generative_ai/**/* @GoogleCloudPlatform/generative-ai-devrel @GoogleCloudPlatform/python-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
2626
/iam/cloud-client/**/* @GoogleCloudPlatform/dee-infra @GoogleCloudPlatform/python-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
2727
/kms/**/** @GoogleCloudPlatform/dee-infra @GoogleCloudPlatform/python-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
28+
/model_armor/**/* @GoogleCloudPlatform/dee-infra @GoogleCloudPlatform/python-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers @GoogleCloudPlatform/cloud-modelarmor-team
2829
/media_cdn/**/* @GoogleCloudPlatform/dee-infra @GoogleCloudPlatform/python-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
29-
/model_garden/**/* @GoogleCloudPlatform/generative-ai-devrel @GoogleCloudPlatform/python-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
30+
/model_garden/**/* @GoogleCloudPlatform/generative-ai-devrel @GoogleCloudPlatform/python-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
3031
/parametermanager/**/* @GoogleCloudPlatform/dee-infra @GoogleCloudPlatform/python-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers @GoogleCloudPlatform/cloud-secrets-team @GoogleCloudPlatform/cloud-parameters-team
3132
/privateca/**/* @GoogleCloudPlatform/dee-infra @GoogleCloudPlatform/python-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
3233
/recaptcha_enterprise/**/* @GoogleCloudPlatform/dee-infra @GoogleCloudPlatform/recaptcha-customer-obsession-reviewers @GoogleCloudPlatform/python-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers

‎.github/blunderbuss.yml

Copy file name to clipboardExpand all lines: .github/blunderbuss.yml
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ assign_issues_by:
2323
- "api: cloudkms"
2424
- "api: iam"
2525
- "api: kms"
26+
- "api: modelarmor"
2627
- "api: parametermanager"
2728
- "api: privateca"
2829
- "api: recaptchaenterprise"
@@ -157,6 +158,7 @@ assign_prs_by:
157158
- "api: cloudkms"
158159
- "api: iam"
159160
- "api: kms"
161+
- "api: modelarmor"
160162
- "api: parametermanager"
161163
- "api: privateca"
162164
- "api: recaptchaenterprise"

‎model_armor/README.md

Copy file name to clipboard
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Sample Snippets for Model Armor API
2+
3+
## Quick Start
4+
5+
In order to run these samples, you first need to go through the following steps:
6+
7+
1. [Select or create a Cloud Platform project.](https://console.cloud.google.com/project)
8+
2. [Enable billing for your project.](https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project)
9+
3. [Enable the Model Armor API.](https://cloud.google.com/security-command-center/docs/get-started-model-armor#enable-model-armor)
10+
4. [Setup Authentication.](https://googleapis.dev/python/google-api-core/latest/auth.html)

‎model_armor/create_template.py

Copy file name to clipboardExpand all lines: model_armor/create_template.py
-68Lines changed: 0 additions & 68 deletions
This file was deleted.

‎model_armor/requirements.txt

Copy file name to clipboardExpand all lines: model_armor/requirements.txt
-1Lines changed: 0 additions & 1 deletion
This file was deleted.

‎model_armor/sanitize_user_prompt.py

Copy file name to clipboardExpand all lines: model_armor/sanitize_user_prompt.py
-61Lines changed: 0 additions & 61 deletions
This file was deleted.
+84Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
"""
15+
Sample code for creating a new model armor template.
16+
"""
17+
18+
from google.cloud import modelarmor_v1
19+
20+
21+
def create_model_armor_template(
22+
project_id: str,
23+
location: str,
24+
template_id: str,
25+
) -> modelarmor_v1.Template:
26+
"""Create a new Model Armor template.
27+
28+
Args:
29+
project_id (str): Google Cloud project ID.
30+
location (str): Google Cloud location.
31+
template_id (str): ID for the template to create.
32+
33+
Returns:
34+
Template: The created template.
35+
"""
36+
# [START modelarmor_create_template]
37+
38+
from google.api_core.client_options import ClientOptions
39+
from google.cloud import modelarmor_v1
40+
41+
# TODO(Developer): Uncomment these variables.
42+
# project_id = "your-google-cloud-project-id"
43+
# location = "us-central1"
44+
# template_id = "template_id"
45+
46+
# Create the Model Armor client.
47+
client = modelarmor_v1.ModelArmorClient(
48+
transport="rest",
49+
client_options=ClientOptions(
50+
api_endpoint=f"modelarmor.{location}.rep.googleapis.com"
51+
),
52+
)
53+
54+
# Build the Model Armor template with your preferred filters.
55+
# For more details on filters, please refer to the following doc:
56+
# https://cloud.google.com/security-command-center/docs/key-concepts-model-armor#ma-filters
57+
template = modelarmor_v1.Template(
58+
filter_config=modelarmor_v1.FilterConfig(
59+
pi_and_jailbreak_filter_settings=modelarmor_v1.PiAndJailbreakFilterSettings(
60+
filter_enforcement=modelarmor_v1.PiAndJailbreakFilterSettings.PiAndJailbreakFilterEnforcement.ENABLED,
61+
confidence_level=modelarmor_v1.DetectionConfidenceLevel.MEDIUM_AND_ABOVE,
62+
),
63+
malicious_uri_filter_settings=modelarmor_v1.MaliciousUriFilterSettings(
64+
filter_enforcement=modelarmor_v1.MaliciousUriFilterSettings.MaliciousUriFilterEnforcement.ENABLED,
65+
),
66+
),
67+
)
68+
69+
# Prepare the request for creating the template.
70+
request = modelarmor_v1.CreateTemplateRequest(
71+
parent=f"projects/{project_id}/locations/{location}",
72+
template_id=template_id,
73+
template=template,
74+
)
75+
76+
# Create the template.
77+
response = client.create_template(request=request)
78+
79+
# Print the new template name.
80+
print(f"Created template: {response.name}")
81+
82+
# [END modelarmor_create_template]
83+
84+
return response

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.