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;
|
||||
}
|
||||
}
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user