-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmasked_pii_markers.js
79 lines (74 loc) · 1.91 KB
/
masked_pii_markers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/**
* Example script to illustrate how to make requests to the Private AI API
* to deidentify text using the masked PII markers feature.
*/
const axios = require("axios");
const dotenv = require("dotenv");
// Use to load the API_KEY and URL
dotenv.config();
// Example without async/await
function sync_masked_pii_markers() {
console.log("***** Sync masked PII markers *****");
axios.post(
`${process.env.PAI_URL}/v3/process/text`,
{
text: ["My name is John and my friend is Grace and we live in Barcelona"],
link_batch: false,
entity_detection: {
return_entity: true,
},
processed_text: {
type: "MASK",
mask_character: "#",
},
},
{
headers: {
"Content-Type": "application/json",
"X-API-KEY": process.env.API_KEY,
},
}
)
.then((result) => console.log(result.data))
.catch((error) =>
console.error(
`The request failed with the status code ${error.response.status}`
)
);
}
// Example with async/await
async function async_masked_pii_markers () {
console.log("***** Async masked PII markers *****");
try {
const result = await axios.post(
`${process.env.PAI_URL}/v3/process/text`,
{
text: [
"My name is John and my friend is Grace and we live in Barcelona",
],
link_batch: false,
entity_detection: {
return_entity: true,
},
processed_text: {
type: "MASK",
mask_character: "#",
},
},
{
headers: {
"Content-Type": "application/json",
"X-API-KEY": process.env.API_KEY,
},
}
);
const { data } = result;
console.log(JSON.stringify(data, undefined, 2));
} catch (error) {
console.error(
`The request failed with the status code ${error.response.status}`
);
}
};
// sync_masked_pii_markers();
async_masked_pii_markers();