summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/config/session.rs8
-rw-r--r--src/repl/mod.rs37
2 files changed, 19 insertions, 26 deletions
diff --git a/src/config/session.rs b/src/config/session.rs
index 3330f22..3057697 100644
--- a/src/config/session.rs
+++ b/src/config/session.rs
@@ -110,11 +110,9 @@ impl Session {
self.save_session
}
- pub fn need_compress(&self, current_compress_threshold: usize) -> bool {
- let threshold = self
- .compress_threshold
- .unwrap_or(current_compress_threshold);
- threshold >= 1000 && self.tokens() > threshold
+ pub fn need_compress(&self, global_compress_threshold: usize) -> bool {
+ let threshold = self.compress_threshold.unwrap_or(global_compress_threshold);
+ threshold > 0 && self.tokens() > threshold
}
pub fn tokens(&self) -> usize {
diff --git a/src/repl/mod.rs b/src/repl/mod.rs
index eb4e1d9..1613846 100644
--- a/src/repl/mod.rs
+++ b/src/repl/mod.rs
@@ -551,27 +551,6 @@ async fn ask(
config
.write()
.after_chat_completion(&mut input, &output, &tool_results)?;
-
- if config.write().should_compress_session() {
- let config = config.clone();
- let color = if config.read().light_theme {
- Color::LightGray
- } else {
- Color::DarkGray
- };
- print!(
- "\n📢 {}{}{}\n",
- color.normal().paint(
- "Session compression is being activated because the current tokens exceed `"
- ),
- color.italic().paint("compress_threshold"),
- color.normal().paint("`."),
- );
- tokio::spawn(async move {
- let _ = compress_session(&config).await;
- config.write().end_compressing_session();
- });
- }
if need_send_tool_results(&tool_results) {
ask(
config,
@@ -581,6 +560,22 @@ async fn ask(
)
.await
} else {
+ if config.write().should_compress_session() {
+ let config = config.clone();
+ let color = if config.read().light_theme {
+ Color::LightGray
+ } else {
+ Color::DarkGray
+ };
+ print!(
+ "\n📢 {}\n",
+ color.italic().paint("Compressing the session."),
+ );
+ tokio::spawn(async move {
+ let _ = compress_session(&config).await;
+ config.write().end_compressing_session();
+ });
+ }
Ok(())
}
}