new features
This commit is contained in:
+253
-56
@@ -41,6 +41,7 @@ struct AIStudioApp: App {
|
||||
.task {
|
||||
await Task.yield()
|
||||
studio.open()
|
||||
try? await studio.refreshLocalMLXModels()
|
||||
}
|
||||
}
|
||||
.defaultSize(width: 1000, height: 700)
|
||||
@@ -53,6 +54,12 @@ struct AIStudioApp: App {
|
||||
Button("Cycle Workspace Mode") { mode = nextValue(mode) }.keyboardShortcut(StudioShortcut.workspaceMode.shortcut(in: shortcutData))
|
||||
}
|
||||
}
|
||||
Window("Training & Images", id: "creativeWorkspace") {
|
||||
CreativeWorkspace()
|
||||
.preferredColorScheme(theme.colorScheme)
|
||||
.tint(StudioCustomTheme.selected(customThemeID, in: customThemesData)?.accentColor ?? accent.color)
|
||||
}
|
||||
.defaultSize(width: 990, height: 690)
|
||||
Settings {
|
||||
StudioSettingsView(studio: studio)
|
||||
.preferredColorScheme(theme.colorScheme)
|
||||
@@ -67,6 +74,9 @@ struct AIStudioApp: App {
|
||||
}
|
||||
|
||||
struct ChatView: View {
|
||||
@Environment(\.openWindow) private var openWindow
|
||||
@State private var checkedThinkingModel: ChatModelChoice?
|
||||
@State private var inspectedThinkingSupport = false
|
||||
@ObservedObject var studio: StudioModel
|
||||
@AppStorage("endpoint") private var endpoint = "http://127.0.0.1:11434"
|
||||
@AppStorage("ollamaModel") private var model = ""
|
||||
@@ -89,6 +99,8 @@ struct ChatView: View {
|
||||
@AppStorage("mlxPath") private var mlxPath = ""
|
||||
@AppStorage("thinking") private var thinking = Thinking.automatic
|
||||
@AppStorage("failover") private var failover = true
|
||||
@AppStorage("defaultCoreMLPath") private var defaultCoreMLPath = ""
|
||||
@AppStorage("defaultGGUFPath") private var defaultGGUFPath = ""
|
||||
@AppStorage("mlxOnly") private var mlxOnly = false
|
||||
@AppStorage("compatibleEnabled") private var compatibleEnabled = false
|
||||
@AppStorage("compatibleEndpoint") private var compatibleEndpoint = "http://127.0.0.1:1234/v1"
|
||||
@@ -127,10 +139,13 @@ struct ChatView: View {
|
||||
@State private var newTitle = ""
|
||||
|
||||
@AppStorage(ChatModelChoice.settingsKey) private var chatModelData = Data()
|
||||
@AppStorage(GGUFModelMetadata.libraryKey) private var registeredGGUF = Data()
|
||||
@AppStorage("mlxRegisteredPaths") private var registeredMLX = Data()
|
||||
@AppStorage("managedMLXModels") private var managedMLX = Data()
|
||||
|
||||
private var defaultChatModel: ChatModelChoice {
|
||||
if !defaultCoreMLPath.isEmpty { return ChatModelChoice(backend: .coreML, model: defaultCoreMLPath) }
|
||||
if !defaultGGUFPath.isEmpty { return ChatModelChoice(backend: .gguf, model: defaultGGUFPath) }
|
||||
if mlxOnly { return ChatModelChoice(backend: .mlx, model: mlxPath) }
|
||||
if compatibleEnabled { return ChatModelChoice(backend: .compatible, model: compatibleModel) }
|
||||
return ChatModelChoice(backend: .ollama, model: model)
|
||||
@@ -138,6 +153,29 @@ struct ChatView: View {
|
||||
|
||||
private var chatChoices: [UUID: ChatModelChoice] { ChatModelChoice.read(chatModelData) }
|
||||
private var chatModel: ChatModelChoice { modelForChat(studio.selected) }
|
||||
private var thinkingModes: [Thinking] {
|
||||
let choice = chatModel
|
||||
let registered = choice.backend == .gguf && GGUFModelMetadata.library(in: registeredGGUF).contains {
|
||||
$0.path == choice.model && $0.supportsThinking
|
||||
}
|
||||
return ChatThinkingControl.options(backend: choice.backend,
|
||||
supportsLocalThinking: registered || (checkedThinkingModel == choice && inspectedThinkingSupport))
|
||||
}
|
||||
|
||||
private func inspectThinking(_ choice: ChatModelChoice) async {
|
||||
let supported = await Task.detached(priority: .utility) {
|
||||
guard !choice.model.isEmpty else { return false }
|
||||
switch choice.backend {
|
||||
case .mlx: return ThinkingOutput.supportsMLX(choice.model)
|
||||
case .gguf:
|
||||
return (try? GGUFModelMetadata.read(URL(fileURLWithPath: choice.model)).supportsThinking) == true
|
||||
case .ollama, .compatible, .coreML: return false
|
||||
}
|
||||
}.value
|
||||
guard !Task.isCancelled, chatModel == choice else { return }
|
||||
inspectedThinkingSupport = supported
|
||||
checkedThinkingModel = choice
|
||||
}
|
||||
private var backendName: String { chatModel.backend.rawValue }
|
||||
|
||||
private func modelForChat(_ id: UUID?) -> ChatModelChoice {
|
||||
@@ -159,9 +197,11 @@ struct ChatView: View {
|
||||
private var mlxChoices: [String] {
|
||||
let registered = (try? JSONDecoder().decode([String].self, from: registeredMLX)) ?? []
|
||||
let managed = (try? JSONDecoder().decode([CatalogModel].self, from: managedMLX)) ?? []
|
||||
let paths = (managed + CatalogModel.all).map { $0.localFolder.path } + registered + [mlxPath]
|
||||
let installed = paths.filter { !$0.isEmpty && MLXLibrary.isModel(at: URL(fileURLWithPath: $0)) }
|
||||
return Array(Set(installed)).sorted { $0.localizedStandardCompare($1) == .orderedAscending }
|
||||
let saved = (managed + CatalogModel.all).map { $0.localFolder.path } + registered + [mlxPath]
|
||||
let installed = saved.filter { !$0.isEmpty && MLXLibrary.isModel(at: URL(fileURLWithPath: $0)) }
|
||||
return Set((installed + studio.discoveredMLXPaths).map {
|
||||
URL(fileURLWithPath: $0).resolvingSymlinksInPath().path
|
||||
}).sorted { $0.localizedStandardCompare($1) == .orderedAscending }
|
||||
}
|
||||
|
||||
private func modelPicker(for id: UUID?, running: Bool) -> some View {
|
||||
@@ -204,15 +244,25 @@ struct ChatView: View {
|
||||
@State private var replacingFile = false
|
||||
@AppStorage("chatFileAccessFolder") private var chatFileScope = ""
|
||||
@AppStorage("chatFileWriteEnabled") private var chatFileWriteEnabled = false
|
||||
@State private var filePreview: ChatFilePreview?
|
||||
private struct PendingAttachment: Identifiable {
|
||||
let preview: ChatFilePreview
|
||||
let target: StudioModel
|
||||
let conversation: UUID?
|
||||
var id: UUID { preview.id }
|
||||
}
|
||||
@State private var filePreview: PendingAttachment?
|
||||
@State private var preparingFilePreview = false
|
||||
@State private var fileError = ""
|
||||
@State private var splitFileError = ""
|
||||
|
||||
var body: some View {
|
||||
NavigationSplitView(columnVisibility: $columns) {
|
||||
List(visibleChats, selection: $studio.selected) { chat in
|
||||
Label(chat.title, systemImage: "bubble.left").tag(chat.id)
|
||||
.contextMenu {
|
||||
Button("Export Chat as Markdown…", systemImage: "square.and.arrow.up") {
|
||||
exportChat(chat)
|
||||
}
|
||||
Button("Delete Chat", systemImage: "trash", role: .destructive) {
|
||||
chatToDelete = chat
|
||||
confirmDelete = true
|
||||
@@ -223,6 +273,9 @@ struct ChatView: View {
|
||||
.disabled(studio.running || splitStudio.running)
|
||||
.navigationSplitViewColumnWidth(min: 180, ideal: 235)
|
||||
.toolbar {
|
||||
Button("Training & Images", systemImage: "slider.horizontal.3") {
|
||||
openWindow(id: "creativeWorkspace")
|
||||
}
|
||||
Button("New Chat", systemImage: "square.and.pencil") {
|
||||
search = ""
|
||||
studio.newChat()
|
||||
@@ -233,6 +286,12 @@ struct ChatView: View {
|
||||
renaming = true
|
||||
}
|
||||
.disabled(studio.running || splitStudio.running || studio.selected == nil)
|
||||
Button("Export Chat as Markdown…", systemImage: "square.and.arrow.up") {
|
||||
if let chat = studio.conversations.first(where: { $0.id == studio.selected }) {
|
||||
exportChat(chat)
|
||||
}
|
||||
}
|
||||
.disabled(studio.running || splitStudio.running || studio.selected == nil)
|
||||
Button("Delete Chat", systemImage: "trash") {
|
||||
chatToDelete = studio.conversations.first { $0.id == studio.selected }
|
||||
confirmDelete = chatToDelete != nil
|
||||
@@ -286,7 +345,9 @@ struct ChatView: View {
|
||||
.sheet(isPresented: $showingLibrary) { DocumentLibraryView(studio: studio) }
|
||||
.sheet(isPresented: $showingPerformance) { PerformanceDashboard(studio: studio) }
|
||||
.sheet(isPresented: $showingWorkspace) { WorkspaceResourcesView(studio: studio) }
|
||||
.sheet(item: $filePreview) { preview in
|
||||
.sheet(item: $filePreview) { pending in
|
||||
let preview = pending.preview
|
||||
let target = pending.target
|
||||
VStack(alignment: .leading, spacing: 12) {
|
||||
Text(preview.name).font(.headline)
|
||||
ScrollView {
|
||||
@@ -295,7 +356,7 @@ struct ChatView: View {
|
||||
.frame(maxWidth: 520, maxHeight: 260)
|
||||
.accessibilityLabel("Attachment preview")
|
||||
}
|
||||
if preview.imagePNG == nil || chatModel.backend == .mlx {
|
||||
if preview.imagePNG == nil || modelForChat(target.selected).backend == .mlx {
|
||||
Text(preview.text.isEmpty && preview.imagePNG != nil
|
||||
? "No readable text detected. Choose a vision-capable model to analyze this image."
|
||||
: preview.text)
|
||||
@@ -306,8 +367,10 @@ struct ChatView: View {
|
||||
Spacer()
|
||||
Button("Cancel") { filePreview = nil }.keyboardShortcut(.cancelAction)
|
||||
Button("Attach to Next Message") {
|
||||
studio.attachToolResult(name: preview.name, output: preview.text,
|
||||
isDocument: true, isPDF: preview.isPDF, imagePNG: preview.imagePNG)
|
||||
if target.selected == pending.conversation {
|
||||
target.attachToolResult(name: preview.name, output: preview.text,
|
||||
isDocument: true, isPDF: preview.isPDF, imagePNG: preview.imagePNG)
|
||||
}
|
||||
filePreview = nil
|
||||
}.keyboardShortcut(.defaultAction)
|
||||
}
|
||||
@@ -328,6 +391,8 @@ struct ChatView: View {
|
||||
}
|
||||
.onChange(of: studio.modelSelectionRevision) {
|
||||
let defaults = UserDefaults.standard
|
||||
defaultCoreMLPath = defaults.string(forKey: "defaultCoreMLPath") ?? ""
|
||||
defaultGGUFPath = defaults.string(forKey: "defaultGGUFPath") ?? ""
|
||||
mlxPath = defaults.string(forKey: "mlxPath") ?? ""
|
||||
model = defaults.string(forKey: "ollamaModel") ?? ""
|
||||
mlxOnly = defaults.bool(forKey: "mlxOnly")
|
||||
@@ -411,11 +476,13 @@ struct ChatView: View {
|
||||
.font(chatFont.font(size: chatSize))
|
||||
Divider()
|
||||
VStack(alignment: .leading, spacing: 6) {
|
||||
let feedback = [showDebugOutput ? "" : splitStudio.webStatus, splitStudio.status]
|
||||
attachmentLabel(for: splitStudio)
|
||||
let feedback = [splitFileError, showDebugOutput ? "" : splitStudio.webStatus, splitStudio.status]
|
||||
.filter { !$0.isEmpty }.joined(separator: " · ")
|
||||
if !feedback.isEmpty { Text(feedback).font(.caption).foregroundStyle(.secondary) }
|
||||
ChatComposerInput(text: $splitStudio.prompt, canSend: !splitStudio.running, spellCheck: spellCheck,
|
||||
autoCorrect: autoCorrect, font: chatFont.appKit(size: chatSize), send: sendSplitMessage)
|
||||
autoCorrect: autoCorrect, font: chatFont.appKit(size: chatSize), send: sendSplitMessage,
|
||||
pasteAttachment: { pasteAttachment($0, into: splitStudio) })
|
||||
.frame(height: 54)
|
||||
HStack {
|
||||
resourceMenu(for: splitStudio)
|
||||
@@ -474,18 +541,7 @@ struct ChatView: View {
|
||||
.font(.caption)
|
||||
.disabled(studio.running)
|
||||
}
|
||||
if let attachment = studio.toolAttachment {
|
||||
HStack {
|
||||
Label("\(attachment.name) attached to next message", systemImage: "paperclip")
|
||||
if attachment.imagePNG != nil && chatModel.backend == .mlx {
|
||||
Text("Extracted text only").foregroundStyle(.secondary)
|
||||
}
|
||||
if chatModel.backend != .mlx { Text("Sent to \(backendName)").foregroundStyle(.secondary) }
|
||||
Spacer()
|
||||
Button("Remove", systemImage: "xmark.circle") { studio.removeToolAttachment() }
|
||||
}
|
||||
.font(.caption)
|
||||
}
|
||||
attachmentLabel(for: studio)
|
||||
let activity = [preparingFilePreview ? "Preparing attachment preview…" : fileError,
|
||||
showDebugOutput ? "" : studio.webStatus, studio.status].filter { !$0.isEmpty }
|
||||
if !activity.isEmpty {
|
||||
@@ -496,7 +552,8 @@ struct ChatView: View {
|
||||
Link("Open in Browser", destination: link).font(.caption)
|
||||
}
|
||||
ChatComposerInput(text: $studio.prompt, canSend: !studio.running, spellCheck: spellCheck,
|
||||
autoCorrect: autoCorrect, font: chatFont.appKit(size: chatSize), send: sendMessage)
|
||||
autoCorrect: autoCorrect, font: chatFont.appKit(size: chatSize), send: sendMessage,
|
||||
pasteAttachment: { pasteAttachment($0, into: studio) })
|
||||
.frame(height: 62)
|
||||
.padding(5)
|
||||
.background(.background, in: RoundedRectangle(cornerRadius: 8))
|
||||
@@ -541,16 +598,17 @@ struct ChatView: View {
|
||||
HStack(spacing: 10) {
|
||||
modelPicker(for: studio.selected, running: studio.running)
|
||||
Spacer()
|
||||
if chatModel.backend == .ollama || (chatModel.backend == .mlx && MLXThinking.supports(chatModel.model)) {
|
||||
let modes: [Thinking] = chatModel.backend == .mlx ? [.automatic, .off, .on] : Thinking.allCases
|
||||
Picker("Thinking", selection: Binding(
|
||||
get: { modes.contains(thinking) ? thinking : .automatic },
|
||||
set: { thinking = $0 }
|
||||
)) {
|
||||
ForEach(modes) { Text($0.rawValue.capitalized).tag($0) }
|
||||
}
|
||||
.fixedSize().disabled(studio.running)
|
||||
let modes = thinkingModes
|
||||
Picker("Thinking", selection: Binding(
|
||||
get: { modes.contains(thinking) ? thinking : .automatic },
|
||||
set: { thinking = $0 }
|
||||
)) {
|
||||
ForEach(modes) { Text($0.rawValue.capitalized).tag($0) }
|
||||
}
|
||||
.fixedSize()
|
||||
.disabled(studio.running || modes.count == 1)
|
||||
.help(modes.count == 1 ? "This backend controls its own thinking mode." : "Set thinking for the selected model.")
|
||||
.task(id: chatModel) { await inspectThinking(chatModel) }
|
||||
Toggle("Agents", isOn: $agentWorkflowEnabled)
|
||||
.toggleStyle(.checkbox)
|
||||
.fixedSize()
|
||||
@@ -572,6 +630,38 @@ struct ChatView: View {
|
||||
}
|
||||
.padding(16)
|
||||
}
|
||||
@ViewBuilder private func attachmentLabel(for target: StudioModel) -> some View {
|
||||
if let attachment = target.toolAttachment {
|
||||
let backend = modelForChat(target.selected).backend
|
||||
HStack {
|
||||
Label("\(attachment.name) attached to next message", systemImage: "paperclip")
|
||||
if backend != .mlx { Text("Sent to \(backend.rawValue)").foregroundStyle(.secondary) }
|
||||
else if attachment.imagePNG != nil { Text("Extracted text only").foregroundStyle(.secondary) }
|
||||
Spacer()
|
||||
Button("Remove", systemImage: "xmark.circle") { target.removeToolAttachment() }
|
||||
}
|
||||
.font(.caption)
|
||||
}
|
||||
}
|
||||
|
||||
private func exportChat(_ chat: Conversation) {
|
||||
let panel = NSSavePanel()
|
||||
panel.allowedContentTypes = [UTType(filenameExtension: "md") ?? .plainText]
|
||||
panel.canCreateDirectories = true
|
||||
let name = chat.title.components(separatedBy: CharacterSet.controlCharacters.union(CharacterSet(charactersIn: "/:")))
|
||||
.joined(separator: " ").trimmingCharacters(in: .whitespacesAndNewlines.union(CharacterSet(charactersIn: ".")))
|
||||
panel.nameFieldStringValue = (name.isEmpty ? "Chat" : String(name.prefix(80))) + ".md"
|
||||
panel.begin { response in
|
||||
guard response == .OK, let url = panel.url else { return }
|
||||
do {
|
||||
try studio.exportChat(chat.id, to: url)
|
||||
fileError = "Exported \(url.lastPathComponent)."
|
||||
} catch {
|
||||
fileError = error.localizedDescription
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func pickLocalFile() {
|
||||
let panel = NSOpenPanel()
|
||||
panel.canChooseFiles = true
|
||||
@@ -580,16 +670,27 @@ struct ChatView: View {
|
||||
panel.prompt = "Preview"
|
||||
panel.begin { response in
|
||||
guard response == .OK, let url = panel.url else { return }
|
||||
Task { @MainActor in
|
||||
let conversation = studio.selected
|
||||
preparingFilePreview = true
|
||||
fileError = ""
|
||||
defer { preparingFilePreview = false }
|
||||
do {
|
||||
let preview = try await Task.detached { try ChatFilePreview.read(url) }.value
|
||||
guard studio.selected == conversation, !studio.running else { return }
|
||||
filePreview = preview
|
||||
} catch { fileError = error.localizedDescription }
|
||||
pasteAttachment(.files([url]), into: studio)
|
||||
}
|
||||
}
|
||||
|
||||
private func pasteAttachment(_ item: ComposerPaste, into target: StudioModel) {
|
||||
guard !target.running, !preparingFilePreview, filePreview == nil else { return }
|
||||
let conversation = target.selected
|
||||
let isMain = target === studio
|
||||
preparingFilePreview = true
|
||||
if isMain { fileError = "" }
|
||||
else { splitFileError = "Preparing attachment preview…" }
|
||||
Task { @MainActor in
|
||||
defer { preparingFilePreview = false }
|
||||
do {
|
||||
let preview = try await Task.detached { try item.preview() }.value
|
||||
if !isMain { splitFileError = "" }
|
||||
guard target.selected == conversation, !target.running else { return }
|
||||
filePreview = PendingAttachment(preview: preview, target: target, conversation: conversation)
|
||||
} catch {
|
||||
if isMain { fileError = error.localizedDescription }
|
||||
else { splitFileError = error.localizedDescription }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -632,7 +733,7 @@ struct ChatView: View {
|
||||
recall: recall, useDocuments: useDocuments, instructions: promptMode.instructions(custom: customPrompt),
|
||||
settings: GenerationSettings.read(generationSettings), agents: selectedAgents, agentTools: allowAgentTools,
|
||||
ragEnabled: ragEnabled, lmStudioPlugins: pluginsEnabled && pluginEndpoint == compatibleEndpoint
|
||||
? CompatibleEndpoint.pluginIDs(pluginIDs) : [])
|
||||
? CompatibleEndpoint.pluginIDs(pluginIDs) : [], gguf: choice.backend == .gguf, coreML: choice.backend == .coreML)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -750,6 +851,7 @@ private struct ChatModelPicker: View {
|
||||
let compatibleDefault: String
|
||||
let select: (ChatModelChoice?) -> Void
|
||||
|
||||
@AppStorage(CoreMLLibrary.key) private var coreMLLibrary = Data()
|
||||
@State private var showing = false
|
||||
@State private var compatibleModels: [String] = []
|
||||
@State private var compatibleStatus = ""
|
||||
@@ -759,11 +861,17 @@ private struct ChatModelPicker: View {
|
||||
Button {
|
||||
showing.toggle()
|
||||
} label: {
|
||||
Label(choice.displayName, systemImage: choice.backend == .mlx ? "cpu" : "server.rack")
|
||||
.lineLimit(1)
|
||||
HStack(spacing: 6) {
|
||||
Label(choice.displayName, systemImage: [.mlx, .gguf, .coreML].contains(choice.backend) ? "cpu" : "server.rack")
|
||||
.lineLimit(1)
|
||||
Text(choice.backend.rawValue)
|
||||
.font(.caption.weight(.semibold))
|
||||
.foregroundStyle(.secondary)
|
||||
.fixedSize()
|
||||
}
|
||||
}
|
||||
.buttonStyle(.bordered)
|
||||
.accessibilityLabel("Chat model: " + choice.displayName)
|
||||
.accessibilityLabel("Chat model: \(choice.displayName), \(choice.backend.rawValue)")
|
||||
.help("Switch models for this conversation")
|
||||
.popover(isPresented: $showing) {
|
||||
Form {
|
||||
@@ -774,6 +882,14 @@ private struct ChatModelPicker: View {
|
||||
optionLabel("Use Default · " + defaultChoice.displayName, selected: !hasOverride)
|
||||
}
|
||||
}
|
||||
GGUFModels(selection: choice.backend == .gguf ? choice.model : nil) {
|
||||
choose(ChatModelChoice(backend: .gguf, model: $0))
|
||||
}
|
||||
if #available(macOS 15, *), !CoreMLLibrary.read(coreMLLibrary).isEmpty {
|
||||
Section("Core ML") {
|
||||
ForEach(CoreMLLibrary.read(coreMLLibrary)) { model in modelButton(.coreML, model.path) }
|
||||
}
|
||||
}
|
||||
Section("Ollama") {
|
||||
let installed = studio.modelListEndpoint == endpoint ? studio.models.map(\.name) : []
|
||||
ForEach(names(installed + [ollamaDefault]), id: \.self) { name in
|
||||
@@ -808,7 +924,7 @@ private struct ChatModelPicker: View {
|
||||
.formStyle(.grouped)
|
||||
.frame(width: 340, height: 420)
|
||||
.task {
|
||||
if studio.modelListEndpoint != endpoint { studio.refresh(endpoint: endpoint) }
|
||||
if choice.backend == .ollama && studio.modelListEndpoint != endpoint { studio.refresh(endpoint: endpoint) }
|
||||
}
|
||||
.onChange(of: compatibleEndpoint) {
|
||||
compatibleModels = []
|
||||
@@ -976,6 +1092,8 @@ struct BackendSettings: View {
|
||||
@AppStorage("ollamaModel") private var model = ""
|
||||
@AppStorage("mlxPath") private var mlxPath = ""
|
||||
@AppStorage("failover") private var failover = true
|
||||
@AppStorage("defaultCoreMLPath") private var defaultCoreMLPath = ""
|
||||
@AppStorage("defaultGGUFPath") private var defaultGGUFPath = ""
|
||||
@AppStorage("mlxOnly") private var mlxOnly = false
|
||||
@AppStorage("compatibleEnabled") private var compatibleEnabled = false
|
||||
@AppStorage("compatibleEndpoint") private var compatibleEndpoint = "http://127.0.0.1:1234/v1"
|
||||
@@ -990,8 +1108,10 @@ struct BackendSettings: View {
|
||||
Form {
|
||||
Section("Inference") {
|
||||
Picker("Backend", selection: Binding(
|
||||
get: { mlxOnly ? "mlx" : (compatibleEnabled ? "compatible" : "ollama") },
|
||||
get: { !defaultCoreMLPath.isEmpty ? "coreML" : !defaultGGUFPath.isEmpty ? "gguf" : mlxOnly ? "mlx" : (compatibleEnabled ? "compatible" : "ollama") },
|
||||
set: { mode in
|
||||
if mode != "gguf" { defaultGGUFPath = "" }
|
||||
if mode != "coreML" { defaultCoreMLPath = "" }
|
||||
mlxOnly = mode == "mlx"
|
||||
compatibleEnabled = mode == "compatible"
|
||||
}
|
||||
@@ -999,11 +1119,14 @@ struct BackendSettings: View {
|
||||
Text("Prefer Ollama").tag("ollama")
|
||||
Text("OpenAI-compatible").tag("compatible")
|
||||
Text("MLX only").tag("mlx")
|
||||
if !defaultCoreMLPath.isEmpty { Text("Core ML").tag("coreML") }
|
||||
if !defaultGGUFPath.isEmpty { Text("Local GGUF").tag("gguf") }
|
||||
}
|
||||
Toggle("Fall back to MLX before output begins", isOn: $failover)
|
||||
.disabled(mlxOnly)
|
||||
.disabled(mlxOnly || !defaultGGUFPath.isEmpty || !defaultCoreMLPath.isEmpty)
|
||||
Toggle("Recall older matching messages in this conversation", isOn: $recall)
|
||||
}
|
||||
GGUFModels(selection: defaultGGUFPath, selectionDisabled: studio.running) { studio.selectGGUFModel($0) }
|
||||
Section("Ollama") {
|
||||
TextField("Server URL", text: $endpoint)
|
||||
.disabled(studio.managing)
|
||||
@@ -1030,11 +1153,13 @@ struct BackendSettings: View {
|
||||
Spacer()
|
||||
Text(ModelLibrarySize.label(entry.size))
|
||||
.foregroundStyle(.secondary).font(.caption)
|
||||
Button(model == entry.name && !mlxOnly && !compatibleEnabled ? "Selected" : "Use Model") {
|
||||
Button(defaultCoreMLPath.isEmpty && defaultGGUFPath.isEmpty && model == entry.name && !mlxOnly && !compatibleEnabled ? "Selected" : "Use Model") {
|
||||
model = entry.name
|
||||
defaultCoreMLPath = ""
|
||||
defaultGGUFPath = ""
|
||||
mlxOnly = false
|
||||
compatibleEnabled = false
|
||||
}.disabled(model == entry.name && !mlxOnly && !compatibleEnabled)
|
||||
}.disabled(defaultCoreMLPath.isEmpty && defaultGGUFPath.isEmpty && model == entry.name && !mlxOnly && !compatibleEnabled)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1066,7 +1191,7 @@ struct BackendSettings: View {
|
||||
}
|
||||
.formStyle(.grouped)
|
||||
.onAppear {
|
||||
if !mlxOnly && !compatibleEnabled && studio.modelListEndpoint != endpoint {
|
||||
if defaultCoreMLPath.isEmpty && defaultGGUFPath.isEmpty && !mlxOnly && !compatibleEnabled && studio.modelListEndpoint != endpoint {
|
||||
studio.refresh(endpoint: endpoint)
|
||||
}
|
||||
}
|
||||
@@ -1074,8 +1199,8 @@ struct BackendSettings: View {
|
||||
.fileImporter(isPresented: $pickingFolder, allowedContentTypes: [.folder]) { result in
|
||||
do {
|
||||
let url = try result.get()
|
||||
guard FileManager.default.fileExists(atPath: url.appending(path: "config.json").path) else {
|
||||
throw StudioError("This folder does not contain an MLX config.json.")
|
||||
guard MLXLibrary.isModel(at: url) else {
|
||||
throw StudioError("Choose a complete model folder with a readable config.json and all safetensors weight files.")
|
||||
}
|
||||
mlxPath = url.path
|
||||
folderError = ""
|
||||
@@ -1973,6 +2098,68 @@ struct RuntimeSettingsView: View {
|
||||
}
|
||||
}
|
||||
|
||||
enum ComposerPaste: Equatable, Sendable {
|
||||
case files([URL])
|
||||
case image(Data)
|
||||
|
||||
@MainActor static func read(_ pasteboard: NSPasteboard) -> Self? {
|
||||
if pasteboard.types?.contains(.fileURL) == true,
|
||||
let urls = pasteboard.readObjects(forClasses: [NSURL.self],
|
||||
options: [.urlReadingFileURLsOnly: true]) as? [URL],
|
||||
!urls.isEmpty {
|
||||
return .files(urls)
|
||||
}
|
||||
if let type = imageType(on: pasteboard), let data = pasteboard.data(forType: type) {
|
||||
return .image(data)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@MainActor private static func imageType(on pasteboard: NSPasteboard) -> NSPasteboard.PasteboardType? {
|
||||
let types = pasteboard.types ?? []
|
||||
if let preferred = [NSPasteboard.PasteboardType.png, .tiff].first(where: types.contains) {
|
||||
return preferred
|
||||
}
|
||||
return types.first { UTType($0.rawValue)?.conforms(to: .image) == true }
|
||||
}
|
||||
|
||||
@MainActor static func isAvailable(on pasteboard: NSPasteboard) -> Bool {
|
||||
pasteboard.types?.contains(.fileURL) == true || imageType(on: pasteboard) != nil
|
||||
}
|
||||
|
||||
func preview() throws -> ChatFilePreview {
|
||||
switch self {
|
||||
case .files(let urls):
|
||||
guard urls.count == 1, let url = urls.first else {
|
||||
throw StudioError("Paste one file at a time.")
|
||||
}
|
||||
return try ChatFilePreview.read(url)
|
||||
case .image(let data):
|
||||
return try ChatFilePreview.pastedImage(data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final class ComposerTextView: NSTextView {
|
||||
var pasteAttachment: ((ComposerPaste) -> Void)?
|
||||
|
||||
override func paste(_ sender: Any?) {
|
||||
if let pasteAttachment, let item = ComposerPaste.read(.general) {
|
||||
pasteAttachment(item)
|
||||
} else {
|
||||
super.paste(sender)
|
||||
}
|
||||
}
|
||||
|
||||
override func validateUserInterfaceItem(_ item: any NSValidatedUserInterfaceItem) -> Bool {
|
||||
if item.action == #selector(paste(_:)), isEditable, pasteAttachment != nil,
|
||||
ComposerPaste.isAvailable(on: .general) {
|
||||
return true
|
||||
}
|
||||
return super.validateUserInterfaceItem(item)
|
||||
}
|
||||
}
|
||||
|
||||
struct ChatComposerInput: NSViewRepresentable {
|
||||
@Binding var text: String
|
||||
var canSend: Bool
|
||||
@@ -1980,15 +2167,25 @@ struct ChatComposerInput: NSViewRepresentable {
|
||||
var autoCorrect: Bool
|
||||
var font: NSFont
|
||||
var send: () -> Void
|
||||
var pasteAttachment: (ComposerPaste) -> Void
|
||||
|
||||
func makeCoordinator() -> Coordinator { Coordinator(self) }
|
||||
|
||||
func makeNSView(context: Context) -> NSScrollView {
|
||||
let scroll = NSTextView.scrollableTextView()
|
||||
guard let editor = scroll.documentView as? NSTextView else { return scroll }
|
||||
let scroll = NSScrollView()
|
||||
scroll.hasVerticalScroller = true
|
||||
let editor = ComposerTextView(frame: scroll.contentView.bounds)
|
||||
editor.isVerticallyResizable = true
|
||||
editor.isHorizontallyResizable = false
|
||||
editor.autoresizingMask = [.width]
|
||||
editor.textContainer?.widthTracksTextView = true
|
||||
scroll.documentView = editor
|
||||
editor.isRichText = false
|
||||
editor.font = font
|
||||
editor.delegate = context.coordinator
|
||||
editor.pasteAttachment = { [weak coordinator = context.coordinator] item in
|
||||
coordinator?.parent.pasteAttachment(item)
|
||||
}
|
||||
editor.drawsBackground = false
|
||||
scroll.drawsBackground = false
|
||||
editor.setAccessibilityLabel("Message")
|
||||
|
||||
Reference in New Issue
Block a user