Scan all known locations for models and return a list of discovered models.
()
| 68 | |
| 69 | /// Scan all known locations for models and return a list of discovered models. |
| 70 | pub fn list_models() -> Result<Vec<LocalModel>> { |
| 71 | let mut models = Vec::new(); |
| 72 | |
| 73 | // 1. Scan HuggingFace cache |
| 74 | if let Some(hf_cache) = hf_cache_dir() { |
| 75 | scan_hf_cache(&hf_cache, &mut models)?; |
| 76 | } |
| 77 | |
| 78 | // 2. Scan zero-config cluster cache |
| 79 | if let Some(cake_cache) = cake_cache_dir() { |
| 80 | scan_cake_cache(&cake_cache, &mut models)?; |
| 81 | } |
| 82 | |
| 83 | // Sort: complete first, then by name |
| 84 | models.sort_by(|a, b| { |
| 85 | let status_ord = |s: &ModelStatus| match s { |
| 86 | ModelStatus::Complete => 0, |
| 87 | ModelStatus::Partial { .. } => 1, |
| 88 | }; |
| 89 | status_ord(&a.status) |
| 90 | .cmp(&status_ord(&b.status)) |
| 91 | .then_with(|| a.name.cmp(&b.name)) |
| 92 | }); |
| 93 | |
| 94 | Ok(models) |
| 95 | } |
| 96 | |
| 97 | /// Find a model by name. Supports exact match (`org/model`) or suffix match (`model`). |
| 98 | /// Returns `Err` if the suffix match is ambiguous (multiple models match). |