Skip to main content

Reference

Enum Reference 

Source
pub enum Reference {
    Ollama {
        namespace: String,
        name: String,
        tag: String,
    },
    HuggingFace {
        owner: String,
        repo: String,
        revision: String,
        quant: Option<String>,
    },
    Local {
        path: String,
    },
    Url {
        url: String,
        sha256: Option<String>,
    },
}
Expand description

Where a model comes from, once we have understood the reference.

Variants§

§

Ollama

Fields

§namespace: String

library for the curated catalog, a username otherwise.

§name: String
§

HuggingFace

Fields

§owner: String
§repo: String
§revision: String

Git revision. main unless asked otherwise.

§quant: Option<String>

Which quantization, if the caller pinned one. When absent we choose, and say which one we chose.

§

Local

A GGUF already on disk. No catalog, no download, no opinions.

Fields

§path: String
§

Url

A direct download. Neither registry: no manifest, no repo listing, no published digest — just a URL that is supposed to be a GGUF.

Fields

§sha256: Option<String>

Pinned via a #sha256:HEX fragment. None means hearth will hash the file itself after downloading and trust that — self-consistent, not registry-verified, and hearth why says which.

Implementations§

Source§

impl Reference

Source

pub fn parse(input: &str) -> Result<Reference, ParseError>

Read a reference the way a person typed it.

Examples found in repository?
examples/against_reality.rs (line 17)
12fn main() {
13    // ---- real registry.ollama.ai manifest for library/llama3:latest -------
14    let manifest: serde_json::Value =
15        serde_json::from_str(&std::fs::read_to_string("/tmp/ollama_manifest.json").unwrap())
16            .unwrap();
17    let r = Reference::parse("llama3").unwrap();
18    let (ns, nm) = match &r {
19        Reference::Ollama {
20            namespace, name, ..
21        } => (namespace.clone(), name.clone()),
22        _ => unreachable!(),
23    };
24    let p = plan_from_ollama_manifest(
25        &manifest,
26        "https://registry.ollama.ai",
27        &ns,
28        &nm,
29        r.key(),
30        r.display_name(),
31    )
32    .unwrap();
33    println!("OLLAMA  {}", p.display_name);
34    println!("  key      {}", p.key);
35    println!("  blobs    {} (filtered from 4 layers)", p.blobs.len());
36    println!("  size     {:.2} GiB", gib(p.total_bytes().unwrap()));
37    println!("  digest   {}", p.blobs[0].digest.as_deref().unwrap());
38    println!("  url      {}", p.blobs[0].url);
39
40    // ---- real huggingface listing ----------------------------------------
41    let hf: serde_json::Value =
42        serde_json::from_str(&std::fs::read_to_string("/tmp/hf.json").unwrap()).unwrap();
43    let files: Vec<RepoFile> = hf["siblings"]
44        .as_array()
45        .unwrap()
46        .iter()
47        .map(|s| RepoFile {
48            path: s["rfilename"].as_str().unwrap().to_string(),
49            size_bytes: s.get("size").and_then(|v| v.as_u64()),
50        })
51        .filter(|f| f.path.ends_with(".gguf"))
52        .collect();
53    println!("\nHUGGINGFACE  {} gguf files in the repo", files.len());
54
55    let hr = Reference::parse("hf:TheBloke/Llama-2-7B-GGUF").unwrap();
56    let (picked, quant, chose) = pick_gguf(&files, None).unwrap();
57    let plan = plan_from_hf_files(
58        HfSource {
59            owner: "TheBloke",
60            repo: "Llama-2-7B-GGUF",
61            revision: "main",
62        },
63        picked,
64        QuantChoice {
65            quant: quant.clone(),
66            chosen_for_you: chose,
67        },
68        hr.key(),
69        hr.display_name(),
70    );
71    println!(
72        "  auto     {} ({:.2} GiB){}",
73        quant,
74        gib(plan.total_bytes().unwrap()),
75        if chose { "  <- we chose this" } else { "" }
76    );
77    println!("  url      {}", plan.blobs[0].url);
78
79    let (pinned, q2, chose2) = pick_gguf(&files, Some("Q8_0")).unwrap();
80    println!(
81        "  pinned   {} ({:.2} GiB){}",
82        q2,
83        gib(pinned.iter().filter_map(|f| f.size_bytes).sum::<u64>()),
84        if chose2 {
85            "  <- we chose"
86        } else {
87            "  <- caller chose"
88        }
89    );
90
91    match pick_gguf(&files, Some("Q9_MEGA")) {
92        Ok(_) => println!("  BAD: accepted a quant that does not exist"),
93        Err(e) => println!("  bogus quant -> {}", &e.0[..e.0.len().min(96)]),
94    }
95}
Source

pub fn key(&self) -> String

A stable identity for this model on disk and in the event log.

Two references that mean the same model must produce the same key, or the same weights get downloaded twice and the residency history splits in half.

Examples found in repository?
examples/against_reality.rs (line 29)
12fn main() {
13    // ---- real registry.ollama.ai manifest for library/llama3:latest -------
14    let manifest: serde_json::Value =
15        serde_json::from_str(&std::fs::read_to_string("/tmp/ollama_manifest.json").unwrap())
16            .unwrap();
17    let r = Reference::parse("llama3").unwrap();
18    let (ns, nm) = match &r {
19        Reference::Ollama {
20            namespace, name, ..
21        } => (namespace.clone(), name.clone()),
22        _ => unreachable!(),
23    };
24    let p = plan_from_ollama_manifest(
25        &manifest,
26        "https://registry.ollama.ai",
27        &ns,
28        &nm,
29        r.key(),
30        r.display_name(),
31    )
32    .unwrap();
33    println!("OLLAMA  {}", p.display_name);
34    println!("  key      {}", p.key);
35    println!("  blobs    {} (filtered from 4 layers)", p.blobs.len());
36    println!("  size     {:.2} GiB", gib(p.total_bytes().unwrap()));
37    println!("  digest   {}", p.blobs[0].digest.as_deref().unwrap());
38    println!("  url      {}", p.blobs[0].url);
39
40    // ---- real huggingface listing ----------------------------------------
41    let hf: serde_json::Value =
42        serde_json::from_str(&std::fs::read_to_string("/tmp/hf.json").unwrap()).unwrap();
43    let files: Vec<RepoFile> = hf["siblings"]
44        .as_array()
45        .unwrap()
46        .iter()
47        .map(|s| RepoFile {
48            path: s["rfilename"].as_str().unwrap().to_string(),
49            size_bytes: s.get("size").and_then(|v| v.as_u64()),
50        })
51        .filter(|f| f.path.ends_with(".gguf"))
52        .collect();
53    println!("\nHUGGINGFACE  {} gguf files in the repo", files.len());
54
55    let hr = Reference::parse("hf:TheBloke/Llama-2-7B-GGUF").unwrap();
56    let (picked, quant, chose) = pick_gguf(&files, None).unwrap();
57    let plan = plan_from_hf_files(
58        HfSource {
59            owner: "TheBloke",
60            repo: "Llama-2-7B-GGUF",
61            revision: "main",
62        },
63        picked,
64        QuantChoice {
65            quant: quant.clone(),
66            chosen_for_you: chose,
67        },
68        hr.key(),
69        hr.display_name(),
70    );
71    println!(
72        "  auto     {} ({:.2} GiB){}",
73        quant,
74        gib(plan.total_bytes().unwrap()),
75        if chose { "  <- we chose this" } else { "" }
76    );
77    println!("  url      {}", plan.blobs[0].url);
78
79    let (pinned, q2, chose2) = pick_gguf(&files, Some("Q8_0")).unwrap();
80    println!(
81        "  pinned   {} ({:.2} GiB){}",
82        q2,
83        gib(pinned.iter().filter_map(|f| f.size_bytes).sum::<u64>()),
84        if chose2 {
85            "  <- we chose"
86        } else {
87            "  <- caller chose"
88        }
89    );
90
91    match pick_gguf(&files, Some("Q9_MEGA")) {
92        Ok(_) => println!("  BAD: accepted a quant that does not exist"),
93        Err(e) => println!("  bogus quant -> {}", &e.0[..e.0.len().min(96)]),
94    }
95}
Source

pub fn display_name(&self) -> String

What to call it in a report, a route, or an API response.

Examples found in repository?
examples/against_reality.rs (line 30)
12fn main() {
13    // ---- real registry.ollama.ai manifest for library/llama3:latest -------
14    let manifest: serde_json::Value =
15        serde_json::from_str(&std::fs::read_to_string("/tmp/ollama_manifest.json").unwrap())
16            .unwrap();
17    let r = Reference::parse("llama3").unwrap();
18    let (ns, nm) = match &r {
19        Reference::Ollama {
20            namespace, name, ..
21        } => (namespace.clone(), name.clone()),
22        _ => unreachable!(),
23    };
24    let p = plan_from_ollama_manifest(
25        &manifest,
26        "https://registry.ollama.ai",
27        &ns,
28        &nm,
29        r.key(),
30        r.display_name(),
31    )
32    .unwrap();
33    println!("OLLAMA  {}", p.display_name);
34    println!("  key      {}", p.key);
35    println!("  blobs    {} (filtered from 4 layers)", p.blobs.len());
36    println!("  size     {:.2} GiB", gib(p.total_bytes().unwrap()));
37    println!("  digest   {}", p.blobs[0].digest.as_deref().unwrap());
38    println!("  url      {}", p.blobs[0].url);
39
40    // ---- real huggingface listing ----------------------------------------
41    let hf: serde_json::Value =
42        serde_json::from_str(&std::fs::read_to_string("/tmp/hf.json").unwrap()).unwrap();
43    let files: Vec<RepoFile> = hf["siblings"]
44        .as_array()
45        .unwrap()
46        .iter()
47        .map(|s| RepoFile {
48            path: s["rfilename"].as_str().unwrap().to_string(),
49            size_bytes: s.get("size").and_then(|v| v.as_u64()),
50        })
51        .filter(|f| f.path.ends_with(".gguf"))
52        .collect();
53    println!("\nHUGGINGFACE  {} gguf files in the repo", files.len());
54
55    let hr = Reference::parse("hf:TheBloke/Llama-2-7B-GGUF").unwrap();
56    let (picked, quant, chose) = pick_gguf(&files, None).unwrap();
57    let plan = plan_from_hf_files(
58        HfSource {
59            owner: "TheBloke",
60            repo: "Llama-2-7B-GGUF",
61            revision: "main",
62        },
63        picked,
64        QuantChoice {
65            quant: quant.clone(),
66            chosen_for_you: chose,
67        },
68        hr.key(),
69        hr.display_name(),
70    );
71    println!(
72        "  auto     {} ({:.2} GiB){}",
73        quant,
74        gib(plan.total_bytes().unwrap()),
75        if chose { "  <- we chose this" } else { "" }
76    );
77    println!("  url      {}", plan.blobs[0].url);
78
79    let (pinned, q2, chose2) = pick_gguf(&files, Some("Q8_0")).unwrap();
80    println!(
81        "  pinned   {} ({:.2} GiB){}",
82        q2,
83        gib(pinned.iter().filter_map(|f| f.size_bytes).sum::<u64>()),
84        if chose2 {
85            "  <- we chose"
86        } else {
87            "  <- caller chose"
88        }
89    );
90
91    match pick_gguf(&files, Some("Q9_MEGA")) {
92        Ok(_) => println!("  BAD: accepted a quant that does not exist"),
93        Err(e) => println!("  bogus quant -> {}", &e.0[..e.0.len().min(96)]),
94    }
95}
Source

pub fn needs_download(&self) -> bool

Trait Implementations§

Source§

impl Clone for Reference

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Reference

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Reference

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for Reference

Source§

impl PartialEq for Reference

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Reference

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Reference

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.