strip_code_fences: poistetaan kaikki backtick-rivit aggressiivisesti
Ollama tuottaa \`\`\`python ... \`\`\` -blokkeja vaikka system prompt kieltää ne. Nyt kaikki rivit jotka alkavat \`\`\` suodatetaan pois, myös keskeltä vastausta (useita koodiblokkeja per vastaus). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -109,7 +109,7 @@ impl LlmEngine {
|
|||||||
.map_err(|e| format!("Ollama JSON: {}", e))?;
|
.map_err(|e| format!("Ollama JSON: {}", e))?;
|
||||||
|
|
||||||
let text = body["response"].as_str().unwrap_or("").to_string();
|
let text = body["response"].as_str().unwrap_or("").to_string();
|
||||||
let total_duration_ns = body["total_duration"].as_u64().unwrap_or(0);
|
let _total_duration_ns = body["total_duration"].as_u64().unwrap_or(0);
|
||||||
let eval_count = body["eval_count"].as_u64().unwrap_or(0) as usize;
|
let eval_count = body["eval_count"].as_u64().unwrap_or(0) as usize;
|
||||||
let eval_duration_ns = body["eval_duration"].as_u64().unwrap_or(1);
|
let eval_duration_ns = body["eval_duration"].as_u64().unwrap_or(1);
|
||||||
|
|
||||||
@@ -129,23 +129,17 @@ impl LlmEngine {
|
|||||||
|
|
||||||
/// Siivoa markdown-koodiblokki-merkit ja selitystekstit
|
/// Siivoa markdown-koodiblokki-merkit ja selitystekstit
|
||||||
fn strip_code_fences(text: &str) -> String {
|
fn strip_code_fences(text: &str) -> String {
|
||||||
let mut result = text.trim().to_string();
|
// Poistetaan kaikki ```-rivit ja kielitunnisteet (```python, ```rust jne.)
|
||||||
|
let lines: Vec<&str> = text.lines().collect();
|
||||||
// Poista aloittava ```lang
|
let filtered: Vec<&str> = lines.into_iter().filter(|line| {
|
||||||
if result.starts_with("```") {
|
let trimmed = line.trim();
|
||||||
if let Some(nl) = result.find('\n') {
|
// Poista rivit jotka ovat pelkkiä ``` tai ```kielitunniste
|
||||||
result = result[nl + 1..].to_string();
|
if trimmed.starts_with("```") {
|
||||||
}
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
// Poista sulkeva ```
|
|
||||||
let trimmed = result.trim_end();
|
|
||||||
if trimmed.ends_with("```") {
|
|
||||||
let before = &trimmed[..trimmed.len() - 3];
|
|
||||||
if before.is_empty() || before.ends_with('\n') {
|
|
||||||
result = before.trim_end().to_string();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
true
|
||||||
|
}).collect();
|
||||||
|
let mut result = filtered.join("\n").trim().to_string();
|
||||||
|
|
||||||
// Poista selitysteksti lopusta (kaikki rivin "\nPlease note" jälkeen jne.)
|
// Poista selitysteksti lopusta (kaikki rivin "\nPlease note" jälkeen jne.)
|
||||||
let lower = result.to_lowercase();
|
let lower = result.to_lowercase();
|
||||||
|
|||||||
Reference in New Issue
Block a user