From 05d20f207fedf03c2a564438a0d44a2d85d4ed2d Mon Sep 17 00:00:00 2001 From: sigoden Date: Thu, 9 Mar 2023 15:30:39 +0800 Subject: feat: add remain tokens indicator and max tokens guard (#50) --- src/repl/handler.rs | 2 +- src/repl/init.rs | 7 ++++++- src/repl/mod.rs | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) (limited to 'src/repl') diff --git a/src/repl/handler.rs b/src/repl/handler.rs index b5651c3..30a75c5 100644 --- a/src/repl/handler.rs +++ b/src/repl/handler.rs @@ -63,7 +63,7 @@ impl ReplCmdHandler { wg.wait(); let buffer = ret?; self.config.lock().save_message(&input, &buffer)?; - self.config.lock().record_conversation(&input, &buffer)?; + self.config.lock().save_conversation(&input, &buffer)?; *self.reply.borrow_mut() = buffer; } ReplCmd::SetRole(name) => { diff --git a/src/repl/init.rs b/src/repl/init.rs index a14265c..faafd9d 100644 --- a/src/repl/init.rs +++ b/src/repl/init.rs @@ -135,7 +135,12 @@ impl Prompt for ReplPrompt { } fn render_prompt_right(&self) -> Cow { - Cow::Borrowed("") + let config = self.0.lock(); + if let Some(conversation) = config.conversation.as_ref() { + conversation.reamind_tokens().to_string().into() + } else { + Cow::Borrowed("") + } } fn render_prompt_indicator(&self, _prompt_mode: reedline::PromptEditMode) -> Cow { diff --git a/src/repl/mod.rs b/src/repl/mod.rs index 9407bcf..661be75 100644 --- a/src/repl/mod.rs +++ b/src/repl/mod.rs @@ -22,7 +22,7 @@ pub const REPL_COMMANDS: [(&str, &str, bool); 12] = [ (".role", "Select a role", false), (".clear role", "Clear the currently selected role", false), (".conversation", "Start a conversation.", false), - (".clear conversation", "End the conversation.", false), + (".clear conversation", "End current conversation.", false), (".history", "Print the history", false), (".clear history", "Clear the history", false), (".editor", "Enter editor mode for multiline input", true), -- cgit v1.2.3