Skip to content

Commit

Permalink
refactor: improve saving messages (#322)
Browse files Browse the repository at this point in the history
  • Loading branch information
sigoden authored Feb 25, 2024
1 parent a3fbf71 commit c773e8d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/config/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![];
Expand All @@ -94,7 +99,7 @@ impl Input {
}
chars.into_iter().collect()
} else {
text.clone()
text
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/config/role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit c773e8d

Please sign in to comment.