pub struct LocalModelRegistry { /* private fields */ }audio only.Expand description
Registry for managing local model downloads and caching.
Supports both MLX-format (.safetensors + config.json) and
ONNX-format (.onnx) models from HuggingFace Hub.
On first access the model is downloaded via the HuggingFace Hub API
(requires the onnx or mlx feature for the hf-hub dependency).
Subsequent calls return the cached path immediately.
§Example
let registry = LocalModelRegistry::default();
let path = registry.get_or_download("onnx-community/whisper-base").await?;Implementations§
Source§impl LocalModelRegistry
impl LocalModelRegistry
Sourcepub fn new(cache_dir: impl Into<PathBuf>) -> LocalModelRegistry
pub fn new(cache_dir: impl Into<PathBuf>) -> LocalModelRegistry
Create a registry with a custom cache directory.
Sourcepub async fn get_or_download(
&self,
model_id: &str,
) -> Result<PathBuf, AudioError>
pub async fn get_or_download( &self, model_id: &str, ) -> Result<PathBuf, AudioError>
Get the local path for a model, downloading from HuggingFace Hub if not cached.
The method first checks for a local cache directory at
<cache_dir>/<org>--<model>. If found, it returns immediately.
Otherwise it uses the hf-hub crate to download all repository
files into the HuggingFace cache and returns that path.
§Errors
Returns AudioError::ModelDownload if model_id is empty or
the download fails.
Sourcepub fn model_path(&self, model_id: &str) -> PathBuf
pub fn model_path(&self, model_id: &str) -> PathBuf
Compute the local path for a model ID (without downloading).