From 9069145de6f985d2dfc4e21e7db89f94db42f838 Mon Sep 17 00:00:00 2001 From: pulsareonbot Date: Sat, 4 Jul 2026 17:28:06 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E6=9E=90=20llama-cli=20?= =?UTF-8?q?=E8=BF=9B=E5=BA=A6=E5=8A=A8=E7=94=BB=E5=92=8C=E5=9B=9E=E5=A4=8D?= =?UTF-8?q?=E5=9C=A8=E5=90=8C=E4=B8=80=E8=A1=8C=E7=9A=84=E6=83=85=E5=86=B5?= =?UTF-8?q?=20(=E6=B8=85=E7=90=86=20\b=20=E8=BD=AC=E4=B9=89)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/ai/backend.rs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/plugins/ai/backend.rs b/src/plugins/ai/backend.rs index e8085fd..ca659da 100644 --- a/src/plugins/ai/backend.rs +++ b/src/plugins/ai/backend.rs @@ -325,12 +325,6 @@ fn parse_llama_output(raw: &str) -> String { continue; } - // 跳过进度动画行(只含 |/-\ 和空格) - let cleaned: String = trimmed.chars().filter(|c| !"|\\-/ ".contains(*c)).collect(); - if cleaned.is_empty() { - continue; - } - // 遇到性能统计行 [ Prompt: ... ] 停止 if trimmed.starts_with('[') && trimmed.contains("Generation") { break; @@ -340,7 +334,19 @@ fn parse_llama_output(raw: &str) -> String { break; } - reply_lines.push(trimmed); + // 清理进度动画字符 |/-\ 和转义序列 \b + // llama-cli 的进度动画用 \b(退格)刷新,stdout 捕获后变成字面 \b + let cleaned: String = trimmed + .replace("\\b", "") // 退格转义 + .chars() + .filter(|c| !"|\\-/".contains(*c)) + .collect(); + let cleaned = cleaned.trim(); + if cleaned.is_empty() { + continue; + } + + reply_lines.push(cleaned); } reply_lines.join("\n").trim().to_string() @@ -352,12 +358,13 @@ mod tests { #[test] fn test_parse_llama_output() { + // 进度动画和回复在同一行,用 \b 分隔 let raw = " █ █ build : b1-fdb1db8\n\ model : model_store/llm/qwen2.5-0.5b-q4_k_m.gguf\n\ \n\ > hello\n\ \n\ -|/-\\|/-\\ 汪!\n\ +\\b-\\b\\\\\\b|\\b/\\b-\\b\\\\\\b|\\b/\\b \b汪!\n\ \n\ [ Prompt: 31.1 t/s | Generation: 26.3 t/s ]\n\ \n\