From cc74be5d2163fbb1e9d57f85d5546857c6602446 Mon Sep 17 00:00:00 2001 From: sigoden Date: Tue, 30 Jul 2024 07:45:29 +0800 Subject: refactor: several improvements (#765) --- src/config/agent.rs | 2 +- src/config/input.rs | 3 +-- src/config/role.rs | 17 +++++++---------- 3 files changed, 9 insertions(+), 13 deletions(-) (limited to 'src/config') diff --git a/src/config/agent.rs b/src/config/agent.rs index 5f78e4b..0025095 100644 --- a/src/config/agent.rs +++ b/src/config/agent.rs @@ -409,7 +409,7 @@ fn builtin_variables() -> Vec<(&'static str, String)> { ("__os__", env::consts::OS.to_string()), ("__os_family__", env::consts::FAMILY.to_string()), ("__arch__", env::consts::ARCH.to_string()), - ("__shell__", detect_shell().name), + ("__shell__", SHELL.name.clone()), ("__locale__", sys_locale::get_locale().unwrap_or_default()), ( "__now__", diff --git a/src/config/input.rs b/src/config/input.rs index 6df3b71..fe1da51 100644 --- a/src/config/input.rs +++ b/src/config/input.rs @@ -9,13 +9,12 @@ use crate::utils::{base64_encode, sha256, AbortSignal}; use anyhow::{bail, Context, Result}; use fancy_regex::Regex; -use lazy_static::lazy_static; use std::{collections::HashMap, fs::File, io::Read, path::Path}; use unicode_width::{UnicodeWidthChar, UnicodeWidthStr}; const IMAGE_EXTS: [&str; 5] = ["png", "jpeg", "jpg", "webp", "gif"]; -lazy_static! { +lazy_static::lazy_static! { static ref URL_RE: Regex = Regex::new(r"^[A-Za-z0-9_-]{2,}:/").unwrap(); } diff --git a/src/config/role.rs b/src/config/role.rs index 3fc7696..31e894b 100644 --- a/src/config/role.rs +++ b/src/config/role.rs @@ -1,9 +1,6 @@ use super::*; -use crate::{ - client::{Message, MessageContent, MessageRole, Model}, - utils::{detect_os, detect_shell}, -}; +use crate::client::{Message, MessageContent, MessageRole, Model}; use anyhow::{Context, Result}; use serde::{Deserialize, Serialize}; @@ -315,17 +312,17 @@ fn parse_structure_prompt(prompt: &str) -> (&str, Vec<(&str, &str)>) { } fn shell_prompt() -> String { - let os = detect_os(); - let shell = detect_shell(); - let shell = shell.name.as_str(); + let os = OS.as_str(); + let shell = SHELL.name.as_str(); let combinator = if shell == "powershell" { - "\nIf multiple steps required try to combine them together using ';'.\nIf it already combined with '&&' try to replace it with ';'.".to_string() + "If multiple steps required try to combine them together using ';'.\nIf it already combined with '&&' try to replace it with ';'.".to_string() } else { - "\nIf multiple steps required try to combine them together using '&&'.".to_string() + "If multiple steps required try to combine them together using '&&'.".to_string() }; format!( r#"Provide only {shell} commands for {os} without any description. -Ensure the output is a valid {shell} command. {combinator} +Ensure the output is a valid {shell} command. +{combinator} If there is a lack of details, provide most logical solution. Output plain text only, without any markdown formatting."# ) -- cgit v1.2.3