feat: settings for default model

This commit is contained in:
2026-03-17 20:20:54 +01:00
parent aa2712555a
commit 20f9c0bcc4
3 changed files with 28 additions and 3 deletions

View File

@@ -14,8 +14,8 @@ struct MLXServerApp: App {
ContentView()
.environment(modelManager)
.task {
// Auto-load last used model (or default)
let modelId = Preferences.lastModelId ?? ModelConfig.default.id
// Auto-load: configured default last used built-in default
let modelId = Preferences.defaultModelId ?? Preferences.lastModelId ?? ModelConfig.default.id
if let config = ModelConfig.availableModels.first(where: { $0.id == modelId }) {
await modelManager.loadModel(config)
}

View File

@@ -13,6 +13,15 @@ enum Preferences {
set { defaults.set(newValue, forKey: lastModelKey) }
}
// MARK: - Default startup model
private static let defaultModelKey = "defaultModelId"
static var defaultModelId: String? {
get { defaults.string(forKey: defaultModelKey) }
set { defaults.set(newValue, forKey: defaultModelKey) }
}
// MARK: - System prompt
private static let systemPromptKey = "systemPrompt"

View File

@@ -5,9 +5,25 @@ struct SettingsView: View {
@State private var apiPort: String = String(Preferences.apiPort)
@State private var apiAutoStart: Bool = Preferences.apiAutoStart
@State private var idleUnloadMinutes: String = String(Preferences.idleUnloadMinutes)
@State private var defaultModelId: String = Preferences.defaultModelId ?? ModelConfig.default.id
var body: some View {
Form {
Section("Startup") {
Picker("Default model", selection: $defaultModelId) {
ForEach(ModelConfig.availableModels) { model in
Text(model.displayName).tag(model.id)
}
}
.onChange(of: defaultModelId) {
Preferences.defaultModelId = defaultModelId
}
Text("The model to load automatically when the app starts.")
.font(.caption)
.foregroundStyle(.secondary)
}
Section("System Prompt") {
TextEditor(text: $systemPrompt)
.font(.body.monospaced())
@@ -59,6 +75,6 @@ struct SettingsView: View {
}
}
.formStyle(.grouped)
.frame(width: 450, height: 380)
.frame(width: 450, height: 460)
}
}