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
HuggingFace
Fields
Local
A GGUF already on disk. No catalog, no download, no opinions.
Url
A direct download. Neither registry: no manifest, no repo listing, no published digest — just a URL that is supposed to be a GGUF.
Implementations§
Source§impl Reference
impl Reference
Sourcepub fn parse(input: &str) -> Result<Reference, ParseError>
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}Sourcepub fn key(&self) -> String
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}Sourcepub fn display_name(&self) -> String
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}pub fn needs_download(&self) -> bool
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Reference
impl<'de> Deserialize<'de> for Reference
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for Reference
impl StructuralPartialEq for Reference
Auto Trait Implementations§
impl Freeze for Reference
impl RefUnwindSafe for Reference
impl Send for Reference
impl Sync for Reference
impl Unpin for Reference
impl UnsafeUnpin for Reference
impl UnwindSafe for Reference
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