Table of Contents

Interface IOnnxModelDownloader

Namespace
AiDotNet.Interfaces
Assembly
AiDotNet.dll

Defines the contract for downloading ONNX models from remote sources.

public interface IOnnxModelDownloader

Remarks

This interface provides a way to download ONNX models from repositories like HuggingFace Hub or ONNX Model Zoo. It supports progress reporting and caching of downloaded models.

For Beginners: Instead of manually downloading model files, you can use implementers of this interface to automatically fetch models:

var downloader = new OnnxModelDownloader();
var modelPath = await downloader.DownloadAsync("openai/whisper-base");
var model = new OnnxModel<float>(modelPath);

Methods

ClearCache(string?)

Clears the local cache for a specific model or all models.

void ClearCache(string? modelId = null)

Parameters

modelId string

Optional model identifier. If null, clears all cached models.

DownloadAsync(string, string?, IProgress<double>?, CancellationToken)

Downloads an ONNX model from a remote repository.

Task<string> DownloadAsync(string modelId, string? fileName = null, IProgress<double>? progress = null, CancellationToken cancellationToken = default)

Parameters

modelId string

The model identifier (e.g., "openai/whisper-base").

fileName string

Optional specific file name within the model repository.

progress IProgress<double>

Optional progress reporter (0.0 to 1.0).

cancellationToken CancellationToken

Cancellation token.

Returns

Task<string>

The local file path to the downloaded model.

DownloadMultipleAsync(string, IEnumerable<string>, IProgress<double>?, CancellationToken)

Downloads multiple ONNX files from a model repository.

Task<IReadOnlyDictionary<string, string>> DownloadMultipleAsync(string modelId, IEnumerable<string> fileNames, IProgress<double>? progress = null, CancellationToken cancellationToken = default)

Parameters

modelId string

The model identifier.

fileNames IEnumerable<string>

The file names to download.

progress IProgress<double>

Optional progress reporter (0.0 to 1.0).

cancellationToken CancellationToken

Cancellation token.

Returns

Task<IReadOnlyDictionary<string, string>>

Dictionary mapping file names to local paths.

GetCacheSize()

Gets the total size of the local cache in bytes.

long GetCacheSize()

Returns

long

GetCachedPath(string, string?)

Checks if a model is already cached locally.

string? GetCachedPath(string modelId, string? fileName = null)

Parameters

modelId string

The model identifier.

fileName string

Optional specific file name.

Returns

string

The local path if cached, null otherwise.