async function pipeline(
    task,
    model = null,
    {
        progress_callback = null,
        config = null,
        cache_dir = null,
        local_files_only = false,
        revision = 'main',
        device = null,
        dtype = null,
        subfolder = 'onnx',
        use_external_data_format = null,
        model_file_name = null,
        session_options = {},
    } = {}
) {
    // Helper method to construct pipeline

    // Apply aliases
    // @ts-ignore
    task = TASK_ALIASES[task] ?? task;

    // Get pipeline info
    const pipelineInfo = SUPPORTED_TASKS[task.split('_', 1)[0]];
    if (!pipelineInfo) {
        throw Error(`Unsupported pipeline: ${task}. Must be one of [${Object.keys(SUPPORTED_TASKS)}]`)
    }

    // Use model if specified, otherwise, use default
    if (!model) {
        model = pipelineInfo.default.model
        console.log(`No model specified. Using default model: "${model}".`);
    }

    const pretrainedOptions = {
        progress_callback,
        config,
        cache_dir,
        local_files_only,
        revision,
        device,
        dtype,
        subfolder,
        use_external_data_format,
        model_file_name,
        session_options,
    }

    const classes = new Map([
        ['tokenizer', pipelineInfo.tokenizer],
        ['model', pipelineInfo.model],
        ['processor', pipelineInfo.processor],
    ]);

    // Load model, tokenizer, and processor (if they exist)
    const results = await loadItems(classes, model, pretrainedOptions);
    results.task = task;

    dispatchCallback(progress_callback, {
        'status': 'ready',
        'task': task,
        'model': model,
    });

    const pipelineClass = pipelineInfo.pipeline;
    return new pipelineClass(results);
}
Utility factory method to build a `Pipeline` object.

@template {PipelineType} T The type of pipeline to return.
@param {T} task The task defining which pipeline will be returned. Currently accepted tasks are:
 - `"audio-classification"`: will return a `AudioClassificationPipeline`.
 - `"automatic-speech-recognition"`: will return a `AutomaticSpeechRecognitionPipeline`.
 - `"depth-estimation"`: will return a `DepthEstimationPipeline`.
 - `"document-question-answering"`: will return a `DocumentQuestionAnsweringPipeline`.
 - `"feature-extraction"`: will return a `FeatureExtractionPipeline`.
 - `"fill-mask"`: will return a `FillMaskPipeline`.
 - `"image-classification"`: will return a `ImageClassificationPipeline`.
 - `"image-segmentation"`: will return a `ImageSegmentationPipeline`.
 - `"image-to-text"`: will return a `ImageToTextPipeline`.
 - `"object-detection"`: will return a `ObjectDetectionPipeline`.
 - `"question-answering"`: will return a `QuestionAnsweringPipeline`.
 - `"summarization"`: will return a `SummarizationPipeline`.
 - `"text2text-generation"`: will return a `Text2TextGenerationPipeline`.
 - `"text-classification"` (alias "sentiment-analysis" available): will return a `TextClassificationPipeline`.
 - `"text-generation"`: will return a `TextGenerationPipeline`.
 - `"token-classification"` (alias "ner" available): will return a `TokenClassificationPipeline`.
 - `"translation"`: will return a `TranslationPipeline`.
 - `"translation_xx_to_yy"`: will return a `TranslationPipeline`.
 - `"zero-shot-classification"`: will return a `ZeroShotClassificationPipeline`.
 - `"zero-shot-audio-classification"`: will return a `ZeroShotAudioClassificationPipeline`.
 - `"zero-shot-image-classification"`: will return a `ZeroShotImageClassificationPipeline`.
 - `"zero-shot-object-detection"`: will return a `ZeroShotObjectDetectionPipeline`.
@param {string} [model=null] The name of the pre-trained model to use. If not specified, the default model for the task will be used.
@param {import('./utils/hub.js').PretrainedModelOptions} [options] Optional parameters for the pipeline.
@returns {Promise<AllTasks[T]>} A Pipeline object for the specified task.
@throws {Error} If an unsupported pipeline is requested.