diff options
| author | sigoden <sigoden@gmail.com> | 2023-11-07 23:07:42 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-07 23:07:42 +0800 |
| commit | c99bd015aa6ede7d306838c71d0ad6b89950a56b (patch) | |
| tree | a492524f1704f51215faba296516fc4c1c827dae /src | |
| parent | c256b6bae56c714adb7182bdbd02a74c27fd6b2d (diff) | |
| download | aichat-c99bd015aa6ede7d306838c71d0ad6b89950a56b.tar.gz | |
feat: temporarily use a role to send a message (#227)
Diffstat (limited to 'src')
| -rw-r--r-- | src/config/mod.rs | 16 | ||||
| -rw-r--r-- | src/repl/mod.rs | 22 |
2 files changed, 29 insertions, 9 deletions
diff --git a/src/config/mod.rs b/src/config/mod.rs index 3d4df7d..05c681b 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -344,7 +344,7 @@ impl Config { } pub fn sys_info(&self) -> Result<String> { - let path_info = |path: &Path| { + let display_path = |path: &Path| { let state = if path.exists() { "" } else { " ⚠️" }; format!("{}{state}", path.display()) }; @@ -355,6 +355,11 @@ impl Config { .wrap .clone() .map_or_else(|| String::from("no"), |v| v.to_string()); + let prelude = if self.prelude.is_empty() { + String::from("-") + } else { + self.prelude.clone() + }; let items = vec![ ("model", self.model.id()), ("temperature", temperature), @@ -365,10 +370,11 @@ impl Config { ("wrap_code", self.wrap_code.to_string()), ("light_theme", self.light_theme.to_string()), ("keybindings", self.keybindings.stringify().into()), - ("config_file", path_info(&Self::config_file()?)), - ("roles_file", path_info(&Self::roles_file()?)), - ("messages_file", path_info(&Self::messages_file()?)), - ("sessions_dir", path_info(&Self::sessions_dir()?)), + ("prelude", prelude), + ("config_file", display_path(&Self::config_file()?)), + ("roles_file", display_path(&Self::roles_file()?)), + ("messages_file", display_path(&Self::messages_file()?)), + ("sessions_dir", display_path(&Self::sessions_dir()?)), ]; let output = items .iter() diff --git a/src/repl/mod.rs b/src/repl/mod.rs index 75d2627..1143ab9 100644 --- a/src/repl/mod.rs +++ b/src/repl/mod.rs @@ -153,10 +153,24 @@ impl Repl { None => println!("Usage: .model <name>"), }, ".role" => match args { - Some(name) => { - self.config.write().set_role(name)?; - } - None => println!("Usage: .role <name>"), + Some(args) => match args.split_once(|c| c == '\n' || c == ' ') { + Some((name, text)) => { + let name = name.trim(); + let text = text.trim(); + let old_role = + self.config.read().role.as_ref().map(|v| v.name.to_string()); + self.config.write().set_role(name)?; + self.ask(text)?; + match old_role { + Some(old_role) => self.config.write().set_role(&old_role)?, + None => self.config.write().clear_role()?, + } + } + None => { + self.config.write().set_role(args)?; + } + }, + None => println!(r#"Usage: .role <name> [text...]"#), }, ".session" => { self.config.write().start_session(args)?; |
