summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md11
-rw-r--r--src/config/mod.rs16
-rw-r--r--src/repl/mod.rs22
3 files changed, 40 insertions, 9 deletions
diff --git a/README.md b/README.md
index 0f52c90..fd40161 100644
--- a/README.md
+++ b/README.md
@@ -170,6 +170,7 @@ wrap no
wrap_code false
dry_run false
keybindings emacs
+prelude -
config_file /home/alice/.config/aichat/config.yaml
roles_file /home/alice/.config/aichat/roles.yaml
messages_file /home/alice/.config/aichat/messages.md
@@ -218,6 +219,16 @@ prompt: I want you to translate the sentences I write into emojis. I will write
temperature: null
```
+Temporarily use a role to send a message.
+```
+〉""" .role emoji
+hello world
+"""
+👋🌍
+
+〉
+```
+
### `.session` - context-aware conversation
By default, aichat behaves in a one-off request/response manner.
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)?;