pub struct HuggingFaceStorage { /* private fields */ }Expand description
Storage backend for HuggingFace Hub models.
Downloads GGUF models from HuggingFace with progress tracking and checksum verification.
§Example
ⓘ
use spn_native::{HuggingFaceStorage, default_model_dir, DownloadRequest, find_model};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let storage = HuggingFaceStorage::new(default_model_dir());
let model = find_model("qwen3:8b").unwrap();
let request = DownloadRequest::curated(model);
let result = storage.download(&request, |p| {
println!("{}", p);
}).await?;
println!("Downloaded: {:?}", result.path);
Ok(())
}Implementations§
Source§impl HuggingFaceStorage
impl HuggingFaceStorage
Sourcepub fn new(storage_dir: PathBuf) -> Self
pub fn new(storage_dir: PathBuf) -> Self
Create a new HuggingFace storage with the given directory.
Sourcepub fn with_client(storage_dir: PathBuf, client: Client) -> Self
pub fn with_client(storage_dir: PathBuf, client: Client) -> Self
Create storage with a custom HTTP client.
Sourcepub async fn download<F>(
&self,
request: &DownloadRequest<'_>,
progress: F,
) -> Result<DownloadResult>
pub async fn download<F>( &self, request: &DownloadRequest<'_>, progress: F, ) -> Result<DownloadResult>
Download a model with progress callback.
§Arguments
request- Download request specifying model and quantizationprogress- Callback for download progress updates
§Errors
Returns error if:
- Model not found on HuggingFace
- Network error during download
- Checksum verification fails
- I/O error writing file
Trait Implementations§
Source§impl ModelStorage for HuggingFaceStorage
impl ModelStorage for HuggingFaceStorage
Source§fn list_models(&self) -> Result<Vec<ModelInfo>, BackendError>
fn list_models(&self) -> Result<Vec<ModelInfo>, BackendError>
List downloaded models. Read more
Source§fn model_info(&self, model_id: &str) -> Result<ModelInfo, BackendError>
fn model_info(&self, model_id: &str) -> Result<ModelInfo, BackendError>
Get model info for a specific model. Read more
Source§fn model_path(&self, model_id: &str) -> PathBuf
fn model_path(&self, model_id: &str) -> PathBuf
Get the local path for a model.
Source§fn storage_dir(&self) -> &Path
fn storage_dir(&self) -> &Path
Get the storage root directory.
Auto Trait Implementations§
impl Freeze for HuggingFaceStorage
impl !RefUnwindSafe for HuggingFaceStorage
impl Send for HuggingFaceStorage
impl Sync for HuggingFaceStorage
impl Unpin for HuggingFaceStorage
impl UnsafeUnpin for HuggingFaceStorage
impl !UnwindSafe for HuggingFaceStorage
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more