-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbatching.js
88 lines (82 loc) · 2.12 KB
/
batching.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
80
81
82
83
84
85
86
87
88
/**
* Example script to illustrate how to make requests to the Private AI API
* to deidentify text using the batching 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_batching() {
console.log("***** Sync batching *****");
axios.post(
`${process.env.PAI_URL}/v3/process/text`,
{
text: [
"Hi, my name is Penelope, could you tell me your phone number please?",
"Sure, x234",
"and your DOB please?",
"fourth of Feb nineteen 86",
],
link_batch: true,
entity_detection: {
return_entity: true,
},
processed_text: {
type: "MARKER",
pattern: "[UNIQUE_NUMBERED_ENTITY_TYPE]",
},
},
{
headers: {
"Content-Type": "application/json",
"X-API-KEY": process.env.API_KEY,
},
}
)
.then((result) => console.log(JSON.stringify(result.data, undefined, 2)))
.catch((error) =>
console.error(
`The request failed with the status code ${error.response.status}`
)
);
}
// Example with async/await
async function async_batching() {
console.log("***** Async batching *****");
try {
const result = await axios.post(
`${process.env.PAI_URL}/v3/process/text`,
{
text: [
"Hi, my name is Penelope, could you tell me your phone number please?",
"Sure, x234",
"and your DOB please?",
"fourth of Feb nineteen 86",
],
link_batch: true,
entity_detection: {
return_entity: true,
},
processed_text: {
type: "MARKER",
pattern: "[UNIQUE_NUMBERED_ENTITY_TYPE]",
},
},
{
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_batching();
async_batching();