From 6211d01a648e941fc69954d0855bcdcef98f27b9 Mon Sep 17 00:00:00 2001 From: sigoden Date: Sat, 14 Sep 2024 18:05:29 +0800 Subject: feat: add `.save agent-config` repl command (#870) --- src/repl/mod.rs | 48 ++++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-) (limited to 'src/repl') diff --git a/src/repl/mod.rs b/src/repl/mod.rs index 2f6c76f..09fa74d 100644 --- a/src/repl/mod.rs +++ b/src/repl/mod.rs @@ -31,7 +31,7 @@ lazy_static::lazy_static! { const MENU_NAME: &str = "completion_menu"; lazy_static::lazy_static! { - static ref REPL_COMMANDS: [ReplCommand; 31] = [ + static ref REPL_COMMANDS: [ReplCommand; 32] = [ 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()), @@ -58,7 +58,7 @@ lazy_static::lazy_static! { ReplCommand::new( ".save role", "Save the current role to file", - AssertState::True(StateFlags::ROLE) + AssertState::TrueFalse(StateFlags::ROLE, StateFlags::SESSION_EMPTY | StateFlags::SESSION), ), ReplCommand::new( ".exit role", @@ -70,6 +70,11 @@ lazy_static::lazy_static! { "Begin a session", AssertState::False(StateFlags::SESSION_EMPTY | StateFlags::SESSION), ), + ReplCommand::new( + ".clear messages", + "Erase messages in the current session", + AssertState::True(StateFlags::SESSION) + ), ReplCommand::new( ".info session", "View session info", @@ -80,11 +85,6 @@ lazy_static::lazy_static! { "Edit the current session", AssertState::True(StateFlags::SESSION_EMPTY | StateFlags::SESSION) ), - ReplCommand::new( - ".clear messages", - "Erase messages in the current session", - AssertState::True(StateFlags::SESSION) - ), ReplCommand::new( ".save session", "Save the current session to file", @@ -101,13 +101,13 @@ lazy_static::lazy_static! { AssertState::False(StateFlags::AGENT) ), ReplCommand::new( - ".info rag", - "View RAG info", + ".rebuild rag", + "Rebuild the RAG to sync document changes", AssertState::True(StateFlags::RAG), ), ReplCommand::new( - ".rebuild rag", - "Rebuild the RAG to sync document changes", + ".info rag", + "View RAG info", AssertState::True(StateFlags::RAG), ), ReplCommand::new( @@ -116,11 +116,6 @@ lazy_static::lazy_static! { AssertState::TrueFalse(StateFlags::RAG, StateFlags::AGENT), ), ReplCommand::new(".agent", "Use a agent", AssertState::bare()), - ReplCommand::new( - ".info agent", - "View agent info", - AssertState::True(StateFlags::AGENT), - ), ReplCommand::new( ".starter", "Use the conversation starter", @@ -131,6 +126,16 @@ lazy_static::lazy_static! { "Set agent variable", AssertState::True(StateFlags::AGENT) ), + ReplCommand::new( + ".save agent-config", + "Save the current agent config to file", + AssertState::True(StateFlags::AGENT) + ), + ReplCommand::new( + ".info agent", + "View agent info", + AssertState::True(StateFlags::AGENT), + ), ReplCommand::new( ".exit agent", "Leave the agent", @@ -148,7 +153,7 @@ lazy_static::lazy_static! { AssertState::pass() ), ReplCommand::new(".set", "Adjust runtime configuration", AssertState::pass()), - ReplCommand::new(".delete", "Delete roles/sessions/RAGs/agents-config", AssertState::pass()), + ReplCommand::new(".delete", "Delete roles/sessions/RAGs/agents", AssertState::pass()), ReplCommand::new(".copy", "Copy the last response", AssertState::pass()), ReplCommand::new(".exit", "Exit the REPL", AssertState::pass()), ]; @@ -326,8 +331,11 @@ impl Repl { Some(("session", name)) => { self.config.write().save_session(name)?; } + Some(("agent-config", _)) => { + self.config.write().save_agent_config()?; + } _ => { - println!(r#"Usage: .save [name]"#) + println!(r#"Usage: .save [name]"#) } } } @@ -343,7 +351,7 @@ impl Repl { self.config.write().edit_session()?; } _ => { - println!(r#"Usage: .edit session"#) + println!(r#"Usage: .edit "#) } } } @@ -398,7 +406,7 @@ impl Repl { Config::delete(&self.config, args)?; } _ => { - println!("Usage: .delete [roles|sessions|rags|agents-config]") + println!("Usage: .delete [roles|sessions|rags|agents]") } }, ".copy" => { -- cgit v1.2.3