Repository Public
1// Author: Simon-Pierre Boucher — contact@spboucher.ai2// File: Packages/LocalChatUI/Sources/Features/Models/RecommendedView.swift3// Description: Device profile, per-task recommendations among the models the user has, and routing preferences. Every figure is measured or labelled as an estimate.4import SwiftUI5import LocalChatCore67struct RecommendedView: View {8 @Environment(AppModel.self) private var app910 var body: some View {11 ScrollView {12 VStack(alignment: .leading, spacing: DS.S.lg) {13 device14 recommendations15 routing16 }17 .padding(DS.S.lg)18 }19 .onAppear { app.refreshDevice() }20 }2122 private var device: some View {23 let d = app.device24 return VStack(alignment: .leading, spacing: DS.S.md) {25 SectionHeader("This device", subtitle: [d.chip, d.machine, "OS \(d.osVersion)"].compactMap { $0 }.joined(separator: " · "), symbol: "cpu")26 TileGrid(minimum: 150) {27 MetricTile("Memory", value: String(format: "%.0f", d.memoryGB), unit: "GB", symbol: "memorychip")28 MetricTile("Usable by a model", value: ByteFormat.memory(d.usableModelMemoryBytes), symbol: "square.stack.3d.up", footnote: "Budget used for the fit verdicts (estimate).")29 if let free = d.storageFreeBytes { MetricTile("Free storage", value: ByteFormat.string(free), symbol: "internaldrive", tint: DS.C.accent3) }30 if let p = d.performanceCores { MetricTile("CPU cores", value: "\(p)P" + (d.efficiencyCores.map { " + \($0)E" } ?? ""), symbol: "cpu") }31 MetricTile("Thermal state", value: d.thermal.rawValue.capitalized, symbol: "thermometer.medium",32 tint: d.thermal == .nominal ? DS.C.ok : d.thermal == .fair ? DS.C.warn : DS.C.danger)33 MetricTile("Low Power Mode", value: d.lowPowerMode ? "On" : "Off", symbol: "battery.50", tint: d.lowPowerMode ? DS.C.warn : DS.C.ok)34 }35 ForEach(BackendKind.allCases.filter { app.backendIssues[$0] != nil }, id: \.self) { kind in36 InlineNotice(.info, "\(kind.displayName): \(app.backendIssues[kind] ?? "")")37 }38 }39 }4041 @ViewBuilder private var recommendations: some View {42 let recs = app.recommendations43 SectionHeader("Recommended per task", subtitle: "Chosen among the models you have, from their declared capabilities, size and measured speed.", symbol: "wand.and.stars")44 if recs.isEmpty {45 InlineNotice(.info, "No recommendation yet: install a model that fits this device, or add a trusted remote node.")46 } else {47 LazyVGrid(columns: [GridItem(.adaptive(minimum: 300), spacing: DS.S.md)], alignment: .leading, spacing: DS.S.md) {48 ForEach(recs) { rec in49 VStack(alignment: .leading, spacing: 6) {50 Label(rec.category.title, systemImage: rec.category.symbol).font(DS.F.micro).foregroundStyle(DS.C.accent)51 Text(rec.model.name).font(DS.F.headline).foregroundStyle(DS.C.text).lineLimit(1).truncationMode(.middle)52 HStack(spacing: 5) { BackendBadge(rec.model.backend); FitBadge(rec.verdict) }53 Text(rec.reason).font(DS.F.caption).foregroundStyle(DS.C.text2).fixedSize(horizontal: false, vertical: true)54 }55 .frame(maxWidth: .infinity, alignment: .leading).card(padding: DS.S.md)56 }57 }58 }59 }6061 private var routing: some View {62 VStack(alignment: .leading, spacing: DS.S.sm) {63 SectionHeader("Routing preferences", subtitle: "Used when a conversation is set to Auto. You can always pick a model yourself.", symbol: "arrow.triangle.branch")64 VStack(spacing: 0) {65 SettingRow("Allow remote nodes", detail: "Off: the router never sends a prompt off this device.") {66 Toggle("", isOn: Binding(get: { app.preferences.routing.allowRemote }, set: { v in app.updatePreferences { $0.routing.allowRemote = v } })).labelsHidden()67 }68 Divider()69 SettingRow("Prefer speed", detail: "Favor models with the highest measured tokens per second.") {70 Toggle("", isOn: Binding(get: { app.preferences.routing.preferSpeed }, set: { v in app.updatePreferences { $0.routing.preferSpeed = v } })).labelsHidden()71 }72 ForEach(TaskCategory.allCases.filter { $0 != .embeddings }) { task in73 Divider()74 SettingRow(task.title, detail: "Always use this model for \(task.title.lowercased()).") {75 Picker("", selection: Binding(get: { app.preferences.routing.pinned[task.rawValue] ?? "" },76 set: { v in app.updatePreferences { $0.routing.pinned[task.rawValue] = v.isEmpty ? nil : v } })) {77 Text("Automatic").tag("")78 ForEach(app.chatModels) { Text($0.name).tag($0.id) }79 }80 .labelsHidden().frame(maxWidth: 220)81 }82 }83 }84 .card(padding: DS.S.md)85 if app.preferences.routing.allowRemote { InlineNotice(.warning, "With remote nodes allowed, Auto conversations may send prompts to the nodes you added.") }86 }87 }88}89