From 8da9fa5f4c24ace21fbf0d8d406db44fbc6537ab Mon Sep 17 00:00:00 2001 From: sigoden Date: Wed, 27 Mar 2024 07:33:21 +0800 Subject: feat: add sepereate `save_session` config item to session (#377) --- src/config/session.rs | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'src/config/session.rs') diff --git a/src/config/session.rs b/src/config/session.rs index 2e0d69f..a52a86f 100644 --- a/src/config/session.rs +++ b/src/config/session.rs @@ -1,5 +1,5 @@ use super::input::resolve_data_url; -use super::{Input, Model}; +use super::{Config, Input, Model}; use crate::client::{Message, MessageContent, MessageRole}; use crate::render::MarkdownRender; @@ -18,6 +18,8 @@ pub struct Session { #[serde(rename(serialize = "model", deserialize = "model"))] model_id: String, temperature: Option, + #[serde(default)] + save_session: bool, messages: Vec, #[serde(default)] data_urls: HashMap, @@ -37,10 +39,11 @@ pub struct Session { } impl Session { - pub fn new(name: &str, model: Model, temperature: Option) -> Self { + pub fn new(config: &Config, name: &str) -> Self { Self { - model_id: model.id(), - temperature, + model_id: config.model.id(), + temperature: config.temperature, + save_session: config.save_session, messages: vec![], compressed_messages: vec![], compress_threshold: None, @@ -49,7 +52,7 @@ impl Session { path: None, dirty: false, compressing: false, - model, + model: config.model.clone(), } } @@ -77,6 +80,10 @@ impl Session { self.temperature } + pub fn save_session(&self) -> bool { + self.save_session + } + pub fn need_compress(&self, current_compress_threshold: usize) -> bool { let threshold = self .compress_threshold @@ -102,6 +109,7 @@ impl Session { if let Some(temperature) = self.temperature() { data["temperature"] = temperature.into(); } + data["save_session"] = self.save_session.into(); data["total_tokens"] = tokens.into(); if let Some(conext_window) = self.model.max_input_tokens { data["max_input_tokens"] = conext_window.into(); @@ -129,6 +137,8 @@ impl Session { items.push(("temperature", temperature.to_string())); } + items.push(("save_session", self.save_session.to_string())); + if let Some(compress_threshold) = self.compress_threshold { items.push(("compress_threshold", compress_threshold.to_string())); } @@ -188,6 +198,10 @@ impl Session { self.temperature = value; } + pub fn set_save_session(&mut self, value: bool) { + self.save_session = value; + } + pub fn set_compress_threshold(&mut self, value: usize) { self.compress_threshold = Some(value); } -- cgit v1.2.3