pub struct ModelFetcher { /* private fields */ }Expand description
Fetches a model’s files by revision and verifies them.
The licence gate runs before any request: a use-restricted model needs a person’s
recorded acceptance, and a non-commercial or copyleft one a policy that names it. A
401 or 403 from the hub is a gated repository and becomes
VisionError::LicenceAcceptanceRequired naming the repository page.
§Example
use std::sync::Arc;
use adk_vision::{FetchConfig, InMemoryAcceptanceStore, ManifestSet, ModelFetcher};
let fetcher = ModelFetcher::new(FetchConfig::from_env(), Arc::new(InMemoryAcceptanceStore::new()));
let model = fetcher.fetch(manifests.get("rf-detr-n-q4f16").unwrap()).await?;
for file in model.files() {
println!("{} {}", file.path().display(), file.digest());
}Implementations§
Source§impl ModelFetcher
impl ModelFetcher
Sourcepub fn new(config: FetchConfig, acceptances: Arc<dyn AcceptanceStore>) -> Self
pub fn new(config: FetchConfig, acceptances: Arc<dyn AcceptanceStore>) -> Self
A fetcher with a configuration and a licence acceptance store.
Sourcepub fn with_policy(self, policy: LicencePolicy) -> Self
pub fn with_policy(self, policy: LicencePolicy) -> Self
Allows the non-commercial and copyleft models the policy names.
Sourcepub fn config(&self) -> &FetchConfig
pub fn config(&self) -> &FetchConfig
The configuration.
Sourcepub async fn fetch(&self, manifest: &ModelManifest) -> Result<VerifiedModel>
pub async fn fetch(&self, manifest: &ModelManifest) -> Result<VerifiedModel>
Sourcepub fn fetch_blocking(&self, manifest: &ModelManifest) -> Result<VerifiedModel>
pub fn fetch_blocking(&self, manifest: &ModelManifest) -> Result<VerifiedModel>
Fetches every file of manifest that is not cached and verifies every file.
§Errors
The licence gate’s refusal before any request; VisionError::Offline for a file
missing from the cache in offline mode; VisionError::LicenceAcceptanceRequired
for a 401 or 403; VisionError::Fetch for other download failures;
VisionError::DigestMismatch or VisionError::SizeMismatch for a file that does
not match; VisionError::Unsupported for ModelScope and URL sources, which arrive
with the backends that need them.
Trait Implementations§
Source§impl Clone for ModelFetcher
impl Clone for ModelFetcher
Auto Trait Implementations§
impl !RefUnwindSafe for ModelFetcher
impl !UnwindSafe for ModelFetcher
impl Forget for ModelFetcher
impl Freeze for ModelFetcherwhere
*const u8 is !null: Freeze,
PhantomData<u8>: Freeze,
*const LeafNode<String, SetValZST> is !null: Freeze,
PhantomData<(Owned, LeafOrInternal)>: Freeze,
PhantomData<Box<(String, SetValZST)>>: Freeze,
*const ArcInner<dyn AcceptanceStore> is !null: Freeze,
PhantomData<ArcInner<dyn AcceptanceStore>>: Freeze,
impl Move for ModelFetcher
impl Send for ModelFetcher
impl Sync for ModelFetcher
impl Unpin for ModelFetcher
impl UnsafeUnpin for ModelFetcherwhere
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
*const LeafNode<String, SetValZST> is !null: UnsafeUnpin,
PhantomData<(Owned, LeafOrInternal)>: UnsafeUnpin,
PhantomData<Box<(String, SetValZST)>>: UnsafeUnpin,
*const ArcInner<dyn AcceptanceStore> is !null: UnsafeUnpin,
PhantomData<ArcInner<dyn AcceptanceStore>>: UnsafeUnpin,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for T
impl<T> Downcast for T
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
impl<T> MaybeSend for Twhere
T: Send,
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.