Markdown-wrapper strippaus LLM-vastauksista + hub-status tooltip

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jaakko Vanhala
2026-04-05 08:41:23 +03:00
parent 88fd31ca8c
commit 949f34833f
3 changed files with 67 additions and 3 deletions

View File

@@ -225,7 +225,7 @@ impl LlmEngine {
} else { 0.0 };
Ok(GenerateResult {
text: generated_text,
text: strip_markdown_wrapper(&generated_text),
tokens_generated,
duration_ms: gen_time.as_millis() as f64,
tokens_per_sec,
@@ -233,6 +233,31 @@ impl LlmEngine {
}
}
/// Poistaa mallin tuottaman markdown-wrapperin ja johdantotekstin.
fn strip_markdown_wrapper(text: &str) -> String {
let text = text.trim();
if let Some(start) = text.find("```") {
let after = &text[start + 3..];
let code_start = after.find('\n').map(|i| i + 1).unwrap_or(0);
let code = &after[code_start..];
if let Some(end) = code.find("```") {
return code[..end].trim().to_string();
}
return code.trim().to_string();
}
let mut result = text.to_string();
let lower = result.to_lowercase();
for prefix in &["sure!", "here is", "here's", "certainly!", "below is"] {
if lower.starts_with(prefix) {
if let Some(nl) = result.find('\n') {
result = result[nl + 1..].to_string();
}
break;
}
}
result.trim().to_string()
}
pub struct GenerateResult {
pub text: String,
pub tokens_generated: usize,