* Quickstart example for using Google Cloud Model Armor to * create a template with RAI filters and sanitize content. * * @param {string} projectId - Google Cloud project ID. * @param {string} locationId - Google Cloud location. * @param {string} templateId - ID for the template to create.
( projectId = 'my-project', locationId = 'us-central1', templateId = 'my-template' )
| 23 | * @param {string} templateId - ID for the template to create. |
| 24 | */ |
| 25 | async function quickstart( |
| 26 | projectId = 'my-project', |
| 27 | locationId = 'us-central1', |
| 28 | templateId = 'my-template' |
| 29 | ) { |
| 30 | // [START modelarmor_quickstart] |
| 31 | /** |
| 32 | * TODO(developer): Uncomment these variables before running the sample. |
| 33 | */ |
| 34 | // const projectId = 'my-project'; |
| 35 | // const locationId = 'us-central1'; |
| 36 | // const templateId = 'my-template'; |
| 37 | |
| 38 | // Imports the Model Armor library |
| 39 | const modelarmor = require('@google-cloud/modelarmor'); |
| 40 | const {ModelArmorClient} = modelarmor.v1; |
| 41 | const {protos} = modelarmor; |
| 42 | |
| 43 | const {RaiFilterType} = protos.google.cloud.modelarmor.v1; |
| 44 | const {DetectionConfidenceLevel} = protos.google.cloud.modelarmor.v1; |
| 45 | |
| 46 | // Instantiates a client |
| 47 | const client = new ModelArmorClient({ |
| 48 | apiEndpoint: `modelarmor.${locationId}.rep.googleapis.com`, |
| 49 | }); |
| 50 | |
| 51 | const parent = `projects/${projectId}/locations/${locationId}`; |
| 52 | |
| 53 | // Build the Model Armor template with preferred filters |
| 54 | // For more details on filters, refer to: |
| 55 | // https://cloud.google.com/security-command-center/docs/key-concepts-model-armor#ma-filters |
| 56 | const template = { |
| 57 | filterConfig: { |
| 58 | raiSettings: { |
| 59 | raiFilters: [ |
| 60 | { |
| 61 | filterType: RaiFilterType.DANGEROUS, |
| 62 | confidenceLevel: DetectionConfidenceLevel.HIGH, |
| 63 | }, |
| 64 | { |
| 65 | filterType: RaiFilterType.HARASSMENT, |
| 66 | confidenceLevel: DetectionConfidenceLevel.MEDIUM_AND_ABOVE, |
| 67 | }, |
| 68 | { |
| 69 | filterType: RaiFilterType.HATE_SPEECH, |
| 70 | confidenceLevel: DetectionConfidenceLevel.HIGH, |
| 71 | }, |
| 72 | { |
| 73 | filterType: RaiFilterType.SEXUALLY_EXPLICIT, |
| 74 | confidenceLevel: DetectionConfidenceLevel.HIGH, |
| 75 | }, |
| 76 | ], |
| 77 | }, |
| 78 | }, |
| 79 | }; |
| 80 | |
| 81 | const [createdTemplate] = await client.createTemplate({ |
| 82 | parent, |