Skip to content

chore(modelarmor): refactored sanitization test cases and snippets args inconsistencies #13314

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

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions model_armor/snippets/create_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@

def create_model_armor_template(
project_id: str,
location: str,
location_id: str,
template_id: str,
) -> modelarmor_v1.Template:
"""Create a new Model Armor template.

Args:
project_id (str): Google Cloud project ID.
location (str): Google Cloud location.
location_id (str): Google Cloud location.
template_id (str): ID for the template to create.

Returns:
Expand All @@ -40,14 +40,14 @@ def create_model_armor_template(

# TODO(Developer): Uncomment these variables.
# project_id = "your-google-cloud-project-id"
# location = "us-central1"
# location_id = "us-central1"
# template_id = "template_id"

# Create the Model Armor client.
client = modelarmor_v1.ModelArmorClient(
transport="rest",
client_options=ClientOptions(
api_endpoint=f"modelarmor.{location}.rep.googleapis.com"
api_endpoint=f"modelarmor.{location_id}.rep.googleapis.com"
),
)

Expand All @@ -68,7 +68,7 @@ def create_model_armor_template(

# Prepare the request for creating the template.
request = modelarmor_v1.CreateTemplateRequest(
parent=f"projects/{project_id}/locations/{location}",
parent=f"projects/{project_id}/locations/{location_id}",
template_id=template_id,
template=template,
)
Expand Down
8 changes: 4 additions & 4 deletions model_armor/snippets/create_template_with_advanced_sdp.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ def create_model_armor_template_with_advanced_sdp(
returned as SdpFinding in SdpInsepctionResult e.g.
`organizations/{organization}/inspectTemplates/{inspect_template}`,
`projects/{project}/inspectTemplates/{inspect_template}`
`organizations/{organization}/locations/{location}/inspectTemplates/{inspect_template}`
`projects/{project}/locations/{location}/inspectTemplates/{inspect_template}`
`organizations/{organization}/locations/{location_id}/inspectTemplates/{inspect_template}`
`projects/{project}/locations/{location_id}/inspectTemplates/{inspect_template}`
deidentify_template (str):
Optional. Optional Sensitive Data Protection Deidentify
template resource name.
Expand All @@ -56,8 +56,8 @@ def create_model_armor_template_with_advanced_sdp(
e.g.
`organizations/{organization}/deidentifyTemplates/{deidentify_template}`,
`projects/{project}/deidentifyTemplates/{deidentify_template}`
`organizations/{organization}/locations/{location}/deidentifyTemplates/{deidentify_template}`
`projects/{project}/locations/{location}/deidentifyTemplates/{deidentify_template}`
`organizations/{organization}/locations/{location_id}/deidentifyTemplates/{deidentify_template}`
`projects/{project}/locations/{location_id}/deidentifyTemplates/{deidentify_template}`
Example:
# Create template with advance SDP configuration
create_model_armor_template_with_advanced_sdp(
Expand Down
3 changes: 2 additions & 1 deletion model_armor/snippets/create_template_with_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ def create_model_armor_template_with_metadata(
# For more details on template metadata, please refer to the following doc:
# https://cloud.google.com/security-command-center/docs/reference/model-armor/rest/v1/projects.locations.templates#templatemetadata
template_metadata=modelarmor_v1.Template.TemplateMetadata(
ignore_partial_invocation_failures=True, log_sanitize_operations=True
log_sanitize_operations=True,
log_template_operations=True,
),
)

Expand Down
10 changes: 5 additions & 5 deletions model_armor/snippets/delete_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@

def delete_model_armor_template(
project_id: str,
location: str,
location_id: str,
template_id: str,
) -> None:
"""Delete a model armor template.

Args:
project_id (str): Google Cloud project ID.
location (str): Google Cloud location.
location_id (str): Google Cloud location.
template_id (str): ID for the template to be deleted.
"""
# [START modelarmor_delete_template]
Expand All @@ -35,20 +35,20 @@ def delete_model_armor_template(

# TODO(Developer): Uncomment these variables.
# project_id = "YOUR_PROJECT_ID"
# location = "us-central1"
# location_id = "us-central1"
# template_id = "template_id"

# Create the Model Armor client.
client = modelarmor_v1.ModelArmorClient(
transport="rest",
client_options=ClientOptions(
api_endpoint=f"modelarmor.{location}.rep.googleapis.com"
api_endpoint=f"modelarmor.{location_id}.rep.googleapis.com"
),
)

# Build the request for deleting the template.
request = modelarmor_v1.DeleteTemplateRequest(
name=f"projects/{project_id}/locations/{location}/templates/{template_id}",
name=f"projects/{project_id}/locations/{location_id}/templates/{template_id}",
)

# Delete the template.
Expand Down
8 changes: 4 additions & 4 deletions model_armor/snippets/get_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

def get_model_armor_template(
project_id: str,
location: str,
location_id: str,
template_id: str,
) -> modelarmor_v1.Template:
"""Get model armor template.
Expand All @@ -40,20 +40,20 @@ def get_model_armor_template(

# TODO(Developer): Uncomment these variables.
# project_id = "YOUR_PROJECT_ID"
# location = "us-central1"
# location_id = "us-central1"
# template_id = "template_id"

# Create the Model Armor client.
client = modelarmor_v1.ModelArmorClient(
transport="rest",
client_options=ClientOptions(
api_endpoint=f"modelarmor.{location}.rep.googleapis.com"
api_endpoint=f"modelarmor.{location_id}.rep.googleapis.com"
),
)

# Initialize request arguments.
request = modelarmor_v1.GetTemplateRequest(
name=f"projects/{project_id}/locations/{location}/templates/{template_id}",
name=f"projects/{project_id}/locations/{location_id}/templates/{template_id}",
)

# Get the template.
Expand Down
8 changes: 4 additions & 4 deletions model_armor/snippets/list_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

def list_model_armor_templates(
project_id: str,
location: str,
location_id: str,
) -> pagers.ListTemplatesPager:
"""List model armor templates.

Expand All @@ -37,19 +37,19 @@ def list_model_armor_templates(

# TODO(Developer): Uncomment these variables.
# project_id = "YOUR_PROJECT_ID"
# location = "us-central1"
# location_id = "us-central1"

# Create the Model Armor client.
client = modelarmor_v1.ModelArmorClient(
transport="rest",
client_options=ClientOptions(
api_endpoint=f"modelarmor.{location}.rep.googleapis.com"
api_endpoint=f"modelarmor.{location_id}.rep.googleapis.com"
),
)

# Initialize request argument(s).
request = modelarmor_v1.ListTemplatesRequest(
parent=f"projects/{project_id}/locations/{location}"
parent=f"projects/{project_id}/locations/{location_id}"
)

# Get list of templates.
Expand Down
2 changes: 1 addition & 1 deletion model_armor/snippets/list_templates_with_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def list_model_armor_templates_with_filter(
Args:
project_id (str): Google Cloud project ID.
location_id (str): Google Cloud location.
template_id (str): Model Armour Template ID(s) to filter from list.
template_id (str): Model Armor Template ID(s) to filter from list.

Returns:
List[str]: A list of template names.
Expand Down
4 changes: 2 additions & 2 deletions model_armor/snippets/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
google-cloud-modelarmor==0.1.1
google-cloud-dlp==3.27.0
google-cloud-modelarmor==0.2.5
google-cloud-dlp==3.30.0
2 changes: 1 addition & 1 deletion model_armor/snippets/sanitize_user_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def sanitize_user_prompt(

# TODO(Developer): Uncomment these variables.
# project_id = "YOUR_PROJECT_ID"
# location = "us-central1"
# location_id = "us-central1"
# template_id = "template_id"
# user_prompt = "Prompt entered by the user"

Expand Down
Loading