Integrate Hugging Face model library and separate web actions
This commit is contained in:
+89
-52
@@ -84,6 +84,8 @@ struct ChatView: View {
|
||||
@AppStorage("studioMode") private var mode = StudioMode.normal
|
||||
@State private var columns: NavigationSplitViewVisibility = .all
|
||||
@State private var confirmDelete = false
|
||||
@State private var chatToDelete: Conversation?
|
||||
@State private var toolboxSection = ToolboxSheet.Section.servers
|
||||
@State private var search = ""
|
||||
@State private var renaming = false
|
||||
@State private var newTitle = ""
|
||||
@@ -106,6 +108,12 @@ struct ChatView: View {
|
||||
NavigationSplitView(columnVisibility: $columns) {
|
||||
List(visibleChats, selection: $studio.selected) { chat in
|
||||
Label(chat.title, systemImage: "bubble.left").tag(chat.id)
|
||||
.contextMenu {
|
||||
Button("Delete Chat", systemImage: "trash", role: .destructive) {
|
||||
chatToDelete = chat
|
||||
confirmDelete = true
|
||||
}
|
||||
}
|
||||
}
|
||||
.searchable(text: $search, placement: .sidebar, prompt: "Search Chats")
|
||||
.disabled(studio.running)
|
||||
@@ -121,7 +129,10 @@ struct ChatView: View {
|
||||
renaming = true
|
||||
}
|
||||
.disabled(studio.running || studio.selected == nil)
|
||||
Button("Delete Chat", systemImage: "trash") { confirmDelete = true }
|
||||
Button("Delete Chat", systemImage: "trash") {
|
||||
chatToDelete = studio.conversations.first { $0.id == studio.selected }
|
||||
confirmDelete = chatToDelete != nil
|
||||
}
|
||||
.disabled(studio.running || studio.selected == nil)
|
||||
}
|
||||
} detail: {
|
||||
@@ -168,7 +179,7 @@ struct ChatView: View {
|
||||
}.padding().frame(width: 560, height: 360)
|
||||
}
|
||||
.sheet(isPresented: $showingToolbox) {
|
||||
ToolboxSheet(studio: studio).frame(width: 880, height: 620)
|
||||
ToolboxSheet(studio: studio, section: $toolboxSection).frame(width: 880, height: 620)
|
||||
}
|
||||
.sheet(isPresented: $showingPromptBuilder) {
|
||||
PromptBuilder(customPrompt: $customPrompt) { instructions, global in
|
||||
@@ -194,10 +205,11 @@ struct ChatView: View {
|
||||
Button("Rename") { studio.renameSelectedChat(newTitle) }
|
||||
Button("Cancel", role: .cancel) {}
|
||||
}
|
||||
.confirmationDialog("Delete this conversation?", isPresented: $confirmDelete, titleVisibility: .visible) {
|
||||
Button("Delete Conversation", role: .destructive) { studio.deleteChat() }
|
||||
} message: {
|
||||
Text("This permanently removes the conversation and its recalled messages.")
|
||||
.alert("Delete Chat?", isPresented: $confirmDelete, presenting: chatToDelete) { chat in
|
||||
Button("Delete", role: .destructive) { studio.deleteChat(chat.id) }
|
||||
Button("Cancel", role: .cancel) {}
|
||||
} message: { chat in
|
||||
Text("“\(chat.title)” and its messages will be permanently deleted.")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -241,9 +253,9 @@ struct ChatView: View {
|
||||
Text(activity.joined(separator: " · "))
|
||||
.font(.caption).foregroundStyle(.secondary).lineLimit(2).textSelection(.enabled)
|
||||
}
|
||||
if showDebugOutput {
|
||||
if showDebugOutput, !studio.webDiagnostics.isEmpty || !studio.webStatus.isEmpty {
|
||||
let diagnostics = studio.webDiagnostics.isEmpty
|
||||
? [studio.webStatus.isEmpty ? "No web lookup for this message. Paste a URL or ask to search the web." : studio.webStatus]
|
||||
? [studio.webStatus]
|
||||
: studio.webDiagnostics
|
||||
ScrollView {
|
||||
Text(diagnostics.joined(separator: "\n"))
|
||||
@@ -274,7 +286,18 @@ struct ChatView: View {
|
||||
Button("Attach Files", systemImage: "paperclip", action: pickLocalFile)
|
||||
.labelStyle(.iconOnly).buttonStyle(.bordered)
|
||||
.help("Attach a local file or folder listing").disabled(studio.running)
|
||||
Button("Web Search", systemImage: "magnifyingglass") {
|
||||
toolboxSection = .search
|
||||
showingToolbox = true
|
||||
}
|
||||
.labelStyle(.iconOnly).buttonStyle(.bordered).help("Web Search")
|
||||
Button("Retrieve Page", systemImage: "link") {
|
||||
toolboxSection = .retrieve
|
||||
showingToolbox = true
|
||||
}
|
||||
.labelStyle(.iconOnly).buttonStyle(.bordered).help("Retrieve Page")
|
||||
Button {
|
||||
toolboxSection = .servers
|
||||
showingToolbox = true
|
||||
} label: {
|
||||
let count = studio.activeToolsets.count
|
||||
@@ -287,7 +310,7 @@ struct ChatView: View {
|
||||
Button("Resources", systemImage: "square.stack") { showingWorkspace = true }
|
||||
.buttonStyle(.borderless)
|
||||
}
|
||||
Label(mlxOnly ? "MLX" : activeModel.isEmpty ? "Choose a model" : activeModel,
|
||||
Label(mlxOnly && !mlxPath.isEmpty ? URL(fileURLWithPath: mlxPath).lastPathComponent : activeModel.isEmpty || mlxOnly ? "Choose a model" : activeModel,
|
||||
systemImage: mlxOnly ? "cpu" : "server.rack")
|
||||
.font(.caption).foregroundStyle(.secondary).lineLimit(1)
|
||||
.help(mlxOnly ? "On-device MLX" : "\(backendName) · \(activeEndpoint)")
|
||||
@@ -1240,7 +1263,13 @@ struct ChatComposerInput: NSViewRepresentable {
|
||||
struct ToolboxSheet: View {
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
@ObservedObject var studio: StudioModel
|
||||
@State private var section = "servers"
|
||||
enum Section: String, CaseIterable {
|
||||
case servers = "MCP Servers"
|
||||
case search = "Web Search"
|
||||
case retrieve = "Retrieve Page"
|
||||
}
|
||||
|
||||
@Binding var section: Section
|
||||
|
||||
var body: some View {
|
||||
VStack(spacing: 0) {
|
||||
@@ -1251,18 +1280,17 @@ struct ToolboxSheet: View {
|
||||
}
|
||||
.padding()
|
||||
Picker("Toolbox section", selection: $section) {
|
||||
Text("MCP Servers").tag("servers")
|
||||
Text("Web Search & Retrieval").tag("web")
|
||||
ForEach(Section.allCases, id: \.self) { Text($0.rawValue).tag($0) }
|
||||
}
|
||||
.pickerStyle(.segmented)
|
||||
.labelsHidden()
|
||||
.frame(maxWidth: .infinity)
|
||||
.padding([.horizontal, .bottom])
|
||||
Divider()
|
||||
if section == "servers" {
|
||||
if section == .servers {
|
||||
MCPSettings(studio: studio)
|
||||
} else {
|
||||
WebToolsView(studio: studio, done: { dismiss() })
|
||||
WebToolsView(studio: studio, section: $section, done: { dismiss() })
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1809,6 +1837,7 @@ struct WorkspaceDataView: View {
|
||||
|
||||
struct WebToolsView: View {
|
||||
@ObservedObject var studio: StudioModel
|
||||
@Binding var section: ToolboxSheet.Section
|
||||
let done: () -> Void
|
||||
@AppStorage("webSearchEndpoint") private var endpoint = ""
|
||||
@State private var query = ""
|
||||
@@ -1820,47 +1849,55 @@ struct WebToolsView: View {
|
||||
|
||||
var body: some View {
|
||||
Form {
|
||||
Section("Web Search") {
|
||||
TextField("SearXNG search URL", text: $endpoint, prompt: Text("https://your-server/search"))
|
||||
TextField("Search query", text: $query)
|
||||
HStack {
|
||||
Button("Search") {
|
||||
let source = endpoint
|
||||
let term = query
|
||||
run {
|
||||
results = []
|
||||
results = try await WebSearch.results(endpoint: source, query: term)
|
||||
if results.isEmpty { status = "No usable search results." }
|
||||
}
|
||||
}.disabled(operation != nil || query.isEmpty)
|
||||
Button("Search in Browser") { searchInBrowser() }.disabled(query.isEmpty)
|
||||
if operation != nil { Button("Cancel") { operation?.cancel() } }
|
||||
}
|
||||
Text("Search uses Bing by default. Enter a SearXNG URL to use your own instance.")
|
||||
.foregroundStyle(.secondary)
|
||||
ForEach(results) { result in
|
||||
VStack(alignment: .leading, spacing: 5) {
|
||||
Link(result.title, destination: result.url)
|
||||
Text(result.url.host ?? "").font(.caption).foregroundStyle(.secondary)
|
||||
if !result.snippet.isEmpty { Text(result.snippet) }
|
||||
HStack {
|
||||
Button("Retrieve") { retrieve(result.url.absoluteString) }.disabled(operation != nil)
|
||||
Button("Attach Result") { attach(result.title, result.reference) }
|
||||
.disabled(studio.running || operation != nil)
|
||||
if section == .search {
|
||||
Section("Web Search") {
|
||||
TextField("SearXNG search URL", text: $endpoint, prompt: Text("https://your-server/search"))
|
||||
TextField("Search query", text: $query)
|
||||
HStack {
|
||||
Button("Search") {
|
||||
let source = endpoint
|
||||
let term = query
|
||||
run {
|
||||
results = []
|
||||
results = try await WebSearch.results(endpoint: source, query: term)
|
||||
if results.isEmpty { status = "No usable search results." }
|
||||
}
|
||||
}.disabled(operation != nil || query.isEmpty)
|
||||
Button("Search in Browser") { searchInBrowser() }.disabled(query.isEmpty)
|
||||
if operation != nil { Button("Cancel") { operation?.cancel() } }
|
||||
}
|
||||
Text("Search uses Bing by default. In chat, ask to search the web and AI Studio fetches result pages and relevant links before the model replies. Enter a SearXNG URL to use your own search instance.")
|
||||
.foregroundStyle(.secondary)
|
||||
ForEach(results) { result in
|
||||
VStack(alignment: .leading, spacing: 5) {
|
||||
Link(result.title, destination: result.url)
|
||||
Text(result.url.host ?? "").font(.caption).foregroundStyle(.secondary)
|
||||
if !result.snippet.isEmpty { Text(result.snippet) }
|
||||
HStack {
|
||||
Button("Retrieve") {
|
||||
section = .retrieve
|
||||
retrieve(result.url.absoluteString)
|
||||
}.disabled(operation != nil)
|
||||
Button("Attach Result") { attach(result.title, result.reference) }
|
||||
.disabled(studio.running || operation != nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Section("Retrieve Page") {
|
||||
TextField("Page URL", text: $address, prompt: Text("https://example.com/article"))
|
||||
Button("Retrieve Page") { retrieve(address) }.disabled(operation != nil || address.isEmpty)
|
||||
if let page {
|
||||
Link(page.url.absoluteString, destination: page.url).lineLimit(2)
|
||||
ScrollView {
|
||||
Text(page.text).textSelection(.enabled).frame(maxWidth: .infinity, alignment: .leading)
|
||||
}.frame(height: 145)
|
||||
Button("Attach Page to Chat") { attach("Web page", page.reference) }
|
||||
.disabled(studio.running || operation != nil)
|
||||
} else {
|
||||
Section("Retrieve Page") {
|
||||
Text("Fetches readable text from a page. Paste a URL into chat to retrieve it automatically, or preview it here before attaching it.")
|
||||
.foregroundStyle(.secondary)
|
||||
TextField("Page URL", text: $address, prompt: Text("https://example.com/article"))
|
||||
Button("Retrieve Page") { retrieve(address) }.disabled(operation != nil || address.isEmpty)
|
||||
if let page {
|
||||
Link(page.url.absoluteString, destination: page.url).lineLimit(2)
|
||||
ScrollView {
|
||||
Text(page.text).textSelection(.enabled).frame(maxWidth: .infinity, alignment: .leading)
|
||||
}.frame(height: 145)
|
||||
Button("Attach Page to Chat") { attach("Web page", page.reference) }
|
||||
.disabled(studio.running || operation != nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
if !status.isEmpty { Text(status).foregroundStyle(.secondary).textSelection(.enabled) }
|
||||
|
||||
Reference in New Issue
Block a user