summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2024-02-25 20:09:40 +0800
committerGitHub <noreply@github.com>2024-02-25 20:09:40 +0800
commitc773e8d2e1e737fdda2f7bfe8e97c0411a1ba172 (patch)
tree2ca04eae4752e368814d9f5d7c38c3617ba7fbb5 /src
parenta3fbf71c1c1a1bba27d8a546e63ae54605e1fadc (diff)
downloadaichat-c773e8d2e1e737fdda2f7bfe8e97c0411a1ba172.tar.gz
refactor: improve saving messages (#322)
Diffstat (limited to 'src')
-rw-r--r--src/config/input.rs9
-rw-r--r--src/config/role.rs4
-rw-r--r--src/main.rs1
3 files changed, 10 insertions, 4 deletions
diff --git a/src/config/input.rs b/src/config/input.rs
index 6fa1b1c..cb3cdf2 100644
--- a/src/config/input.rs
+++ b/src/config/input.rs
@@ -80,7 +80,12 @@ impl Input {
}
pub fn summary(&self) -> String {
- let text = &self.text;
+ let text: String = self
+ .text
+ .trim()
+ .chars()
+ .map(|c| if c.is_control() { ' ' } else { c })
+ .collect();
if text.width_cjk() > 70 {
let mut sum_width = 0;
let mut chars = vec![];
@@ -94,7 +99,7 @@ impl Input {
}
chars.into_iter().collect()
} else {
- text.clone()
+ text
}
}
diff --git a/src/config/role.rs b/src/config/role.rs
index ff60b55..f963874 100644
--- a/src/config/role.rs
+++ b/src/config/role.rs
@@ -29,7 +29,7 @@ impl Role {
None => &shell,
};
Self {
- name: "__builtin__".into(),
+ name: "__for_execute__".into(),
prompt: format!(
r#"Provide only {shell} commands for {os} without any description.
If there is a lack of details, provide most logical solution.
@@ -44,7 +44,7 @@ Do not provide markdown formatting such as ```"#
pub fn for_describe() -> Self {
Self {
- name: "__builtin__".into(),
+ name: "__for_describe__".into(),
prompt: r#"Provide a terse, single sentence description of the given shell command.
Describe each argument and option of the command.
Provide short responses in about 80 words.
diff --git a/src/main.rs b/src/main.rs
index 6c3d54f..bd319e1 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -145,6 +145,7 @@ fn execute(config: &GlobalConfig, text: &str) -> Result<()> {
let client = init_client(config)?;
config.read().maybe_print_send_tokens(&input);
let eval_str = client.send_message(input.clone())?;
+ config.write().save_message(input, &eval_str)?;
let render_options = config.read().get_render_options()?;
let mut markdown_render = MarkdownRender::init(render_options)?;
if config.read().dry_run {