Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 108 additions & 0 deletions apps/omlx-mac/Resources/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -9647,6 +9647,42 @@
}
}
},
"models.badge.local_cache" : {
"comment" : "Badge for a model stored in the shared Hugging Face local cache",
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Local cache"
}
}
}
},
"models.badge.profile" : {
"comment" : "Badge for an exposed profile backed by a base model",
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Profile"
}
}
}
},
"models.badge.virtual" : {
"comment" : "Badge for a built-in model with no files on disk",
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Virtual"
}
}
}
},
"models.delete.confirm_button" : {
"comment" : "Destructive button label inside the delete-model confirmation dialog; placeholder is the model id",
"extractionState" : "extracted_with_value",
Expand Down Expand Up @@ -9719,6 +9755,78 @@
}
}
},
"models.remove.local_cache.button" : {
"comment" : "Destructive button that removes a Hugging Face repository from the local cache",
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Remove from local cache"
}
}
}
},
"models.remove.local_cache.message" : {
"comment" : "Warning that removing a shared Hugging Face cache repository may affect other apps",
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "This removes the repository's cache entry, including refs, snapshots, and blobs. Other applications using the same Hugging Face cache may be affected."
}
}
}
},
"models.remove.local_cache.title" : {
"comment" : "Confirmation title before removing a Hugging Face cache-backed model",
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Remove this model from local cache?"
}
}
}
},
"models.remove.profile.button" : {
"comment" : "Destructive button that deletes only an exposed model profile",
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Delete profile"
}
}
}
},
"models.remove.profile.message" : {
"comment" : "Warning that deleting an exposed profile preserves its base model files",
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Only this profile will be deleted. The base model and its files will be kept."
}
}
}
},
"models.remove.profile.title" : {
"comment" : "Confirmation title before deleting an exposed model profile",
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Delete this profile?"
}
}
}
},
"models.library.empty.sub" : {
"comment" : "Empty-state subtitle directing the user to the Downloads screen",
"extractionState" : "manual",
Expand Down
244 changes: 175 additions & 69 deletions apps/omlx-mac/Sources/AppView/Screens/ModelsScreen.swift

Large diffs are not rendered by default.

76 changes: 71 additions & 5 deletions apps/omlx-mac/Sources/AppView/ViewModels/ModelsScreenVM.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,17 @@ final class ModelsScreenVM {
private var pollTask: Task<Void, Never>?

var activeModels: [ModelDTO] {
allModels.filter { $0.loaded || $0.isLoading }
allModels.filter {
$0.virtual != true
&& $0.removalKind != "profile"
&& ($0.loaded || $0.isLoading)
}
}
var libraryModels: [ModelDTO] { modelLibraryRows(allModels) }
var pendingRemovalModel: ModelDTO? {
guard let pendingRemoveID else { return nil }
return libraryModels.first { $0.id == pendingRemoveID }
}
var libraryModels: [ModelDTO] { allModels }

func start(client: OMLXClient) async {
self.client = client
Expand Down Expand Up @@ -78,13 +86,25 @@ final class ModelsScreenVM {
}
}

func remove(id: String, client: OMLXClient) {
func remove(model: ModelDTO, client: OMLXClient) {
pendingRemoveID = nil
deletingID = id
deletingID = model.id
Task { [weak self] in
defer { Task { @MainActor [weak self] in self?.deletingID = nil } }
do {
_ = try await client.deleteHFModel(modelName: id)
switch model.removalKind {
case "profile":
guard let sourceModelID = model.sourceModelId,
let profileName = model.profileName else { return }
_ = try await client.deleteModelProfile(
id: sourceModelID,
name: profileName
)
case "local_cache", "local_model":
_ = try await client.deleteHFModel(modelName: model.id)
default:
return
}
await self?.refresh()
self?.lastError = nil
} catch {
Expand All @@ -105,3 +125,49 @@ final class ModelsScreenVM {
}

}

func modelLibraryRows(_ models: [ModelDTO]) -> [ModelDTO] {
let rows = models.flatMap { model -> [ModelDTO] in
let profiles = (model.exposedProfiles ?? []).map { profile in
ModelDTO(
id: profile.modelId ?? "\(model.id):\(profile.name)",
displayName: profile.displayName,
modelPath: nil,
loaded: false,
isLoading: false,
estimatedSize: 0,
estimatedSizeFormatted: "—",
actualSize: 0,
actualSizeFormatted: nil,
pinned: false,
isDefault: false,
isFavorite: false,
engineType: model.engineType,
modelType: model.modelType,
configModelType: model.configModelType,
modelContextLength: model.modelContextLength,
thinkingDefault: model.thinkingDefault,
dflashCompatible: model.dflashCompatible,
dflashCompatibilityReason: model.dflashCompatibilityReason,
dflashSsdCacheAvailable: model.dflashSsdCacheAvailable,
mtpCompatible: model.mtpCompatible,
mtpCompatibilityReason: model.mtpCompatibilityReason,
qwen4PleSsdOffloadSupported: model.qwen4PleSsdOffloadSupported,
qwen4PleSsdOffloadForced: model.qwen4PleSsdOffloadForced,
qwen4PleResidentBytes: model.qwen4PleResidentBytes,
qwen4PleMmapBytes: model.qwen4PleMmapBytes,
virtual: false,
sourceType: "profile",
sourceRepoId: nil,
deletable: true,
removalKind: "profile",
sourceModelId: model.id,
profileName: profile.name,
exposedProfiles: nil,
settings: nil
)
}
return [model] + profiles
}
return sortModelsByName(rows)
}
12 changes: 12 additions & 0 deletions apps/omlx-mac/Sources/Net/DTO/ModelsDTO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ struct ModelDTO: Codable, Equatable, Sendable, Identifiable {
/// True for builtin virtual entries (e.g. the MarkItDown document
/// converter) that have no real load/unload lifecycle.
let virtual: Bool?
/// Server-owned source classification. `hf_cache` entries live in the
/// shared Hugging Face cache instead of oMLX's model directory.
let sourceType: String?
let sourceRepoId: String?
/// Destructive capability advertised by the admin catalog. The UI must
/// dispatch on this value instead of inferring ownership from paths.
let deletable: Bool?
let removalKind: String?
/// Relationship metadata used by synthetic Profile rows in Model Library.
let sourceModelId: String?
let profileName: String?
let exposedProfiles: [ProfileDTO]?
let settings: ModelSettingsDTO?
}

Expand Down
6 changes: 6 additions & 0 deletions apps/omlx-mac/Sources/Net/OMLXClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,12 @@ final class OMLXClient: ObservableObject {
var req = URLRequest(url: url)
req.httpMethod = method
req.setValue("application/json", forHTTPHeaderField: "Accept")
if method == "GET" {
// Admin resources are live server state. NSURLCache can otherwise
// keep a removed model visible until the app quits.
req.cachePolicy = .reloadIgnoringLocalCacheData
req.setValue("no-cache", forHTTPHeaderField: "Cache-Control")
}
if body != nil {
req.setValue("application/json", forHTTPHeaderField: "Content-Type")
req.httpBody = body
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,13 @@ final class MenubarControllerModelsTests: XCTestCase {
qwen4PleResidentBytes: nil,
qwen4PleMmapBytes: nil,
virtual: virtual,
sourceType: nil,
sourceRepoId: nil,
deletable: nil,
removalKind: nil,
sourceModelId: nil,
profileName: nil,
exposedProfiles: nil,
settings: nil
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,13 @@ final class ModelSettingsScreenVMTests: XCTestCase {
qwen4PleResidentBytes: nil,
qwen4PleMmapBytes: nil,
virtual: nil,
sourceType: nil,
sourceRepoId: nil,
deletable: nil,
removalKind: nil,
sourceModelId: nil,
profileName: nil,
exposedProfiles: nil,
settings: nil
)
model.thinkingForced = configModelType == "k2_horizon"
Expand Down
45 changes: 44 additions & 1 deletion apps/omlx-mac/Tests/oMLXTests/ModelsScreenSortingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,43 @@ final class ModelsScreenSortingTests: XCTestCase {
XCTAssertEqual(ids, ["Qwen", "gemma", "llama"])
}

private func makeModel(_ id: String, displayName: String? = nil) -> ModelDTO {
func testModelLibraryRowsExposeProfileWithoutDuplicatingBaseSize() throws {
let profile = ProfileDTO(
name: "thinking",
displayName: "Thinking",
description: nil,
createdAt: nil,
updatedAt: nil,
sourceTemplate: nil,
isBuiltin: false,
exposeAsModel: true,
modelId: "qwen:thinking",
hasEngineFields: false,
settings: nil
)
let base = makeModel(
"qwen",
removalKind: "local_cache",
exposedProfiles: [profile]
)

let rows = modelLibraryRows([base])

XCTAssertEqual(Set(rows.map(\.id)), ["qwen", "qwen:thinking"])
let profileRow = try XCTUnwrap(rows.first { $0.id == "qwen:thinking" })
XCTAssertEqual(profileRow.removalKind, "profile")
XCTAssertEqual(profileRow.sourceModelId, "qwen")
XCTAssertEqual(profileRow.profileName, "thinking")
XCTAssertEqual(profileRow.estimatedSize, 0)
XCTAssertEqual(profileRow.deletable, true)
}

private func makeModel(
_ id: String,
displayName: String? = nil,
removalKind: String? = nil,
exposedProfiles: [ProfileDTO]? = nil
) -> ModelDTO {
ModelDTO(
id: id,
displayName: displayName,
Expand Down Expand Up @@ -69,6 +105,13 @@ final class ModelsScreenSortingTests: XCTestCase {
qwen4PleResidentBytes: nil,
qwen4PleMmapBytes: nil,
virtual: nil,
sourceType: nil,
sourceRepoId: nil,
deletable: nil,
removalKind: removalKind,
sourceModelId: nil,
profileName: nil,
exposedProfiles: exposedProfiles,
settings: nil
)
}
Expand Down
10 changes: 10 additions & 0 deletions apps/omlx-web/omlx_web/i18n/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@
"models.manager.table.type": "Typ",
"models.manager.table.size": "Velikost",
"models.manager.local_models": "Lokální modely",
"models.manager.available_models": "Available Models",
"models.manager.models_count": "{count} modelů",
"models.manager.refresh": "Obnovit",
"models.manager.reload": "Znovu načíst",
Expand All @@ -219,6 +220,15 @@
"models.manager.delete_confirm": "Smazat?",
"models.manager.delete_yes": "Ano",
"models.manager.delete_no": "Ne",
"models.manager.badge.local_cache": "Local cache",
"models.manager.badge.virtual": "Virtual",
"models.manager.badge.profile": "Profile",
"models.manager.remove.local_cache": "Remove from local cache",
"models.manager.remove.local_model": "Delete model",
"models.manager.remove.profile": "Delete profile",
"models.manager.remove_warning.local_cache": "This removes the repository's local cache entry, including refs, snapshots, and blobs. Other applications using the same Hugging Face cache may be affected.",
"models.manager.remove_warning.local_model": "The model files will be permanently removed from disk and unloaded if currently running.",
"models.manager.remove_warning.profile": "Only this profile will be deleted. The base model and its files will be kept.",
"models.downloader.section_label": "Modely",
"models.downloader.heading": "Stahování modelů",
"models.downloader.description": "Stahujte modely z HuggingFace nebo ModelScope a procházejte dostupné modely.",
Expand Down
Loading
Loading