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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user