Keep installed models, chat selection, and web enablement in sync
This commit is contained in:
@@ -191,6 +191,13 @@ struct ChatView: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
.onChange(of: studio.modelSelectionRevision) {
|
||||
let defaults = UserDefaults.standard
|
||||
mlxPath = defaults.string(forKey: "mlxPath") ?? ""
|
||||
model = defaults.string(forKey: "ollamaModel") ?? ""
|
||||
mlxOnly = defaults.bool(forKey: "mlxOnly")
|
||||
compatibleEnabled = defaults.bool(forKey: "compatibleEnabled")
|
||||
}
|
||||
.onChange(of: studio.selected) { old, _ in
|
||||
useDocuments = false
|
||||
if old != nil {
|
||||
|
||||
+5
-5
@@ -223,6 +223,7 @@ struct MCPSettings: View {
|
||||
@AppStorage("mcpTransport") private var transport = "http"
|
||||
@AppStorage("mcpExecutable") private var executable = ""
|
||||
@AppStorage("mcpArguments") private var launchArguments = ""
|
||||
@AppStorage("builtInWebEnabled") private var builtInWebEnabled = true
|
||||
@AppStorage("webSearchEndpoint") private var webSearchEndpoint = ""
|
||||
@AppStorage("mcpConfigPath") private var configPath = ""
|
||||
@State private var token = ""
|
||||
@@ -243,11 +244,10 @@ struct MCPSettings: View {
|
||||
HSplitView {
|
||||
Form {
|
||||
Section("Built-In Tools") {
|
||||
LabeledContent {
|
||||
Text("Runs on demand").foregroundStyle(.secondary)
|
||||
} label: {
|
||||
Label(BuiltInWebTools.name, systemImage: "globe")
|
||||
}
|
||||
Toggle("Web Search and Page Retrieval", isOn: $builtInWebEnabled)
|
||||
.onChange(of: builtInWebEnabled) { _, _ in studio.restoreToolsets() }
|
||||
Text(builtInWebEnabled ? "Ready for web requests in chat." : "Automatic web lookup is off.")
|
||||
.font(.caption).foregroundStyle(.secondary)
|
||||
}
|
||||
Section("Custom MCP Servers") {
|
||||
Menu("Manage Servers", systemImage: "ellipsis.circle") {
|
||||
|
||||
+15
-15
@@ -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 }
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ final class StudioModel: ObservableObject {
|
||||
@Published private(set) var modelStatus = ""
|
||||
@Published private(set) var managing = false
|
||||
@Published private(set) var running = false
|
||||
@Published private(set) var modelSelectionRevision = 0
|
||||
@Published private(set) var webStatus = ""
|
||||
@Published private(set) var webDiagnostics: [String] = []
|
||||
@Published private(set) var webSearchLink: URL?
|
||||
@@ -181,7 +182,7 @@ final class StudioModel: ObservableObject {
|
||||
\(toolAttachment.output)
|
||||
""")
|
||||
}
|
||||
let lookup = ChatWebLookup(message: text)
|
||||
let lookup = UserDefaults.standard.object(forKey: "builtInWebEnabled") as? Bool == false ? nil : ChatWebLookup(message: text)
|
||||
let wantsRepositories = GiteaRepositoryLookup.matches(text)
|
||||
let repositoryClient = wantsRepositories ?
|
||||
activeToolsets.first(where: { entry in
|
||||
@@ -467,6 +468,21 @@ final class StudioModel: ObservableObject {
|
||||
}
|
||||
|
||||
func cancelManagement() { management?.cancel() }
|
||||
func selectMLXModel(_ path: String) {
|
||||
let defaults = UserDefaults.standard
|
||||
defaults.set(path, forKey: "mlxPath")
|
||||
defaults.set(true, forKey: "mlxOnly")
|
||||
modelSelectionRevision += 1
|
||||
}
|
||||
|
||||
func selectOllamaModel(_ name: String) {
|
||||
let defaults = UserDefaults.standard
|
||||
defaults.set(name, forKey: "ollamaModel")
|
||||
defaults.set(false, forKey: "compatibleEnabled")
|
||||
defaults.set(false, forKey: "mlxOnly")
|
||||
modelSelectionRevision += 1
|
||||
}
|
||||
|
||||
func loadMLX(_ path: String) async throws {
|
||||
await configureMLXRuntime()
|
||||
try await mlx.load(path)
|
||||
@@ -587,7 +603,11 @@ final class StudioModel: ObservableObject {
|
||||
extension StudioModel {
|
||||
func restoreToolsets(defaults: UserDefaults = .standard) {
|
||||
let endpoint = defaults.string(forKey: "webSearchEndpoint") ?? ""
|
||||
connectMCP(.web, name: BuiltInWebTools.name) { BuiltInWebTools(searchEndpoint: endpoint) }
|
||||
if defaults.object(forKey: "builtInWebEnabled") as? Bool != false {
|
||||
connectMCP(.web, name: BuiltInWebTools.name) { BuiltInWebTools(searchEndpoint: endpoint) }
|
||||
} else {
|
||||
disconnectMCP(.web)
|
||||
}
|
||||
guard let path = defaults.string(forKey: "mcpConfigPath"), !path.isEmpty else { return }
|
||||
let enabled = Set(enabledMCPProfiles(path: path, defaults: defaults))
|
||||
for name in enabled {
|
||||
|
||||
Reference in New Issue
Block a user