From 34a6d13fb6e492860e1340ab7a97cbd1bdeb9d4d Mon Sep 17 00:00:00 2001 From: sigoden Date: Tue, 25 Jun 2024 18:47:11 +0800 Subject: refactor: compress session (#649) 1. no require compress_threshold >= 1000 2. no compressing in middle of function calling --- src/repl/mod.rs | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) (limited to 'src/repl/mod.rs') 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(()) } } -- cgit v1.2.3