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
modelIdstringOptional 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
modelIdstringThe model identifier (e.g., "openai/whisper-base").
fileNamestringOptional specific file name within the model repository.
progressIProgress<double>Optional progress reporter (0.0 to 1.0).
cancellationTokenCancellationTokenCancellation token.
Returns
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
modelIdstringThe model identifier.
fileNamesIEnumerable<string>The file names to download.
progressIProgress<double>Optional progress reporter (0.0 to 1.0).
cancellationTokenCancellationTokenCancellation 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
GetCachedPath(string, string?)
Checks if a model is already cached locally.
string? GetCachedPath(string modelId, string? fileName = null)
Parameters
Returns
- string
The local path if cached, null otherwise.