Skip to main content

Class: Client<SessionType>

Type Parameters

Type ParameterDefault type

SessionType extends Session

HttpSession

Constructors

new Client()

new Client<SessionType>(config: SessionType["config"], session?: SessionType): Client<SessionType>

Parameters

ParameterType

config

SessionType["config"]

session?

SessionType

Returns

Client<SessionType>

Properties

session

session: SessionType;

Methods

buildContext()

buildContext(): Promise<Context>

Get a new and well initialized context for this deployment.

Returns

Promise<Context>

A promise that resolves to a new context


getWorkflow()

getWorkflow(): Promise<Workflow>

Return deployment's workflow.

Returns

Promise<Workflow>

A promise that resolves to the workflow


run()

run(params: XOR<{
context: Context;
}, {
parameters: Record<string, string | number | boolean>;
taskName: string;
}, {
parameters: Record<string, string | number | boolean>;
taskId: number;
}> & XOR<{
image: ImageType | ImageIO | undefined;
}, {
images: ImageType | ImageIO[];
}, {
input: TaskIO<string, any>;
}, {
inputs: Results | TaskIO<string, any>[];
}> & {
onProgress: OnProgressCallback;
}): Promise<Results>

Run the deployment with the given parameters.

Parameters

ParameterTypeDescription

params

XOR<{ context: Context; }, { parameters: Record<string, string | number | boolean>; taskName: string; }, { parameters: Record<string, string | number | boolean>; taskId: number; }> & XOR<{ image: ImageType | ImageIO | undefined; }, { images: ImageType | ImageIO[]; }, { input: TaskIO<string, any>; }, { inputs: Results | TaskIO<string, any>[]; }> & { onProgress: OnProgressCallback; }

Parameters for the deployment. You can provide an image or an array of images as inputs and optionally a context or a taskName/taskId with parameters.

Returns

Promise<Results>

A promise that resolves to the results of the deployment

Example

// Run a deployment with a single image input
await client.run({
image: 'https://example.com/image.jpg',
});

// Run a deployment with multiple images inputs
await client.run({
images: ['https://example.com/image1.jpg', 'https://example.com/image2.jpg'],
});

// Run a deployment with a context
const context = await client.buildContext();
context.setOutput('custom_output_task_name', 1);
context.setParameters('custom_task_name', {param1: 'value1', param2: 42});

await client.run({context, image: 'https://example.com/image.jpg'});

runStream()

runStream(params: undefined | XOR<{ context?: Context | undefined; }, { taskName?: string | undefined; parameters?: Record<string, string | number | boolean> | undefined; }, { taskId?: number | undefined; parameters?: Record<...> | undefined; }> & XOR<...> & { ...; }): AsyncGenerator<SessionState, void, unknown>

Same as run, but returns an async generator that yields the state of the session at each polling iteration.

Parameters

ParameterTypeDescription

params

undefined | XOR<{ context?: Context | undefined; }, { taskName?: string | undefined; parameters?: Record<string, string | number | boolean> | undefined; }, { taskId?: number | undefined; parameters?: Record<...> | undefined; }> & XOR<...> & { ...; }

Parameters for the deployment. You can provide an image or an array of images as inputs and optionally a context or a taskName/taskId with parameters.

Returns

AsyncGenerator<SessionState, void, unknown>

Yields

The state of the session at each polling iteration