Native-noden vastausten siivous: stop-sekvenssit + selitystekstien poisto

Stop-sekvenssit laajennettu: Please note, This is, Example, ```
strip_code_fences laajennettu poistamaan:
- Selitystekstit lopusta (Please note, This is a basic, Note that, ...)
- Johdantolauseet alusta (Sure!, Here is, Certainly!)
System prompt vahvistettu: "No 'Please note' or 'Here is' text"

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jaakko Vanhala
2026-04-09 22:04:43 +03:00
parent 4fef8824e1
commit d85cab4bc0

View File

@@ -79,7 +79,7 @@ impl LlmEngine {
} }
pub async fn generate(&self, prompt: &str, max_tokens: usize) -> Result<GenerateResult, String> { pub async fn generate(&self, prompt: &str, max_tokens: usize) -> Result<GenerateResult, String> {
let system = "You are a coding assistant. Respond with ONLY code. Use proper newlines and indentation. No explanations, no markdown fences, no comments unless asked."; let system = "You are a coding assistant. Respond with ONLY code. No explanations, no markdown fences, no 'Please note' or 'Here is' text. Only working code with proper imports.";
let model = self.model.borrow().clone(); let model = self.model.borrow().clone();
let start = Instant::now(); let start = Instant::now();
@@ -94,7 +94,7 @@ impl LlmEngine {
"temperature": 0.7, "temperature": 0.7,
"top_k": 40, "top_k": 40,
"repeat_penalty": 1.15, "repeat_penalty": 1.15,
"stop": ["<|im_end|>", "\n###", "\nExplanation", "\nNote:"] "stop": ["<|im_end|>", "\n###", "\nExplanation", "\nNote:", "\nPlease note", "\nThis is", "\n```\n\n", "\n// Example", "\n# Example"]
} }
})) }))
.send() .send()
@@ -127,7 +127,7 @@ impl LlmEngine {
} }
} }
/// Siivoa mahdolliset markdown-koodiblokki-merkit /// 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(); let mut result = text.trim().to_string();
@@ -147,7 +147,26 @@ fn strip_code_fences(text: &str) -> String {
} }
} }
result // Poista selitysteksti lopusta (kaikki rivin "\nPlease note" jälkeen jne.)
let lower = result.to_lowercase();
for stop in &["\nplease note", "\nthis is a basic", "\nthis code", "\nnote that", "\nremember to", "\nyou can", "\nto run"] {
if let Some(pos) = lower.find(stop) {
result = result[..pos].trim_end().to_string();
}
}
// Poista johdantolauseet alusta
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 struct GenerateResult {