Skip to content

Commit cbb9a94

Browse files
author
rudrakhsha-crest
committed
Updated prompts, tests and log statements for sanitization APIs
1 parent 072b4aa commit cbb9a94

File tree

7 files changed

+275
-193
lines changed

7 files changed

+275
-193
lines changed

model-armor/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"test": "c8 mocha -p -j 2 --recursive test/ --timeout=60000"
1515
},
1616
"dependencies": {
17-
"@google-cloud/modelarmor": "^0.1.0"
17+
"@google-cloud/modelarmor": "^0.1.0",
18+
"@google-cloud/dlp": "^5.0.0"
1819
},
1920
"devDependencies": {
2021
"c8": "^10.0.0",

model-armor/snippets/sanitizeModelResponse.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ async function main(projectId, locationId, templateId, modelResponse) {
3838
};
3939

4040
const [response] = await client.sanitizeModelResponse(request);
41-
console.log('Sanitized model response:', response);
41+
console.log(JSON.stringify(response, null, 2));
4242
}
4343

4444
sanitizeModelResponse();

model-armor/snippets/sanitizeModelResponseWithUserPrompt.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ async function main(
4646
};
4747

4848
const [response] = await client.sanitizeModelResponse(request);
49-
console.log('Sanitized model response with user prompt:', response);
49+
console.log(JSON.stringify(response, null, 2));
5050
}
5151

5252
sanitizeModelResponseWithUserPrompt();

model-armor/snippets/sanitizeUserPrompt.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ async function main(projectId, locationId, templateId, userPrompt) {
3838
};
3939

4040
const [response] = await client.sanitizeUserPrompt(request);
41-
console.log('Sanitized user prompt:', response);
41+
console.log(JSON.stringify(response, null, 2));
4242
}
4343

4444
sanitizeUserPrompt();

model-armor/snippets/screenPdfFile.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,22 @@
1515
'use strict';
1616

1717
/**
18-
* Sanitize/Screen PDF content using the Model Armor API.
18+
* Sanitize/Screen PDF file content using the Model Armor API.
1919
*
2020
* @param {string} projectId - Google Cloud project ID.
2121
* @param {string} locationId - Google Cloud location.
2222
* @param {string} templateId - The template ID used for sanitization.
23-
* @param {string} pdfContentBase64 - Base64-encoded PDF content to sanitize.
23+
* @param {string} pdfContentFilename - Path to a PDF file.
2424
*/
25-
async function main(projectId, locationId, templateId, pdfContentBase64) {
25+
async function main(projectId, locationId, templateId, pdfContentFilename) {
2626
// [START modelarmor_screen_pdf_file]
2727
/**
2828
* TODO(developer): Uncomment these variables before running the sample.
2929
*/
3030
// const projectId = process.env.PROJECT_ID || 'your-project-id';
3131
// const locationId = process.env.LOCATION_ID || 'us-central1';
3232
// const templateId = process.env.TEMPLATE_ID || 'template-id';
33-
// const pdfContentBase64 = process.env.PDF_CONTENT_BASE64 || 'BASE64_ENCODED_PDF_CONTENT';
33+
// const pdfContentFilename = 'path/to/file.pdf';
3434

3535
// Imports the Model Armor library
3636
const modelarmor = require('@google-cloud/modelarmor');
@@ -39,7 +39,11 @@ async function main(projectId, locationId, templateId, pdfContentBase64) {
3939
const ByteItemType =
4040
protos.google.cloud.modelarmor.v1.ByteDataItem.ByteItemType;
4141

42-
// Instantiates a client
42+
const fs = require('fs');
43+
44+
const pdfContent = fs.readFileSync(pdfContentFilename);
45+
const pdfContentBase64 = pdfContent.toString('base64');
46+
4347
const client = new ModelArmorClient({
4448
apiEndpoint: `modelarmor.${locationId}.rep.googleapis.com`,
4549
});
@@ -55,7 +59,7 @@ async function main(projectId, locationId, templateId, pdfContentBase64) {
5559
};
5660

5761
const [response] = await client.sanitizeUserPrompt(request);
58-
console.log('PDF Sanitization Result:', response);
62+
console.log(JSON.stringify(response, null, 2));
5963
// [END modelarmor_screen_pdf_file]
6064
}
6165

0 commit comments

Comments
 (0)