feat: settings for default model
This commit is contained in:
@@ -14,8 +14,8 @@ struct MLXServerApp: App {
|
|||||||
ContentView()
|
ContentView()
|
||||||
.environment(modelManager)
|
.environment(modelManager)
|
||||||
.task {
|
.task {
|
||||||
// Auto-load last used model (or default)
|
// Auto-load: configured default → last used → built-in default
|
||||||
let modelId = Preferences.lastModelId ?? ModelConfig.default.id
|
let modelId = Preferences.defaultModelId ?? Preferences.lastModelId ?? ModelConfig.default.id
|
||||||
if let config = ModelConfig.availableModels.first(where: { $0.id == modelId }) {
|
if let config = ModelConfig.availableModels.first(where: { $0.id == modelId }) {
|
||||||
await modelManager.loadModel(config)
|
await modelManager.loadModel(config)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,15 @@ enum Preferences {
|
|||||||
set { defaults.set(newValue, forKey: lastModelKey) }
|
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
|
// MARK: - System prompt
|
||||||
|
|
||||||
private static let systemPromptKey = "systemPrompt"
|
private static let systemPromptKey = "systemPrompt"
|
||||||
|
|||||||
@@ -5,9 +5,25 @@ struct SettingsView: View {
|
|||||||
@State private var apiPort: String = String(Preferences.apiPort)
|
@State private var apiPort: String = String(Preferences.apiPort)
|
||||||
@State private var apiAutoStart: Bool = Preferences.apiAutoStart
|
@State private var apiAutoStart: Bool = Preferences.apiAutoStart
|
||||||
@State private var idleUnloadMinutes: String = String(Preferences.idleUnloadMinutes)
|
@State private var idleUnloadMinutes: String = String(Preferences.idleUnloadMinutes)
|
||||||
|
@State private var defaultModelId: String = Preferences.defaultModelId ?? ModelConfig.default.id
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
Form {
|
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") {
|
Section("System Prompt") {
|
||||||
TextEditor(text: $systemPrompt)
|
TextEditor(text: $systemPrompt)
|
||||||
.font(.body.monospaced())
|
.font(.body.monospaced())
|
||||||
@@ -59,6 +75,6 @@ struct SettingsView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.formStyle(.grouped)
|
.formStyle(.grouped)
|
||||||
.frame(width: 450, height: 380)
|
.frame(width: 450, height: 460)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user