Skip to content

Commit 09623e8

Browse files
authored
Add moderation solution
* Add moderation solution * Fix missing semicolon
1 parent 12f0ac4 commit 09623e8

File tree

3 files changed

+68
-1
lines changed

3 files changed

+68
-1
lines changed

src/App.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ let Inputs = require('./Inputs');
55
let Concepts = require('./Concepts');
66
let Workflow = require('./Workflow');
77
let Workflows = require('./Workflows');
8+
let Solutions = require('./solutions/Solutions');
89
let {API, ERRORS, getBasePath} = require('./constants');
910
let {TOKEN_PATH} = API;
1011

@@ -106,6 +107,7 @@ class App {
106107
this.concepts = new Concepts(this._config);
107108
this.workflow = new Workflow(this._config);
108109
this.workflows = new Workflows(this._config);
110+
this.solutions = new Solutions(this._config);
109111
}
110112

111113
_getToken(resolve, reject) {
@@ -136,6 +138,5 @@ class App {
136138
});
137139
}
138140
}
139-
;
140141

141142
module.exports = App;

src/solutions/Moderation.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
let axios = require('axios');
2+
let {wrapToken} = require('../utils');
3+
let {isSuccess, clone} = require('../helpers');
4+
5+
let BASE_URL = 'https://api.clarifai-moderation.com';
6+
7+
class Moderation {
8+
9+
constructor(_config) {
10+
this._config = _config;
11+
12+
}
13+
14+
predict(modelID, imageURL) {
15+
return wrapToken(this._config, (headers) => {
16+
let url = `${BASE_URL}/v2/models/${modelID}/outputs`;
17+
let params = {
18+
inputs: [
19+
{
20+
data: {
21+
image: {
22+
url: imageURL
23+
}
24+
}
25+
}
26+
]
27+
};
28+
29+
return new Promise((resolve, reject) => {
30+
return axios.post(url, params, {headers}).then((response) => {
31+
if (isSuccess(response)) {
32+
let data = clone(response.data);
33+
resolve(data);
34+
} else {
35+
reject(response);
36+
}
37+
}, reject);
38+
});
39+
});
40+
}
41+
42+
getModerationStatus(imageID) {
43+
return wrapToken(this._config, (headers) => {
44+
let url = `${BASE_URL}/v2/inputs/${imageID}/outputs`;
45+
return new Promise((resolve, reject) => {
46+
return axios.get(url, {headers}).then((response) => {
47+
let data = clone(response.data);
48+
resolve(data);
49+
}, reject);
50+
51+
});
52+
});
53+
}
54+
}
55+
56+
module.exports = Moderation;

src/solutions/Solutions.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
let Moderation = require('./Moderation');
2+
3+
class Solutions {
4+
5+
constructor(_config) {
6+
this.moderation = new Moderation(_config);
7+
}
8+
}
9+
10+
module.exports = Solutions;

0 commit comments

Comments
 (0)