diff --git a/network-poc/native-node/src/inference.rs b/network-poc/native-node/src/inference.rs index bf0abcc..64420d2 100644 --- a/network-poc/native-node/src/inference.rs +++ b/network-poc/native-node/src/inference.rs @@ -79,7 +79,7 @@ impl LlmEngine { } pub async fn generate(&self, prompt: &str, max_tokens: usize) -> Result { - 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 start = Instant::now(); @@ -94,7 +94,7 @@ impl LlmEngine { "temperature": 0.7, "top_k": 40, "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() @@ -127,7 +127,7 @@ impl LlmEngine { } } -/// Siivoa mahdolliset markdown-koodiblokki-merkit +/// Siivoa markdown-koodiblokki-merkit ja selitystekstit fn strip_code_fences(text: &str) -> 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 {