fix: resolve clippy warnings (matches!, map_or, redundant guard, unnecessary allocations)
This commit is contained in:
@@ -233,7 +233,7 @@ async fn chat_completions_stream(
|
||||
"finish_reason": "stop",
|
||||
}],
|
||||
})).unwrap_or_default()));
|
||||
yield Ok(Event::default().data("[DONE]".to_string()));
|
||||
yield Ok(Event::default().data("[DONE]"));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -257,7 +257,7 @@ async fn chat_completions_stream(
|
||||
"finish_reason": "stop",
|
||||
}],
|
||||
})).unwrap_or_default()));
|
||||
yield Ok(Event::default().data("[DONE]".to_string()));
|
||||
yield Ok(Event::default().data("[DONE]"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -284,7 +284,7 @@ async fn chat_completions_stream(
|
||||
"finish_reason": "stop",
|
||||
}],
|
||||
})).unwrap_or_default()));
|
||||
yield Ok(Event::default().data("[DONE]".to_string()));
|
||||
yield Ok(Event::default().data("[DONE]"));
|
||||
};
|
||||
|
||||
Sse::new(stream)
|
||||
|
||||
@@ -237,14 +237,14 @@ pub(crate) async fn poll_for_response(
|
||||
info!(
|
||||
"Response done ({short_id}), {:.1}s, {} chars, tokens: {}in/{}out ({}){}{}",
|
||||
elapsed, text.len(), u.input_tokens, u.output_tokens, u.model,
|
||||
if thinking.is_some() { format!(", thinking: {} chars", thinking.as_ref().unwrap().len()) } else { String::new() },
|
||||
thinking.as_ref().map_or(String::new(), |t| format!(", thinking: {} chars", t.len())),
|
||||
if thinking_signature.is_some() { ", has sig" } else { "" }
|
||||
);
|
||||
} else {
|
||||
info!(
|
||||
"Response done ({short_id}), {:.1}s, {} chars (no usage){}{}",
|
||||
elapsed, text.len(),
|
||||
if thinking.is_some() { format!(", thinking: {} chars", thinking.as_ref().unwrap().len()) } else { String::new() },
|
||||
thinking.as_ref().map_or(String::new(), |t| format!(", thinking: {} chars", t.len())),
|
||||
if thinking_signature.is_some() { ", has sig" } else { "" }
|
||||
);
|
||||
}
|
||||
|
||||
@@ -206,7 +206,7 @@ pub(crate) async fn handle_responses(
|
||||
.send_message(&cascade_id, &user_text, model.model_enum)
|
||||
.await
|
||||
{
|
||||
Ok((status, _)) if status == 200 => {
|
||||
Ok((200, _)) => {
|
||||
let bg = Arc::clone(&state.backend);
|
||||
let cid = cascade_id.clone();
|
||||
tokio::spawn(async move {
|
||||
|
||||
@@ -141,6 +141,7 @@ pub(crate) struct OutputTokensDetails {
|
||||
}
|
||||
|
||||
#[derive(Serialize, Clone)]
|
||||
#[derive(Default)]
|
||||
pub(crate) struct Reasoning {
|
||||
pub effort: Option<String>,
|
||||
pub summary: Option<String>,
|
||||
@@ -161,8 +162,8 @@ impl Usage {
|
||||
/// Estimate token counts from actual text.
|
||||
/// Uses ~4 chars/token heuristic (standard GPT tokenizer average).
|
||||
pub fn estimate(input_text: &str, output_text: &str) -> Self {
|
||||
let input_tokens = (input_text.len() as u64 + 3) / 4;
|
||||
let output_tokens = (output_text.len() as u64 + 3) / 4;
|
||||
let input_tokens = (input_text.len() as u64).div_ceil(4);
|
||||
let output_tokens = (output_text.len() as u64).div_ceil(4);
|
||||
Self {
|
||||
input_tokens,
|
||||
input_tokens_details: InputTokensDetails { cached_tokens: 0 },
|
||||
@@ -189,14 +190,6 @@ impl Default for Usage {
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Reasoning {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
effort: None,
|
||||
summary: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for TextFormat {
|
||||
fn default() -> Self {
|
||||
|
||||
@@ -227,10 +227,7 @@ fn looks_like_valid_message(fields: &[ProtoField], original_len: usize) -> bool
|
||||
// (e.g., a long string that happened to have a valid first-field prefix)
|
||||
if fields.len() == 1 && original_len > 100 {
|
||||
// Single-field messages of >100 bytes are suspicious unless the field is bytes/message
|
||||
match &fields[0].value {
|
||||
ProtoValue::Bytes(_) | ProtoValue::Message(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(&fields[0].value, ProtoValue::Bytes(_) | ProtoValue::Message(_))
|
||||
} else {
|
||||
true
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@ const PASSTHROUGH_DOMAINS: &[&str] = &[
|
||||
];
|
||||
|
||||
/// Configuration for the MITM proxy.
|
||||
#[derive(Default)]
|
||||
pub struct MitmConfig {
|
||||
/// Port to listen on (0 = auto-assign).
|
||||
pub port: u16,
|
||||
@@ -53,14 +54,6 @@ pub struct MitmConfig {
|
||||
pub modify_requests: bool,
|
||||
}
|
||||
|
||||
impl Default for MitmConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
port: 0,
|
||||
modify_requests: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Run the MITM proxy server.
|
||||
///
|
||||
@@ -405,7 +398,7 @@ async fn handle_http_over_tls(
|
||||
async fn resolve_upstream(domain: &str) -> String {
|
||||
// 1. Try dig @8.8.8.8 (bypasses /etc/hosts)
|
||||
if let Ok(output) = tokio::process::Command::new("dig")
|
||||
.args(["+short", &format!("@8.8.8.8"), domain])
|
||||
.args(["+short", "@8.8.8.8", domain])
|
||||
.output()
|
||||
.await
|
||||
{
|
||||
|
||||
@@ -102,12 +102,11 @@ impl Snapshot {
|
||||
}
|
||||
|
||||
// LS process logs
|
||||
if line.starts_with('I') || line.starts_with('W') || line.starts_with('E') {
|
||||
if line.len() > 4 && line.chars().nth(1).map_or(false, |c| c.is_ascii_digit()) {
|
||||
if (line.starts_with('I') || line.starts_with('W') || line.starts_with('E'))
|
||||
&& line.len() > 4 && line.chars().nth(1).is_some_and(|c| c.is_ascii_digit()) {
|
||||
snap.ls_logs.push(line.to_string());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if line.contains("maxprocs:") {
|
||||
snap.ls_logs.push(line.to_string());
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user