summaryrefslogtreecommitdiffstats
path: root/src/config
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2024-03-27 08:23:24 +0800
committerGitHub <noreply@github.com>2024-03-27 08:23:24 +0800
commita05c46253125a92a9c071e7310835dec2a06c0fc (patch)
tree725fe5508b7ab28fc1410382234ebecafdd4bf2c /src/config
parent3180d1d48573a6e12bb955ea0f6a312f80020fe6 (diff)
downloadaichat-a05c46253125a92a9c071e7310835dec2a06c0fc.tar.gz
fix: not dirty session when updating properties (#379)
Diffstat (limited to 'src/config')
-rw-r--r--src/config/mod.rs12
-rw-r--r--src/config/session.rs25
2 files changed, 28 insertions, 9 deletions
diff --git a/src/config/mod.rs b/src/config/mod.rs
index 02eb64b..0254365 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -361,10 +361,11 @@ impl Config {
}
}
- pub fn set_compress_threshold(&mut self, value: usize) {
- self.compress_threshold = value;
+ pub fn set_compress_threshold(&mut self, value: Option<usize>) {
if let Some(session) = self.session.as_mut() {
session.set_compress_threshold(value);
+ } else {
+ self.compress_threshold = value.unwrap_or_default();
}
}
@@ -561,7 +562,12 @@ impl Config {
self.set_temperature(value);
}
"compress_threshold" => {
- let value = value.parse().with_context(|| "Invalid value")?;
+ let value = if unset {
+ None
+ } else {
+ let value = value.parse().with_context(|| "Invalid value")?;
+ Some(value)
+ };
self.set_compress_threshold(value);
}
"save" => {
diff --git a/src/config/session.rs b/src/config/session.rs
index a52a86f..feade33 100644
--- a/src/config/session.rs
+++ b/src/config/session.rs
@@ -195,20 +195,33 @@ impl Session {
}
pub fn set_temperature(&mut self, value: Option<f64>) {
- self.temperature = value;
+ if self.temperature != value {
+ self.temperature = value;
+ self.dirty = true;
+ }
}
pub fn set_save_session(&mut self, value: bool) {
- self.save_session = value;
+ if self.save_session != value {
+ self.save_session = value;
+ self.dirty = true;
+ }
}
- pub fn set_compress_threshold(&mut self, value: usize) {
- self.compress_threshold = Some(value);
+ pub fn set_compress_threshold(&mut self, value: Option<usize>) {
+ if self.compress_threshold != value {
+ self.compress_threshold = value;
+ self.dirty = true;
+ }
}
pub fn set_model(&mut self, model: Model) -> Result<()> {
- self.model_id = model.id();
- self.model = model;
+ let model_id = model.id();
+ if self.model_id != model_id {
+ self.model_id = model_id;
+ self.model = model;
+ self.dirty = true;
+ }
Ok(())
}