diff options
| author | sigoden <sigoden@gmail.com> | 2025-06-28 19:17:43 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-28 19:17:43 +0800 |
| commit | 419790fb74fbaf47d54519238b5a542a3875961e (patch) | |
| tree | 8917db58a4a77a514079bf115d670a3f82003c03 | |
| parent | bad300bbce72dff6f085fc8b94e8ffbdd103f47f (diff) | |
| download | aichat-419790fb74fbaf47d54519238b5a542a3875961e.tar.gz | |
chore: clippy (#1334)
| -rw-r--r-- | src/cli.rs | 4 | ||||
| -rw-r--r-- | src/client/bedrock.rs | 8 | ||||
| -rw-r--r-- | src/client/model.rs | 3 | ||||
| -rw-r--r-- | src/config/input.rs | 2 | ||||
| -rw-r--r-- | src/config/mod.rs | 8 | ||||
| -rw-r--r-- | src/config/role.rs | 8 | ||||
| -rw-r--r-- | src/config/session.rs | 4 | ||||
| -rw-r--r-- | src/main.rs | 4 | ||||
| -rw-r--r-- | src/rag/mod.rs | 2 | ||||
| -rw-r--r-- | src/render/stream.rs | 2 | ||||
| -rw-r--r-- | src/repl/mod.rs | 14 | ||||
| -rw-r--r-- | src/serve.rs | 2 | ||||
| -rw-r--r-- | src/utils/clipboard.rs | 4 | ||||
| -rw-r--r-- | src/utils/command.rs | 2 | ||||
| -rw-r--r-- | src/utils/crypto.rs | 2 | ||||
| -rw-r--r-- | src/utils/mod.rs | 2 | ||||
| -rw-r--r-- | src/utils/request.rs | 12 | ||||
| -rw-r--r-- | src/utils/variables.rs | 2 |
18 files changed, 39 insertions, 46 deletions
@@ -113,14 +113,14 @@ impl Cli { if stdin_text.is_empty() { Ok(Some(text)) } else { - Ok(Some(format!("{} -- {}", text, stdin_text))) + Ok(Some(format!("{text} -- {stdin_text}"))) } } else { let text = self.text.join(" "); if stdin_text.is_empty() { Ok(Some(text)) } else { - Ok(Some(format!("{}\n{}", text, stdin_text))) + Ok(Some(format!("{text}\n{stdin_text}"))) } } } diff --git a/src/client/bedrock.rs b/src/client/bedrock.rs index 16ea5d0..6ccefe0 100644 --- a/src/client/bedrock.rs +++ b/src/client/bedrock.rs @@ -556,7 +556,7 @@ fn aws_fetch( } = request; let region = &credentials.region; - let endpoint = format!("https://{}{}", host, uri); + let endpoint = format!("https://{host}{uri}"); let now: DateTime<Utc> = Utc::now(); let amz_date = now.format("%Y%m%dT%H%M%SZ").to_string(); @@ -566,7 +566,7 @@ fn aws_fetch( let canonical_headers = headers .iter() - .map(|(key, value)| format!("{}:{}\n", key, value)) + .map(|(key, value)| format!("{key}:{value}\n")) .collect::<Vec<_>>() .join(""); @@ -589,7 +589,7 @@ fn aws_fetch( ); let algorithm = "AWS4-HMAC-SHA256"; - let credential_scope = format!("{}/{}/{}/aws4_request", date_stamp, region, service); + let credential_scope = format!("{date_stamp}/{region}/{service}/aws4_request"); let string_to_sign = format!( "{}\n{}\n{}\n{}", algorithm, @@ -626,7 +626,7 @@ fn aws_fetch( } fn gen_signing_key(key: &str, date_stamp: &str, region: &str, service: &str) -> Vec<u8> { - let k_date = hmac_sha256(format!("AWS4{}", key).as_bytes(), date_stamp); + let k_date = hmac_sha256(format!("AWS4{key}").as_bytes(), date_stamp); let k_region = hmac_sha256(&k_date, region); let k_service = hmac_sha256(&k_region, service); hmac_sha256(&k_service, "aws4_request") diff --git a/src/client/model.rs b/src/client/model.rs index 20996b8..60a80f9 100644 --- a/src/client/model.rs +++ b/src/client/model.rs @@ -155,8 +155,7 @@ impl Model { .collect::<Vec<String>>() .join(""); format!( - "{:>8} / {:>8} | {:>6} / {:>6} {:>6}", - max_input_tokens, max_output_tokens, input_price, output_price, capabilities + "{max_input_tokens:>8} / {max_output_tokens:>8} | {input_price:>6} / {output_price:>6} {capabilities:>6}" ) } ModelType::Embedding => { diff --git a/src/config/input.rs b/src/config/input.rs index a47001b..e2cce21 100644 --- a/src/config/input.rs +++ b/src/config/input.rs @@ -537,7 +537,7 @@ fn read_media_to_data_url(image_path: &str) -> Result<String> { file.read_to_end(&mut buffer)?; let encoded_image = base64_encode(buffer); - let data_url = format!("data:{};base64,{}", mime_type, encoded_image); + let data_url = format!("data:{mime_type};base64,{encoded_image}"); Ok(data_url) } diff --git a/src/config/mod.rs b/src/config/mod.rs index 135e6ca..7e35c47 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -1270,7 +1270,7 @@ impl Config { .clone() .unwrap_or_else(|| SUMMARY_PROMPT.into()); if let Some(session) = config.write().session.as_mut() { - session.compress(format!("{}{}", summary_prompt, summary)); + session.compress(format!("{summary_prompt}{summary}")); } config.write().discontinuous_last_message(); Ok(()) @@ -1620,7 +1620,7 @@ impl Config { None => return Ok(()), }; - let err_msg = || format!("Invalid prelude '{}", prelude); + let err_msg = || format!("Invalid prelude '{prelude}"); match prelude.split_once(':') { Some(("role", name)) => { self.use_role(name).with_context(err_msg)?; @@ -1748,7 +1748,7 @@ impl Config { self.list_autoname_sessions() .iter() .rev() - .map(|v| format!("_/{}", v)) + .map(|v| format!("_/{v}")) .collect::<Vec<String>>(), ) } else { @@ -2192,7 +2192,7 @@ impl Config { let config: Self = serde_yaml::from_str(&content) .map_err(|err| { let err_msg = err.to_string(); - let err_msg = if err_msg.starts_with(&format!("{}: ", CLIENTS_FIELD)) { + let err_msg = if err_msg.starts_with(&format!("{CLIENTS_FIELD}: ")) { // location is incorrect, get rid of it err_msg .split_once(" at line") diff --git a/src/config/role.rs b/src/config/role.rs index 9bdfe6c..829c0d1 100644 --- a/src/config/role.rs +++ b/src/config/role.rs @@ -118,16 +118,16 @@ impl Role { pub fn export(&self) -> String { let mut metadata = vec![]; if let Some(model) = self.model_id() { - metadata.push(format!("model: {}", model)); + metadata.push(format!("model: {model}")); } if let Some(temperature) = self.temperature() { - metadata.push(format!("temperature: {}", temperature)); + metadata.push(format!("temperature: {temperature}")); } if let Some(top_p) = self.top_p() { - metadata.push(format!("top_p: {}", top_p)); + metadata.push(format!("top_p: {top_p}")); } if let Some(use_tools) = self.use_tools() { - metadata.push(format!("use_tools: {}", use_tools)); + metadata.push(format!("use_tools: {use_tools}")); } if metadata.is_empty() { format!("{}\n", self.prompt) diff --git a/src/config/session.rs b/src/config/session.rs index a895e64..f3a86de 100644 --- a/src/config/session.rs +++ b/src/config/session.rs @@ -79,7 +79,7 @@ impl Session { let content = read_to_string(path) .with_context(|| format!("Failed to load session {} at {}", name, path.display()))?; let mut session: Self = - serde_yaml::from_str(&content).with_context(|| format!("Invalid session {}", name))?; + serde_yaml::from_str(&content).with_context(|| format!("Invalid session {name}"))?; session.model = Model::retrieve_model(config, &session.model_id, ModelType::Chat)?; @@ -158,7 +158,7 @@ impl Session { data["max_input_tokens"] = max_input_tokens.into(); } if percent != 0.0 { - data["total/max"] = format!("{}%", percent).into(); + data["total/max"] = format!("{percent}%").into(); } data["messages"] = json!(self.messages); diff --git a/src/main.rs b/src/main.rs index c68b935..444340b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -156,7 +156,7 @@ async fn run(config: GlobalConfig, cli: Cli, text: Option<String>) -> Result<()> } if cli.info { let info = config.read().info()?; - println!("{}", info); + println!("{info}"); return Ok(()); } if let Some(addr) = cli.serve { @@ -334,7 +334,7 @@ async fn shell_execute( break; } } else { - println!("{}", eval_str); + println!("{eval_str}"); } Ok(()) } diff --git a/src/rag/mod.rs b/src/rag/mod.rs index f799b3d..a52c00b 100644 --- a/src/rag/mod.rs +++ b/src/rag/mod.rs @@ -672,7 +672,7 @@ impl Rag { match embedding_client.embeddings(&chunk_data).await { Ok(v) => break v, Err(e) if retry < retry_limit => { - debug!("retry {} failed: {}", retry, e); + debug!("retry {retry} failed: {e}"); sleep(Duration::from_secs(2u64.pow(retry - 1))).await; continue; } diff --git a/src/render/stream.rs b/src/render/stream.rs index d2ac6ef..a6233a5 100644 --- a/src/render/stream.rs +++ b/src/render/stream.rs @@ -43,7 +43,7 @@ pub async fn raw_stream( if let Some(evt) = rx.recv().await { match evt { SseEvent::Text(text) => { - print!("{}", text); + print!("{text}"); stdout().flush()?; } SseEvent::Done => { diff --git a/src/repl/mod.rs b/src/repl/mod.rs index 73e0e9a..e844abc 100644 --- a/src/repl/mod.rs +++ b/src/repl/mod.rs @@ -386,24 +386,24 @@ pub async fn run_repl_command( ".info" => match args { Some("role") => { let info = config.read().role_info()?; - print!("{}", info); + print!("{info}"); } Some("session") => { let info = config.read().session_info()?; - print!("{}", info); + print!("{info}"); } Some("rag") => { let info = config.read().rag_info()?; - print!("{}", info); + print!("{info}"); } Some("agent") => { let info = config.read().agent_info()?; - print!("{}", info); + print!("{info}"); } Some(_) => unknown_command()?, None => { let output = config.read().sysinfo()?; - print!("{}", output); + print!("{output}"); } }, ".model" => match args { @@ -487,7 +487,7 @@ pub async fn run_repl_command( } match text { Some(text) => { - println!("{}", dimmed_text(&format!(">> {}", text))); + println!("{}", dimmed_text(&format!(">> {text}"))); let input = Input::from_str(config, &text, None); ask(config, abort_signal.clone(), input, true).await?; } @@ -570,7 +570,7 @@ pub async fn run_repl_command( ".sources" => match args { Some("rag") => { let output = Config::rag_sources(config)?; - println!("{}", output); + println!("{output}"); } _ => { println!(r#"Usage: .sources rag"#) diff --git a/src/serve.rs b/src/serve.rs index 44139ce..7a90c7d 100644 --- a/src/serve.rs +++ b/src/serve.rs @@ -631,7 +631,7 @@ async fn shutdown_signal() { fn generate_completion_id() -> String { let random_id = chrono::Utc::now().nanosecond(); - format!("chatcmpl-{}", random_id) + format!("chatcmpl-{random_id}") } fn set_cors_header(res: &mut AppResponse) { diff --git a/src/utils/clipboard.rs b/src/utils/clipboard.rs index cb92bce..6b87ff7 100644 --- a/src/utils/clipboard.rs +++ b/src/utils/clipboard.rs @@ -8,7 +8,7 @@ static CLIPBOARD: std::sync::LazyLock<std::sync::Mutex<Option<arboard::Clipboard /// Works in many modern terminals, including over SSH. fn set_text_osc52(text: &str) -> anyhow::Result<()> { let encoded = BASE64.encode(text); - let seq = format!("\x1b]52;c;{}\x07", encoded); + let seq = format!("\x1b]52;c;{encoded}\x07"); // Write to stdout: if let Err(e) = std::io::Write::write_all(&mut std::io::stdout(), seq.as_bytes()) { return Err(anyhow::anyhow!("Failed to send OSC52 sequence").context(e)); @@ -35,7 +35,7 @@ pub fn set_text(text: &str) -> anyhow::Result<()> { match set_text_osc52(text) { Ok(()) => Ok(()), Err(osc_err) => Err(anyhow::anyhow!("No clipboard available") - .context(format!("Failed to copy (OSC52 error: {})", osc_err))), + .context(format!("Failed to copy (OSC52 error: {osc_err})"))), } } diff --git a/src/utils/command.rs b/src/utils/command.rs index 14a40a4..7d98504 100644 --- a/src/utils/command.rs +++ b/src/utils/command.rs @@ -175,7 +175,7 @@ pub fn append_to_shell_history(shell: &str, command: &str, exit_code: i32) -> io .create(true) .append(true) .open(&history_file)?; - writeln!(file, "{}", history_txt)?; + writeln!(file, "{history_txt}")?; } Ok(()) } diff --git a/src/utils/crypto.rs b/src/utils/crypto.rs index 9f0ee82..494ea84 100644 --- a/src/utils/crypto.rs +++ b/src/utils/crypto.rs @@ -17,7 +17,7 @@ pub fn hmac_sha256(key: &[u8], msg: &str) -> Vec<u8> { pub fn hex_encode(bytes: &[u8]) -> String { bytes .iter() - .fold(String::new(), |acc, b| acc + &format!("{:02x}", b)) + .fold(String::new(), |acc, b| acc + &format!("{b:02x}")) } pub fn encode_uri(uri: &str) -> String { diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 98f2da1..6c5b08a 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -162,7 +162,7 @@ pub fn indent_text<T: ToString>(s: T, size: usize) -> String { let indent_str = " ".repeat(size); s.to_string() .split('\n') - .map(|line| format!("{}{}", indent_str, line)) + .map(|line| format!("{indent_str}{line}")) .collect::<Vec<String>>() .join("\n") } diff --git a/src/utils/request.rs b/src/utils/request.rs index 8cee0a0..95c4f9c 100644 --- a/src/utils/request.rs +++ b/src/utils/request.rs @@ -131,7 +131,7 @@ pub async fn fetch_with_loaders( } let image_bytes = res.bytes().await?; let image_base64 = base64_encode(&image_bytes); - let contents = format!("data:{};base64,{}", content_type, image_base64); + let contents = format!("data:{content_type};base64,{image_base64}"); (contents, extension) } else { match loaders.get(&extension) { @@ -316,10 +316,7 @@ async fn crawl_gh_tree(start_url: &Url, exclude: &[String]) -> Result<Vec<String let branch = path_segs[4]; let root_path = path_segs[5..].join("/"); - let url = format!( - "https://api.github.com/repos/{}/{}/git/ref/heads/{}", - owner, repo, branch - ); + let url = format!("https://api.github.com/repos/{owner}/{repo}/git/ref/heads/{branch}"); let res_body: Value = client .get(&url) @@ -335,10 +332,7 @@ async fn crawl_gh_tree(start_url: &Url, exclude: &[String]) -> Result<Vec<String .as_str() .ok_or_else(|| anyhow!("Not found branch or tag"))?; - let url = format!( - "https://api.github.com/repos/{}/{}/git/trees/{}?recursive=true", - owner, repo, sha - ); + let url = format!("https://api.github.com/repos/{owner}/{repo}/git/trees/{sha}?recursive=true"); let res_body: Value = client .get(&url) diff --git a/src/utils/variables.rs b/src/utils/variables.rs index bfec4ca..991da2a 100644 --- a/src/utils/variables.rs +++ b/src/utils/variables.rs @@ -25,7 +25,7 @@ pub fn interpolate_variables(text: &mut String) { "__cwd__" => env::current_dir() .map(|v| v.display().to_string()) .unwrap_or_default(), - _ => format!("{{{{{}}}}}", key), + _ => format!("{{{{{key}}}}}"), } }) .to_string(); |
