fix: 解析 llama-cli 进度动画和回复在同一行的情况 (清理 \b 转义)
This commit is contained in:
@@ -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\
|
||||
|
||||
Reference in New Issue
Block a user