diff options
| author | sigoden <sigoden@gmail.com> | 2024-06-25 18:47:11 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-25 18:47:11 +0800 |
| commit | 34a6d13fb6e492860e1340ab7a97cbd1bdeb9d4d (patch) | |
| tree | a3e17b41c71963a7bf89e425c18bd059df296e42 /src/repl | |
| parent | aeeca1c010117d7455cdbe2652769ca3fad3bb36 (diff) | |
| download | aichat-34a6d13fb6e492860e1340ab7a97cbd1bdeb9d4d.tar.gz | |
refactor: compress session (#649)
1. no require compress_threshold >= 1000
2. no compressing in middle of function calling
Diffstat (limited to 'src/repl')
| -rw-r--r-- | src/repl/mod.rs | 37 |
1 files changed, 16 insertions, 21 deletions
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(()) } } |
