summaryrefslogtreecommitdiffstats
path: root/src/config
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2024-04-20 09:21:52 +0800
committerGitHub <noreply@github.com>2024-04-20 09:21:52 +0800
commit5d763fc10c4e3d40268ead473ccb0000b4923bd1 (patch)
tree5c8e498edfed073dc4e82f34cfb96a3f18c7ad7c /src/config
parent8b806db85791a23f9725adbe09f414464adb6605 (diff)
downloadaichat-5d763fc10c4e3d40268ead473ccb0000b4923bd1.tar.gz
feat: add `.prompt` repl command (#420)
Diffstat (limited to 'src/config')
-rw-r--r--src/config/mod.rs5
-rw-r--r--src/config/role.rs9
2 files changed, 14 insertions, 0 deletions
diff --git a/src/config/mod.rs b/src/config/mod.rs
index 1fe97af..2a3a866 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -301,6 +301,11 @@ impl Config {
Ok(path)
}
+ pub fn set_prompt(&mut self, prompt: &str) -> Result<()> {
+ let role = Role::temp(prompt);
+ self.set_role_obj(role)
+ }
+
pub fn set_role(&mut self, name: &str) -> Result<()> {
let role = self.retrieve_role(name)?;
self.set_role_obj(role)
diff --git a/src/config/role.rs b/src/config/role.rs
index 5a6ff3a..50d5b5e 100644
--- a/src/config/role.rs
+++ b/src/config/role.rs
@@ -7,6 +7,7 @@ use crate::{
use anyhow::{Context, Result};
use serde::{Deserialize, Serialize};
+pub const TEMP_ROLE: &str = "%%";
pub const SHELL_ROLE: &str = "%shell%";
pub const EXPLAIN_ROLE: &str = "%explain%";
pub const CODE_ROLE: &str = "%code%";
@@ -24,6 +25,14 @@ pub struct Role {
}
impl Role {
+ pub fn temp(prompt: &str) -> Self {
+ Self {
+ name: TEMP_ROLE.into(),
+ prompt: prompt.into(),
+ temperature: None,
+ }
+ }
+
pub fn find_system_role(name: &str) -> Option<Self> {
match name {
SHELL_ROLE => Some(Self::shell()),