Store preferences by model profile
This commit is contained in:
42
src/app.rs
42
src/app.rs
@@ -16,7 +16,7 @@ use preferences::{parse_optional_gib, parse_streaming_cache};
|
||||
|
||||
use crate::config::{
|
||||
Config, DevBrainConfig, EndpointConfig, GitConfig, GitDiffAlgorithm, GitDiffLayout,
|
||||
GitDiffWhitespace, PermissionMode,
|
||||
GitDiffWhitespace, ModelPreferences, PermissionMode,
|
||||
};
|
||||
use crate::database::{Database, ProjectWithSessions, SessionState, StoredMessage};
|
||||
#[cfg(any(target_os = "macos", test))]
|
||||
@@ -37,7 +37,7 @@ use crate::settings::{
|
||||
use iced::widget::{markdown, scrollable, text_editor};
|
||||
use iced::{Size, Subscription, Task, keyboard, mouse, window};
|
||||
use rfd::AsyncFileDialog;
|
||||
use std::collections::{HashMap, HashSet, VecDeque};
|
||||
use std::collections::{BTreeMap, HashMap, HashSet, VecDeque};
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::Arc;
|
||||
@@ -261,6 +261,7 @@ pub(super) enum PreferenceSection {
|
||||
Endpoint,
|
||||
DevBrain,
|
||||
Git,
|
||||
Prompt,
|
||||
Generation,
|
||||
Execution,
|
||||
Acceleration,
|
||||
@@ -269,11 +270,12 @@ pub(super) enum PreferenceSection {
|
||||
}
|
||||
|
||||
impl PreferenceSection {
|
||||
const ALL: [Self; 9] = [
|
||||
const ALL: [Self; 10] = [
|
||||
Self::Model,
|
||||
Self::Endpoint,
|
||||
Self::DevBrain,
|
||||
Self::Git,
|
||||
Self::Prompt,
|
||||
Self::Generation,
|
||||
Self::Execution,
|
||||
Self::Acceleration,
|
||||
@@ -287,6 +289,7 @@ impl PreferenceSection {
|
||||
Self::Endpoint => "preferences-endpoint",
|
||||
Self::DevBrain => "preferences-dev-brain",
|
||||
Self::Git => "preferences-git",
|
||||
Self::Prompt => "preferences-prompt",
|
||||
Self::Generation => "preferences-generation",
|
||||
Self::Execution => "preferences-execution",
|
||||
Self::Acceleration => "preferences-acceleration",
|
||||
@@ -301,6 +304,7 @@ impl PreferenceSection {
|
||||
Self::Endpoint => "Local endpoint",
|
||||
Self::DevBrain => "Dev Brain",
|
||||
Self::Git => "Git diffs",
|
||||
Self::Prompt => "Prompt",
|
||||
Self::Generation => "Generation",
|
||||
Self::Execution => "Execution",
|
||||
Self::Acceleration => "Acceleration & memory",
|
||||
@@ -350,6 +354,10 @@ pub(crate) enum Message {
|
||||
FocusNext,
|
||||
FocusPrevious,
|
||||
PreferenceModelChanged(ModelChoice),
|
||||
PreferenceDefaultReasoningChanged(ReasoningMode),
|
||||
PreferenceGenerationModelChanged(ModelChoice),
|
||||
PreferenceGenerationReasoningChanged(ReasoningMode),
|
||||
PreferenceAccelerationModelChanged(ModelChoice),
|
||||
PreferencePermissionModeChanged(PermissionMode),
|
||||
PreferenceLegacyMtpChanged(bool),
|
||||
PreferenceDsparkChanged(bool),
|
||||
@@ -379,7 +387,6 @@ pub(crate) enum Message {
|
||||
PreferenceTopPChanged(String),
|
||||
PreferenceMinPChanged(String),
|
||||
PreferenceSeedChanged(String),
|
||||
PreferenceReasoningChanged(ReasoningMode),
|
||||
PreferenceCpuThreadsChanged(String),
|
||||
PreferencePowerChanged(String),
|
||||
PreferencePrefillChunkChanged(String),
|
||||
@@ -505,7 +512,7 @@ impl App {
|
||||
sweep_orphan_checkpoints(&kv_cache_path(), &projects);
|
||||
#[cfg(target_os = "macos")]
|
||||
crate::engine::sweep_transient_cache(&transient_cache_path());
|
||||
let context_limit = config.generation.context_tokens.max(0) as u32;
|
||||
let context_limit = config.active_generation().context_tokens.max(0) as u32;
|
||||
let default_permission_mode = config.default_permission_mode;
|
||||
// Reopen on the project we left, with a fresh draft chat.
|
||||
let last_project = config
|
||||
@@ -658,7 +665,7 @@ impl App {
|
||||
fn failed(error: String, main_window: window::Id) -> Self {
|
||||
let config = Config::default();
|
||||
let preference_draft = PreferenceDraft::from_saved(&config);
|
||||
let context_limit = config.generation.context_tokens.max(0) as u32;
|
||||
let context_limit = config.active_generation().context_tokens.max(0) as u32;
|
||||
let default_permission_mode = config.default_permission_mode;
|
||||
let metrics = Arc::new(Metrics::new(&application_support_path().join("kv-cache")));
|
||||
let metrics_snapshot = metrics.snapshot();
|
||||
@@ -811,7 +818,7 @@ impl App {
|
||||
context_used: std::mem::take(&mut self.context_used),
|
||||
context_limit: std::mem::replace(
|
||||
&mut self.context_limit,
|
||||
self.config.generation.context_tokens.max(0) as u32,
|
||||
self.config.active_generation().context_tokens.max(0) as u32,
|
||||
),
|
||||
tokens_per_second: self.tokens_per_second.take(),
|
||||
detail_tab: std::mem::take(&mut self.detail_tab),
|
||||
@@ -1545,8 +1552,7 @@ impl App {
|
||||
Some("Stop all active generations before changing thinking mode.".into());
|
||||
} else if !self
|
||||
.config
|
||||
.generation
|
||||
.supported_reasoning_modes()
|
||||
.supported_reasoning_modes(self.config.model)
|
||||
.contains(&mode)
|
||||
{
|
||||
self.error = Some(
|
||||
@@ -1554,11 +1560,23 @@ impl App {
|
||||
);
|
||||
} else {
|
||||
let mut config = self.config.clone();
|
||||
config.generation.reasoning_mode = mode;
|
||||
config
|
||||
.model_profiles
|
||||
.entry(config.model)
|
||||
.or_default()
|
||||
.reasoning_mode = mode;
|
||||
match config.save(&config_path()) {
|
||||
Ok(()) => {
|
||||
self.config = config;
|
||||
self.preference_draft.reasoning_mode = mode;
|
||||
self.preference_draft.default_reasoning_mode = mode;
|
||||
self.preference_draft
|
||||
.load_generation(self.config.model, mode);
|
||||
self.context_limit =
|
||||
self.config.active_generation().context_tokens.max(0) as u32;
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
self.agent_tools = None;
|
||||
}
|
||||
self.error = None;
|
||||
#[cfg(target_os = "macos")]
|
||||
preferences::update_runtime_config(&self.runtime_config, &self.config);
|
||||
@@ -1812,7 +1830,7 @@ impl App {
|
||||
self.context_limit = if limit > 0 {
|
||||
limit as u32
|
||||
} else {
|
||||
self.config.generation.context_tokens.max(0) as u32
|
||||
self.config.active_generation().context_tokens.max(0) as u32
|
||||
};
|
||||
self.tokens_per_second = tokens_per_second;
|
||||
self.permission_mode = permission_mode;
|
||||
|
||||
Reference in New Issue
Block a user