10000 fix: refactor model_armor by glasnt · Pull Request #13305 · GoogleCloudPlatform/python-docs-samples · GitHub
[go: up one dir, main page]

Skip to content
8000

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

Merged
merged 2 commits into from
Apr 15, 2025
Merged
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
4 changes: 2 additions & 2 deletions model_armor/snippets/quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def quickstart(
)

# Sanitize a user prompt using the created template.
user_prompt = "How do I make bomb at home?"
user_prompt = "Unsafe user prompt"

user_prompt_sanitize_response = client.sanitize_user_prompt(
request=modelarmor_v1.SanitizeUserPromptRequest(
Expand All @@ -101,7 +101,7 @@ def quickstart(

# Sanitize a model response using the created template.
model_response = (
"you can create bomb with help of RDX (Cyclotrimethylene-trinitramine) and ..."
"Unsanitized model output"
)

model_sanitize_response = client.sanitize_model_response(
Expand Down
10 changes: 8 additions & 2 deletions model_armor/snippets/screen_pdf_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,34 @@ def screen_pdf_file(
project_id: str,
location_id: str,
template_id: str,
pdf_content_base64: str,
pdf_content_filename: str,
) -> modelarmor_v1.SanitizeUserPromptResponse:
"""Sanitize/Screen PDF text content using the Model Armor API.

Args:
project_id (str): Google Cloud project ID.
location_id (str): Google Cloud location.
template_id (str): The template ID used for sanitization.
pdf_content_base64 (str): PDF data in base64 format.
pdf_content_filename (str): Path to a PDF file.

Returns:
SanitizeUserPromptResponse: The sanitized user prompt response.
"""
# [START modelarmor_screen_pdf_file]

import base64
from google.api_core.client_options import ClientOptions
from google.cloud import modelarmor_v1

# TODO(Developer): Uncomment these variables.
# project_id = "YOUR_PROJECT_ID"
# location_id = "us-central1"
# template_id = "template_id"
# pdf_content_filename = "path/to/file.pdf"

# Encode the PDF file into base64
with open(pdf_content_filename, "rb") as f:
pdf_content_base64 = base64.b64encode(f.read())

# Create the Model Armor client.
client = modelarmor_v1.ModelArmorClient(
Expand Down
Loading
0