A class for creating a workflow using a fluent API.

Example

 const workflow = new Workflow();
const {
KSampler,
CheckpointLoaderSimple,
EmptyLatentImage,
CLIPTextEncode,
VAEDecode,
SaveImage,
NODE1,
} = workflow.classes;

const seed = Math.floor(Math.random() * 2 ** 32);
const pos = "best quality, 1girl";
const neg = "worst quality, bad anatomy, embedding:NG_DeepNegative_V1_75T";
const model1_name = "lofi_v5.baked.fp16.safetensors";
const model2_name = "case-h-beta.baked.fp16.safetensors";
const sampler_settings = {
seed,
steps: 35,
cfg: 4,
sampler_name: "dpmpp_2m_sde_gpu",
scheduler: "karras",
denoise: 1,
};

const [model1, clip1, vae1] = CheckpointLoaderSimple({
ckpt_name: model1_name,
});
const [model2, clip2, vae2] = CheckpointLoaderSimple({
ckpt_name: model2_name,
});

const dress_case = [
"white yoga",
"black office",
"pink sportswear",
"cosplay",
];

const generate_pipeline = (model, clip, vae, pos, neg) => {
const [latent_image] = EmptyLatentImage({
width: 640,
height: 960,
batch_size: 1,
});
const [positive] = CLIPTextEncode({ text: pos, clip });
const [negative] = CLIPTextEncode({ text: neg, clip });
const [samples] = KSampler({
...sampler_settings,
model,
positive,
negative,
latent_image,
});
const [image] = VAEDecode({ samples, vae });
return image;
};

for (const cloth of dress_case) {
const input_pos = `${pos}, ${cloth} dress`;
const image = generate_pipeline(model1, clip1, vae1, input_pos, neg);
SaveImage({
images: image,
filename_prefix: `${cloth}-lofi-v5`,
});

const input_pos2 = `${pos}, ${cloth} dress`;
const image2 = generate_pipeline(model2, clip2, vae2, input_pos2, neg);
SaveImage({
images: image2,
filename_prefix: `${cloth}-case-h-beta`,
});
}

return workflow;

Constructors

Properties

_last_node_id: number = 0
_workflow: IWorkflow = ...
classes: BuiltinNodeClasses & Record<string, ComfyUINodeClass<NodeClassInputs>> = ...

Methods

  • Creates a new invoked workflow instance.

    Type Parameters

    • T

    Parameters

    • client: Client

      The client used to run the prompt.

    • Optional options: InvokeOptions<T>

      Optional invoke options.

    Returns InvokedWorkflow<T>

    The invoked workflow instance.

  • Parameters

    Returns InvokedWorkflow<unknown>

  • Type Parameters

    • T extends string | number | symbol | string & {}
    • C extends any

    Parameters

    • node_name: T
    • inputs: C extends {
              inputs: INP;
          }
          ? INP
          : Record<string, unknown>

    Returns Iterable<NodeOutput>

  • Resets the workflow by clearing the prompt and setting the workflow to undefined.

    Returns void