Auto-detect text model architecture from config.json's "architectures" field.
(config_path: &std::path::Path)
| 174 | |
| 175 | /// Auto-detect text model architecture from config.json's "architectures" field. |
| 176 | pub fn detect_text_model_arch(config_path: &std::path::Path) -> Result<String> { |
| 177 | let data = std::fs::read(config_path) |
| 178 | .map_err(|e| anyhow!("can't read {}: {:?}", config_path.display(), e))?; |
| 179 | let json: serde_json::Value = serde_json::from_slice(&data) |
| 180 | .map_err(|e| anyhow!("can't parse {}: {:?}", config_path.display(), e))?; |
| 181 | |
| 182 | if let Some(archs) = json.get("architectures").and_then(|v| v.as_array()) { |
| 183 | for arch in archs { |
| 184 | if let Some(s) = arch.as_str() { |
| 185 | return Ok(s.to_string()); |
| 186 | } |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | Ok(String::new()) |
| 191 | } |
| 192 | |
| 193 | #[cfg(test)] |
| 194 | mod tests { |