Skip to content

Commit 11bba78

Browse files
committed
Add config param to workflow predict method
1 parent 0eea838 commit 11bba78

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/Workflow.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import {formatObjectForSnakeCase} from "./utils";
2+
13
let axios = require('axios');
24
let {API, replaceVars} = require('./constants');
35
let {WORKFLOWS_PATH, WORKFLOW_PATH, WORKFLOW_RESULTS_PATH} = API;
@@ -74,8 +76,11 @@ class Workflow {
7476
* @param {object[]|object|string} inputs An array of objects/object/string pointing to an image resource. A string can either be a url or base64 image bytes. Object keys explained below:
7577
* @param {object} inputs[].image Object with keys explained below:
7678
* @param {string} inputs[].image.(url|base64) Can be a publicly accessibly url or base64 string representing image bytes (required)
79+
* @param {object} config An object with keys explained below.
80+
* @param {float} config.minValue The minimum confidence threshold that a result must meet. From 0.0 to 1.0
81+
* @param {number} config.maxConcepts The maximum number of concepts to return
7782
*/
78-
predict(workflowId, inputs) {
83+
predict(workflowId, inputs, config = {}) {
7984
const url = `${this._config.basePath}${replaceVars(WORKFLOW_RESULTS_PATH, [workflowId])}`;
8085
if (checkType(/(Object|String)/, inputs)) {
8186
inputs = [inputs];
@@ -84,6 +89,9 @@ class Workflow {
8489
const params = {
8590
inputs: inputs.map(formatInput)
8691
};
92+
if (config && Object.getOwnPropertyNames(config).length > 0) {
93+
params['output_config'] = formatObjectForSnakeCase(config);
94+
}
8795
return new Promise((resolve, reject) => {
8896
axios.post(url, params, {
8997
headers

tests/unit/workflows-unit-tests.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,11 @@ describe('Unit Tests - Workflows', () => {
393393
`));
394394

395395

396-
app.workflow.predict("@workflowID", ["https://some-image-url1", "https://some-image-url2"])
397-
.then(response => {
396+
app.workflow.predict(
397+
"@workflowID",
398+
["https://some-image-url1", "https://some-image-url2"],
399+
{minValue: 0.98, maxConcepts: 3}
400+
).then(response => {
398401
expect(mock.history.post.length).toBe(1);
399402
expect(JSON.parse(mock.history.post[0].data)).toEqual(JSON.parse(`
400403
{
@@ -415,7 +418,11 @@ describe('Unit Tests - Workflows', () => {
415418
}
416419
}
417420
}
418-
]
421+
],
422+
"output_config": {
423+
"max_concepts": 3,
424+
"min_value": 0.98
425+
}
419426
}
420427
`));
421428

0 commit comments

Comments
 (0)