summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2023-10-30 14:17:15 +0800
committerGitHub <noreply@github.com>2023-10-30 14:17:15 +0800
commit23e9fb5bbf96cd4a93f4150659a99b4055623b9f (patch)
treee59e4b093516df206afe3242cfffc8762f64050a /src
parentba3cc4f15dd4b7457bbcacc64fcdbdbb0362d473 (diff)
downloadaichat-23e9fb5bbf96cd4a93f4150659a99b4055623b9f.tar.gz
feat: deprecate .clear command (#180)
Diffstat (limited to 'src')
-rw-r--r--src/cli.rs12
-rw-r--r--src/repl/handler.rs28
-rw-r--r--src/repl/mod.rs66
3 files changed, 58 insertions, 48 deletions
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<String>,
- /// 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<String>,
- /// 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<Option<String>>,
/// Specify the text-wrapping mode (no*, auto, <max-width>)
#[clap(short = 'w', long)]
pub wrap: Option<String>,
- /// 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<String>),
- 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<ReplCmdHandler>, line: &str) -> Result<bool> {
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 <name>\n\n"),
@@ -111,16 +111,13 @@ impl Repl {
Some(name) => handler.handle(ReplCmd::SetRole(name.to_string()))?,
None => print_now!("Usage: .role <name>\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 <file name>\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 => {