Poistetaan selityskommentit LLM-vastauksista: "# This is a simple program..." -tyyppiset rivit
Malli tuottaa toisinaan selityskommentin koodin alkuun ilman markdown-wrapperia. Stripperi tunnistaa ja poistaa nämä avainsanojen perusteella (this is, simple, program that, jne.) mutta säilyttää oikeat koodikommentit ja shebangin. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -255,7 +255,20 @@ fn strip_markdown_wrapper(text: &str) -> String {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result.trim().to_string()
|
let mut lines: Vec<&str> = result.trim().lines().collect();
|
||||||
|
while !lines.is_empty() {
|
||||||
|
let first = lines[0].trim();
|
||||||
|
let is_preamble = first.starts_with("# ")
|
||||||
|
&& !first.starts_with("#!")
|
||||||
|
&& (first.to_lowercase().contains("this is")
|
||||||
|
|| first.to_lowercase().contains("simple")
|
||||||
|
|| first.to_lowercase().contains("program that")
|
||||||
|
|| first.to_lowercase().contains("here is")
|
||||||
|
|| first.to_lowercase().contains("the following")
|
||||||
|
|| first.to_lowercase().contains("below"));
|
||||||
|
if is_preamble { lines.remove(0); } else { break; }
|
||||||
|
}
|
||||||
|
lines.join("\n").trim().to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct GenerateResult {
|
pub struct GenerateResult {
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ fn strip_markdown_wrapper(text: &str) -> String {
|
|||||||
// Ei sulkevaa ``` — ota kaikki loput
|
// Ei sulkevaa ``` — ota kaikki loput
|
||||||
return code.trim().to_string();
|
return code.trim().to_string();
|
||||||
}
|
}
|
||||||
// Ei koodiblokkia — poista yleiset johdantolauseet alusta
|
// Ei koodiblokkia — poista yleiset johdantolauseet ja selityskommentit alusta
|
||||||
let mut result = text.to_string();
|
let mut result = text.to_string();
|
||||||
let lower = result.to_lowercase();
|
let lower = result.to_lowercase();
|
||||||
for prefix in &["sure!", "here is", "here's", "certainly!", "below is"] {
|
for prefix in &["sure!", "here is", "here's", "certainly!", "below is"] {
|
||||||
@@ -55,7 +55,26 @@ fn strip_markdown_wrapper(text: &str) -> String {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result.trim().to_string()
|
// Poistetaan alun selityskommentit: "# This is a simple..." -tyyppiset rivit
|
||||||
|
// jotka eivät ole osa varsinaista koodia (esim. shebangia #! pidetään)
|
||||||
|
let mut lines: Vec<&str> = result.trim().lines().collect();
|
||||||
|
while !lines.is_empty() {
|
||||||
|
let first = lines[0].trim();
|
||||||
|
let is_preamble_comment = first.starts_with("# ")
|
||||||
|
&& !first.starts_with("#!")
|
||||||
|
&& (first.to_lowercase().contains("this is")
|
||||||
|
|| first.to_lowercase().contains("simple")
|
||||||
|
|| first.to_lowercase().contains("program that")
|
||||||
|
|| first.to_lowercase().contains("here is")
|
||||||
|
|| first.to_lowercase().contains("the following")
|
||||||
|
|| first.to_lowercase().contains("below"));
|
||||||
|
if is_preamble_comment {
|
||||||
|
lines.remove(0);
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lines.join("\n").trim().to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
thread_local! {
|
thread_local! {
|
||||||
|
|||||||
Reference in New Issue
Block a user