From 7c6dac061b2a33aae334c08b725e02459c5e9ade Mon Sep 17 00:00:00 2001 From: sigoden Date: Mon, 1 Jul 2024 20:19:41 +0800 Subject: feat: support `.rebuild rag` repl command(#672) --- src/repl/mod.rs | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'src/repl') diff --git a/src/repl/mod.rs b/src/repl/mod.rs index 6c15002..2111c48 100644 --- a/src/repl/mod.rs +++ b/src/repl/mod.rs @@ -33,7 +33,7 @@ lazy_static! { const MENU_NAME: &str = "completion_menu"; lazy_static! { - static ref REPL_COMMANDS: [ReplCommand; 26] = [ + static ref REPL_COMMANDS: [ReplCommand; 27] = [ ReplCommand::new(".help", "Show this help message", AssertState::pass()), ReplCommand::new(".info", "View system info", AssertState::pass()), ReplCommand::new(".model", "Change the current LLM", AssertState::pass()), @@ -89,17 +89,22 @@ lazy_static! { ), ReplCommand::new( ".rag", - "Init or use a rag", + "Init or use the RAG", AssertState::False(StateFlags::AGENT) ), ReplCommand::new( ".info rag", - "View rag info", + "View RAG info", + AssertState::True(StateFlags::RAG), + ), + ReplCommand::new( + ".rebuild rag", + "Rebuild the RAG to sync document changes", AssertState::True(StateFlags::RAG), ), ReplCommand::new( ".exit rag", - "Leave the rag", + "Leave the RAG", AssertState::TrueFalse(StateFlags::RAG, StateFlags::AGENT), ), ReplCommand::new(".agent", "Use a agent", AssertState::bare()), @@ -314,6 +319,19 @@ Tips: use to autocomplete conversation starter text. } } } + ".rebuild" => { + match args.map(|v| match v.split_once(' ') { + Some((subcmd, args)) => (subcmd, Some(args.trim())), + None => (v, None), + }) { + Some(("rag", _)) => { + Config::rebuild_rag(&self.config, self.abort_signal.clone()).await?; + } + _ => { + println!(r#"Usage: .rebuild rag"#) + } + } + } ".file" => match args { Some(args) => { let (files, text) = split_files_text(args); -- cgit v1.2.3