Skip to main content

Advanced Usage

Running a specific task

If you want to run the workflow to retrieve the output of another task, you can use Client.runTask():

const results = await client.runTask('infer_yolo_v8', {
inputs: [
'https://raw.githubusercontent.com/Ikomia-dev/notebooks/main/examples/img/img_work.jpg',
],
});

Advanced configuration and output selection

If you need to select outputs from various tasks or set parameters for intermediate tasks, you can use a Context object for maximum flexibility:

const context = await client.buildContext();

A context holds specific configuration for your deployment, which you can reuse across multiple runs.

Using context.addOutput(), you can select specific outputs from any task in your workflow:

// Add ALL outputs from the "ocv_blur" task
context.addOutput('ocv_blur');

// Add output 1 from "infer_yolo_v8"
context.addOutput('infer_yolo_v8', {index: 1});

// Add ALL outputs from the "infer_yolo_v8_seg" task
// Save them to project's storage (will be returned as StorageObjectIO)
context.addOutput('infer_yolo_v8_seg', {saveTemporary: true});

You can also use context.setParameters() to edit configuration of any task:

context.setParameters('infer_yolo_v8', {conf_thres: 0.5});

To run using a context, you can pass it to the Client.runOn() method:

const results = await client.runOn(context, {
inputs: [
'https://raw.githubusercontent.com/Ikomia-dev/notebooks/main/examples/img/img_work.jpg',
],
});

Chaining deployments

You can chain multiple deployments together by passing the outputs of one deployment as inputs to another:

const client1 = new Client({url: 'https://your.scale.endpoint.url'});
const client2 = new Client({url: 'https://your.other.scale.endpoint.url'});

const results1 = await client1.run({
inputs: [
'https://raw.githubusercontent.com/Ikomia-dev/notebooks/main/examples/img/img_work.jpg',
],
});
const results2 = await client2.run({inputs: [results1]});

You can also forward selected outputs using results.getOutput():

const results1 = await client1.run({
inputs: [
'https://raw.githubusercontent.com/Ikomia-dev/notebooks/main/examples/img/img_work.jpg',
],
});
const results2 = await client2.run({
inputs: [results1.getOutput(1), results1.getOutput(2)],
});