Try to read a model name from config.json (e.g. _name_or_path field).
(dir: &Path)
| 324 | |
| 325 | /// Try to read a model name from config.json (e.g. _name_or_path field). |
| 326 | fn read_model_name_from_config(dir: &Path) -> Option<String> { |
| 327 | let config = std::fs::read_to_string(dir.join("config.json")).ok()?; |
| 328 | let json: serde_json::Value = serde_json::from_str(&config).ok()?; |
| 329 | |
| 330 | // Try common fields that identify the model |
| 331 | json.get("_name_or_path") |
| 332 | .and_then(|v| v.as_str()) |
| 333 | .map(|s| s.to_string()) |
| 334 | .or_else(|| { |
| 335 | json.get("model_type") |
| 336 | .and_then(|v| v.as_str()) |
| 337 | .map(|s| s.to_string()) |
| 338 | }) |
| 339 | } |
| 340 | |
| 341 | #[cfg(test)] |
| 342 | mod tests { |