autoagents_llamacpp/
models.rs1use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
7pub enum ModelSource {
8 Gguf {
10 model_path: String,
12 },
13 HuggingFace {
15 repo_id: String,
17 filename: Option<String>,
19 mmproj_filename: Option<String>,
21 },
22}
23
24impl ModelSource {
25 pub fn gguf(model_path: impl Into<String>) -> Self {
27 Self::Gguf {
28 model_path: model_path.into(),
29 }
30 }
31
32 pub fn huggingface(repo_id: impl Into<String>) -> Self {
34 Self::HuggingFace {
35 repo_id: repo_id.into(),
36 filename: None,
37 mmproj_filename: None,
38 }
39 }
40
41 pub fn huggingface_with_filename(
43 repo_id: impl Into<String>,
44 filename: impl Into<String>,
45 ) -> Self {
46 Self::HuggingFace {
47 repo_id: repo_id.into(),
48 filename: Some(filename.into()),
49 mmproj_filename: None,
50 }
51 }
52
53 pub fn huggingface_with_mmproj(
55 repo_id: impl Into<String>,
56 filename: impl Into<String>,
57 mmproj_filename: impl Into<String>,
58 ) -> Self {
59 Self::HuggingFace {
60 repo_id: repo_id.into(),
61 filename: Some(filename.into()),
62 mmproj_filename: Some(mmproj_filename.into()),
63 }
64 }
65
66 pub fn model_path(&self) -> Option<&str> {
68 match self {
69 ModelSource::Gguf { model_path } => Some(model_path),
70 ModelSource::HuggingFace { .. } => None,
71 }
72 }
73}
74
75#[cfg(test)]
76mod tests {
77 use super::*;
78
79 #[test]
80 fn test_model_source_path() {
81 let source = ModelSource::gguf("test.gguf");
82 assert_eq!(source.model_path(), Some("test.gguf"));
83 }
84
85 #[test]
86 fn test_model_source_hf() {
87 let source = ModelSource::huggingface("org/model");
88 assert!(source.model_path().is_none());
89 assert_eq!(
90 source,
91 ModelSource::HuggingFace {
92 repo_id: "org/model".to_string(),
93 filename: None,
94 mmproj_filename: None,
95 }
96 );
97 }
98}