From 23e9fb5bbf96cd4a93f4150659a99b4055623b9f Mon Sep 17 00:00:00 2001 From: sigoden Date: Mon, 30 Oct 2023 14:17:15 +0800 Subject: feat: deprecate .clear command (#180) --- README.md | 44 +++++++++++++++++------------------ src/cli.rs | 12 +++++----- src/repl/handler.rs | 28 +++++++++++------------ src/repl/mod.rs | 66 ++++++++++++++++++++++++++++++----------------------- 4 files changed, 80 insertions(+), 70 deletions(-) diff --git a/README.md b/README.md index a6c4a7e..ad4f591 100644 --- a/README.md +++ b/README.md @@ -140,20 +140,21 @@ The Chat REPL supports: ``` 〉.help +.help Print this help message .info Print system-wide information -.set Modify the configuration temporarily -.model Choose a model -.role Select a role -.clear role Clear the currently selected role -.session Start a session -.clear session End current session -.copy Copy the last output to the clipboard -.read Read the contents of a file and submit .edit Multi-line editing (CTRL+S to finish) -.help Print this help message +.model Switch LLM model +.role Use role +.exit role Leave current role +.session Start a context-aware chat session +.exit session End the current session +.set Modify the configuration parameters +.copy Copy the last reply to the clipboard +.read Import from file and submit .exit Exit the REPL Press Ctrl+C to abort readline, Ctrl+D to exit the REPL + ``` ### `.info` - view current configuration information @@ -190,17 +191,7 @@ AIChat also provides `.edit` command for multi-lines editing. } ``` -> Submit the multi-line text with `Ctrl+S`. - - -### `.set` - modify the configuration temporarily - -``` -〉.set dry_run true -〉.set highlight false -〉.set save false -〉.set temperature 1.2 -``` +> Submit with `Ctrl+S`. ### `.model` - choose a model @@ -233,7 +224,7 @@ emoji〉hello Clear current selected role: ``` -emoji〉.clear role +emoji〉.exit role 〉hello Hello there! How can I assist you today? @@ -254,7 +245,7 @@ temp)1 to 5, odd only temp)to 7 4070 1, 3, 5, 7 -temp).clear session +temp).exit session 〉 ``` @@ -269,6 +260,15 @@ aichat -m openai:gpt-4-32k -s # Create a session with a model aichat -s sh unzip a file # Run session in command mode ``` +### `.set` - modify the configuration temporarily + +``` +〉.set temperature 1.2 +〉.set dry_run true +〉.set highlight false +〉.set save false +``` + ## License Copyright (c) 2023 aichat-developers. diff --git a/src/cli.rs b/src/cli.rs index 2901ed4..ca4b4c2 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -3,28 +3,28 @@ use clap::Parser; #[derive(Parser, Debug)] #[command(author, version, about, long_about = None)] pub struct Cli { - /// List all models + /// List all available models #[clap(long)] pub list_models: bool, /// Choose a LLM model #[clap(short, long)] pub model: Option, - /// List all roles + /// List all available roles #[clap(long)] pub list_roles: bool, - /// Select a role + /// Choose a role #[clap(short, long)] pub role: Option, - /// List sessions + /// List all available sessions #[clap(long)] pub list_sessions: bool, - /// Initiate or continue a session + /// Initiate or reuse a session #[clap(short = 's', long)] pub session: Option>, /// Specify the text-wrapping mode (no*, auto, ) #[clap(short = 'w', long)] pub wrap: Option, - /// Print information + /// Print related information #[clap(long)] pub info: bool, /// Use light theme diff --git a/src/repl/handler.rs b/src/repl/handler.rs index e726661..d70abbe 100644 --- a/src/repl/handler.rs +++ b/src/repl/handler.rs @@ -15,13 +15,13 @@ use std::cell::RefCell; pub enum ReplCmd { Submit(String), + ViewInfo, SetModel(String), SetRole(String), - UpdateConfig(String), - ClearRole, - ViewInfo, + ExitRole, StartSession(Option), - EndSession, + ExitSession, + Set(String), Copy, ReadFile(String), } @@ -66,6 +66,10 @@ impl ReplCmdHandler { let _ = self.copy(&buffer); } } + ReplCmd::ViewInfo => { + let output = self.config.read().info()?; + print_now!("{}\n\n", output.trim_end()); + } ReplCmd::SetModel(name) => { self.config.write().set_model(&name)?; print_now!("\n"); @@ -74,26 +78,22 @@ impl ReplCmdHandler { let output = self.config.write().set_role(&name)?; print_now!("{}\n\n", output.trim_end()); } - ReplCmd::ClearRole => { + ReplCmd::ExitRole => { self.config.write().clear_role()?; print_now!("\n"); } - ReplCmd::ViewInfo => { - let output = self.config.read().info()?; - print_now!("{}\n\n", output.trim_end()); - } - ReplCmd::UpdateConfig(input) => { - self.config.write().update(&input)?; - print_now!("\n"); - } ReplCmd::StartSession(name) => { self.config.write().start_session(&name)?; print_now!("\n"); } - ReplCmd::EndSession => { + ReplCmd::ExitSession => { self.config.write().end_session()?; print_now!("\n"); } + ReplCmd::Set(input) => { + self.config.write().update(&input)?; + print_now!("\n"); + } ReplCmd::Copy => { let reply = self .config diff --git a/src/repl/mod.rs b/src/repl/mod.rs index 7a665ea..e5691dc 100644 --- a/src/repl/mod.rs +++ b/src/repl/mod.rs @@ -19,17 +19,17 @@ use reedline::Signal; use std::rc::Rc; pub const REPL_COMMANDS: [(&str, &str); 12] = [ + (".help", "Print this help message"), (".info", "Print system-wide information"), - (".set", "Modify the configuration temporarily"), - (".model", "Choose a model"), - (".role", "Select a role"), - (".clear role", "Clear the currently selected role"), - (".session", "Start a session"), - (".clear session", "End current session"), - (".copy", "Copy the last output to the clipboard"), - (".read", "Read the contents of a file and submit"), (".edit", "Multi-line editing (CTRL+S to finish)"), - (".help", "Print this help message"), + (".model", "Switch LLM model"), + (".role", "Use role"), + (".exit role", "Leave current role"), + (".session", "Start a context-aware chat session"), + (".exit session", "End the current session"), + (".set", "Modify the configuration parameters"), + (".copy", "Copy the last reply to the clipboard"), + (".read", "Import from file and submit"), (".exit", "Exit the REPL"), ]; @@ -85,24 +85,24 @@ impl Repl { _ => {} } } - handler.handle(ReplCmd::EndSession)?; + handler.handle(ReplCmd::ExitSession)?; Ok(()) } fn handle_line(&mut self, handler: &Rc, line: &str) -> Result { match parse_command(line) { Some((cmd, args)) => match cmd { - ".exit" => { - return Ok(true); - } ".help" => { dump_repl_help(); } - ".clear" => match args { - Some("role") => handler.handle(ReplCmd::ClearRole)?, - Some("session") => handler.handle(ReplCmd::EndSession)?, - _ => dump_unknown_command(), - }, + ".info" => { + handler.handle(ReplCmd::ViewInfo)?; + } + ".edit" => { + if let Some(text) = args { + handler.handle(ReplCmd::Submit(text.to_string()))?; + } + } ".model" => match args { Some(name) => handler.handle(ReplCmd::SetModel(name.to_string()))?, None => print_now!("Usage: .model \n\n"), @@ -111,16 +111,13 @@ impl Repl { Some(name) => handler.handle(ReplCmd::SetRole(name.to_string()))?, None => print_now!("Usage: .role \n\n"), }, - ".info" => { - handler.handle(ReplCmd::ViewInfo)?; + ".session" => { + handler.handle(ReplCmd::StartSession(args.map(|v| v.to_string())))?; } ".set" => { - handler.handle(ReplCmd::UpdateConfig(args.unwrap_or_default().to_string()))?; + handler.handle(ReplCmd::Set(args.unwrap_or_default().to_string()))?; self.prompt.sync_config(); } - ".session" => { - handler.handle(ReplCmd::StartSession(args.map(|v| v.to_string())))?; - } ".copy" => { handler.handle(ReplCmd::Copy)?; } @@ -128,11 +125,24 @@ impl Repl { Some(file) => handler.handle(ReplCmd::ReadFile(file.to_string()))?, None => print_now!("Usage: .read \n\n"), }, - ".edit" => { - if let Some(text) = args { - handler.handle(ReplCmd::Submit(text.to_string()))?; + ".exit" => match args { + Some("role") => handler.handle(ReplCmd::ExitRole)?, + Some("session") => handler.handle(ReplCmd::ExitSession)?, + Some(_) => dump_unknown_command(), + None => { + return Ok(true); } - } + }, + // deprecated + ".clear" => match args { + Some("role") => { + print_now!("Deprecated. Use '.exit role' instead.\n\n"); + } + Some("session") => { + print_now!("Deprecated. Use '.exit session' instead.\n\n"); + } + _ => dump_unknown_command(), + }, _ => dump_unknown_command(), }, None => { -- cgit v1.2.3