Keep installed models, chat selection, and web enablement in sync

This commit is contained in:
Mark Gregory
2026-11-17 09:40:46 +00:00
parent 1d5edbc292
commit 4ad93b383b
5 changed files with 52 additions and 22 deletions
+15 -15
View File
@@ -156,7 +156,8 @@ struct ModelCatalogView: View {
private var installedModels: [CatalogModel] {
(try? JSONDecoder().decode([CatalogModel].self, from: managed)) ?? []
let saved = (try? JSONDecoder().decode([CatalogModel].self, from: managed)) ?? []
return saved + CatalogModel.all.filter { $0.installed(at: $0.localFolder) }
}
@@ -179,6 +180,11 @@ struct ModelCatalogView: View {
private var mlxLibrary: some View {
Form {
if !installedModels.isEmpty {
Section("Installed MLX Models") {
ForEach(installedModels.filter { $0.installed(at: $0.localFolder) }) { model in modelRow(model) }
}
}
Section("Local MLX Models") {
HStack {
Button("Register Model Folder…") { scanRequested = false; pickingLibrary = true }
@@ -207,11 +213,6 @@ struct ModelCatalogView: View {
}
if !libraryStatus.isEmpty { Text(libraryStatus).foregroundStyle(.secondary) }
}
if !installedModels.isEmpty {
Section("Downloaded Models") {
ForEach(installedModels) { model in modelRow(model) }
}
}
Section("Hugging Face") {
HStack {
TextField("Search MLX models", text: $query, prompt: Text("e.g. Qwen, Gemma"))
@@ -220,10 +221,12 @@ struct ModelCatalogView: View {
if searching { ProgressView().controlSize(.small) }
}
if !searchStatus.isEmpty { Text(searchStatus).foregroundStyle(.secondary) }
ForEach(matches) { model in modelRow(model) }
ForEach(matches.filter { model in !installedModels.contains { $0.id == model.id && $0.installed(at: $0.localFolder) } }) { model in
modelRow(model)
}
}
Section("Recommended Models") {
ForEach(CatalogModel.all) { model in modelRow(model) }
ForEach(CatalogModel.all.filter { !$0.installed(at: $0.localFolder) }) { model in modelRow(model) }
}
if !status.isEmpty {
Section {
@@ -285,9 +288,7 @@ struct ModelCatalogView: View {
}
let active = ollamaModel == model.name && !mlxOnly && !compatibleEnabled
Button(active ? "Active" : "Use Model") {
ollamaModel = model.name
compatibleEnabled = false
mlxOnly = false
studio.selectOllamaModel(model.name)
}
.disabled(active || studio.running)
}
@@ -405,8 +406,7 @@ struct ModelCatalogView: View {
defer { loadingPath = nil }
do {
try await studio.loadMLX(path)
mlxPath = path
mlxOnly = true
studio.selectMLXModel(path)
status = "Loaded \(name)."
} catch { status = error.localizedDescription }
}
@@ -424,7 +424,7 @@ struct ModelCatalogView: View {
await MainActor.run { status = message; progress = fraction }
}
if !CatalogModel.all.contains(where: { $0.id == model.id }) {
managed = try JSONEncoder().encode(installedModels.filter { $0.id != model.id } + [model])
managed = try JSONEncoder().encode(installedModels.filter { $0.id != model.id && !CatalogModel.all.contains($0) } + [model])
}
status = "Downloaded \(model.title)."
} catch {
@@ -441,7 +441,7 @@ struct ModelCatalogView: View {
mlxPath = ""
studio.unloadMLX()
}
managed = try JSONEncoder().encode(installedModels.filter { $0.id != model.id })
managed = try JSONEncoder().encode(installedModels.filter { $0.id != model.id && !CatalogModel.all.contains($0) })
status = "Removed \(model.title)."
} catch { status = error.localizedDescription }
}