MCPcopy Create free account
hub / github.com/evilsocket/cake / read_model_name_from_config

Function read_model_name_from_config

cake-core/src/utils/models.rs:326–339  ·  view source on GitHub ↗

Try to read a model name from config.json (e.g. _name_or_path field).

(dir: &Path)

Source from the content-addressed store, hash-verified

324
325/// Try to read a model name from config.json (e.g. _name_or_path field).
326fn 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)]
342mod tests {

Calls 1

getMethod · 0.45