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+ def create_model_armor_template (project_id : str , location : str , template_id : str ):
16+ # [START modelarmor_create_template]
17+
18+ from google .cloud import modelarmor_v1
19+ client = modelarmor_v1 .ModelArmorClient (transport = "rest" , client_options = {
20+ "api_endpoint" : "modelarmor.us-central1.rep.googleapis.com" })
21+
22+ # TODO(Developer): Uncomment these variables and initialize
23+ # project_id = "your-google-cloud-project-id"
24+ # location = "us-central1"
25+ # template_id = "template_id"
26+
27+ template = {
28+ "name" : f"projects/{ project_id } /locations/{ location } /templates/{ template_id } " ,
29+ "filter_config" : {
30+ "rai_settings" : {
31+ "rai_filters" : [
32+ {
33+ "filter_type" : "HATE_SPEECH" ,
34+ "confidence_level" : "LOW_AND_ABOVE"
35+ }
36+ ]
37+ },
38+ "pi_and_jailbreak_filter_settings" : {
39+ "filter_enforcement" : "ENABLED"
40+ },
41+ "malicious_uri_filter_settings" : {
42+ "filter_enforcement" : "ENABLED"
43+ }
44+ },
45+ "template_metadata" : {
46+ "log_template_operations" : False ,
47+ "log_sanitize_operations" : False
48+ }
49+ }
50+
51+ # Initialize request arguments
52+ request = modelarmor_v1 .CreateTemplateRequest (
53+ parent = f"projects/{ project_id } /locations/{ location } " ,
54+ template_id = template_id ,
55+ template = template
56+ )
57+
58+ # Make the request
59+ response = client .create_template (request = request )
60+
61+ # Response
62+ return response
63+ # [END modelarmor_create_template]
0 commit comments