Run: add auto-download when model is missing#52
Conversation
|
If you need this is exists in https://github.com/RamboRogers/mlx-gui |
| try writeModelMetadata(modelName: alias, modelDir: modelDir) | ||
| } | ||
|
|
||
| public static func ensureModelAvailable(modelName: String, silent: Bool = false) async throws -> String { |
There was a problem hiding this comment.
It seems like the silent parameter doesn’t add much value here. Even if it were implemented properly, it wouldn’t really make sense in this context because the function already resolves and downloads models with user-facing messages by design.
Maybe we should consider removing silent entirely to simplify the API.
| let modelExists = FileManager.default.fileExists(atPath: modelDir.path) | ||
|
|
||
| if !silent && resolved != modelName { | ||
| fputs("Info: Resolved model alias '\(modelName)' to '\(resolved)'\n", stdout) |
There was a problem hiding this comment.
I’m not sure if using fputs and fflush(stdout) at this layer is a good idea. This function is part of the model resolution and download logic, so printing directly to stdout tightly couples it to CLI-style usage.
Maybe we should move these log messages up to a higher layer (like a CLI handler) and keep this layer clean and side-effect free? That way, this API can also be reused in other contexts (e.g., GUI or services) without printing unexpectedly.
There was a problem hiding this comment.
You are right, I will have a try
| try writeModelMetadata(modelName: alias, modelDir: modelDir) | ||
| } | ||
|
|
||
| public static func ensureModelAvailable(modelName: String, silent: Bool = false) async throws -> String { |
There was a problem hiding this comment.
To be honest, the function name ensureModelAvailable feels a little off. From the name, I would expect it to just check or guarantee that the model is available, but not to actually resolve aliases, download models, or print logs.
This PR adds a small feature that automatically downloads the model if it is not found, similar to the logic in the pull command.
Issues 40.
Tested locally — the model downloads successfully and inference runs as expected.