Skip to content

Commit

Permalink
fix: not dirty session when updating properties (#379)
Browse files Browse the repository at this point in the history
  • Loading branch information
sigoden authored Mar 27, 2024
1 parent 3180d1d commit a05c462
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ model openai:gpt-3.5-turbo
temperature -
dry_run false
save true
save_session true
highlight true
light_theme false
wrap no
Expand Down
12 changes: 9 additions & 3 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -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" => {
Expand Down
25 changes: 19 additions & 6 deletions src/config/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}

Expand Down

0 comments on commit a05c462

Please sign in to comment.