pub struct ModelCache { /* private fields */ }Expand description
A folder of downloaded model files, one <id>-<sha256>.gguf per row,
so a row with another digest never reuses a file. A file is used only
when its size and SHA-256 match, hashed once per process; fetch
checks the SHA-256 before a file gets its final name. No call
downloads alone.
Implementations§
Source§impl ModelCache
impl ModelCache
Sourcepub fn new(dir: impl Into<PathBuf>) -> Self
pub fn new(dir: impl Into<PathBuf>) -> Self
Uses dir as the model folder; it is created on the first fetch.
Mobile apps pass their own app folder here.
Output: the cache.
Sourcepub fn default_dir() -> Result<Self, LocalError>
pub fn default_dir() -> Result<Self, LocalError>
Picks the default folder: $TROUPEKIT_MODEL_DIR, else
$HOME/.cache/troupekit/models, else %LOCALAPPDATA%\troupekit\models.
Output: the cache, or Cache asking for ModelCache::new(dir).
Sourcepub fn path(&self, spec: &LocalSpec) -> Option<PathBuf>
pub fn path(&self, spec: &LocalSpec) -> Option<PathBuf>
Returns the file of a row when it is a regular file of exactly the
declared size whose SHA-256 matches the row. The first call in a
process hashes the file; later calls skip it while the file keeps
its identity (device, inode, size, mtime). A partial or other file
gives None. Never touches the network.
Sourcepub async fn fetch(
&self,
spec: &LocalSpec,
transport: &dyn Transport,
) -> Result<PathBuf, LocalError>
pub async fn fetch( &self, spec: &LocalSpec, transport: &dyn Transport, ) -> Result<PathBuf, LocalError>
Downloads a row through transport unless path already finds
it, following up to 5 redirects that stay on https: into a part file of its own (created exclusively, 0600), refused
past the declared size or on a hash mismatch, then renamed. Output: the path.
Trait Implementations§
Source§impl Clone for ModelCache
impl Clone for ModelCache
Source§impl Debug for ModelCache
impl Debug for ModelCache
impl Eq for ModelCache
Source§impl PartialEq for ModelCache
impl PartialEq for ModelCache
impl StructuralPartialEq for ModelCache
Auto Trait Implementations§
impl Forget for ModelCache
impl Freeze for ModelCache
impl Move for ModelCache
impl RefUnwindSafe for ModelCache
impl Send for ModelCachewhere
RawVecInner: Send,
impl Sync for ModelCachewhere
RawVecInner: Sync,
impl Unpin for ModelCache
impl UnsafeUnpin for ModelCache
impl UnwindSafe for ModelCachewhere
RawVecInner: UnwindSafe,
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.