mirror of
https://github.com/sigoden/aichat
synced 2024-11-16 06:15:26 +00:00
feat: deprecate .clear command (#180)
This commit is contained in:
parent
ba3cc4f15d
commit
23e9fb5bbf
46
README.md
46
README.md
@ -140,20 +140,21 @@ The Chat REPL supports:
|
||||
|
||||
```
|
||||
〉.help
|
||||
.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
|
||||
.info Print system-wide information
|
||||
.edit Multi-line editing (CTRL+S to finish)
|
||||
.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.
|
||||
|
12
src/cli.rs
12
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
|
||||
|
@ -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
|
||||
|
@ -19,17 +19,17 @@ use reedline::Signal;
|
||||
use std::rc::Rc;
|
||||
|
||||
pub const REPL_COMMANDS: [(&str, &str); 12] = [
|
||||
(".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"),
|
||||
(".info", "Print system-wide information"),
|
||||
(".edit", "Multi-line editing (CTRL+S to finish)"),
|
||||
(".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)?;
|
||||
}
|
||||
".set" => {
|
||||
handler.handle(ReplCmd::UpdateConfig(args.unwrap_or_default().to_string()))?;
|
||||
self.prompt.sync_config();
|
||||
}
|
||||
".session" => {
|
||||
handler.handle(ReplCmd::StartSession(args.map(|v| v.to_string())))?;
|
||||
}
|
||||
".set" => {
|
||||
handler.handle(ReplCmd::Set(args.unwrap_or_default().to_string()))?;
|
||||
self.prompt.sync_config();
|
||||
}
|
||||
".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 => {
|
||||
|
Loading…
Reference in New Issue
Block a user