-
-
Notifications
You must be signed in to change notification settings - Fork 65
Enable pruning downloaded models #71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
689fd16
2f8c984
1256c61
28999b2
fc303c6
857256e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -302,6 +302,33 @@ public extension LLMSession { | |
| public func downloadModel(onProgress: @Sendable @escaping (Double) async -> Void = { _ in }) async throws { | ||
| try await downloader.download(onProgress: onProgress) | ||
| } | ||
|
|
||
| public static func pruneModels(in url: URL = FileDownloader.defaultRootDestination, excluding: [Model] = []) throws { | ||
| guard let enumerator = FileManager.default.enumerator(at: url, includingPropertiesForKeys: [.isDirectoryKey], options: [.skipsPackageDescendants]) else { return } | ||
|
|
||
| let excludingNormalized: Set<URL> = Set(excluding.compactMap { model -> URL? in | ||
| if let model = model as? LLMSession.DownloadModel { | ||
| return model.modelPath.resolvingSymlinksInPath().standardizedFileURL | ||
| } | ||
| if let model = model as? LLMSession.LocalModel { | ||
| return model.modelPath.resolvingSymlinksInPath().standardizedFileURL | ||
| } | ||
| return nil | ||
| }) | ||
|
|
||
| for case let fileURL as URL in enumerator { | ||
| if excludingNormalized.contains(fileURL.resolvingSymlinksInPath().standardizedFileURL) { | ||
| enumerator.skipDescendants() | ||
| continue | ||
| } | ||
|
|
||
| if (try fileURL.resourceValues(forKeys: [.isDirectoryKey])).isDirectory == false { | ||
| try FileManager.default.removeItem(at: fileURL) | ||
| } | ||
|
Comment on lines
+311
to
+315
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might make sense for these models (
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You’re absolutely right. I’d like to refactor this in the future. |
||
| } | ||
|
|
||
| try url.removeEmptyFolders() | ||
|
ashtonmeuser marked this conversation as resolved.
Outdated
|
||
| } | ||
| } | ||
|
|
||
| struct LocalModel: Model { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.