From cb74f2fb12273829d27cd64aa1564b572b587166 Mon Sep 17 00:00:00 2001 From: Beingpax Date: Tue, 16 Sep 2025 17:38:48 +0545 Subject: [PATCH] Simplify hallucination filter angle tags --- VoiceInk/Whisper/WhisperHallucinationFilter.swift | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/VoiceInk/Whisper/WhisperHallucinationFilter.swift b/VoiceInk/Whisper/WhisperHallucinationFilter.swift index bea80b3..7bd1e67 100644 --- a/VoiceInk/Whisper/WhisperHallucinationFilter.swift +++ b/VoiceInk/Whisper/WhisperHallucinationFilter.swift @@ -5,9 +5,9 @@ struct WhisperHallucinationFilter { private static let logger = Logger(subsystem: "com.prakashjoshipax.voiceink", category: "WhisperHallucinationFilter") private static let hallucinationPatterns = [ - #"\[.*?\]"#, // Square brackets - #"\(.*?\)"#, // Parentheses - #"\{.*?\}"# // Curly braces + #"\[.*?\]"#, // [] + #"\(.*?\)"#, // () + #"\{.*?\}"# // {} ] private static let fillerWords = [ @@ -18,6 +18,13 @@ struct WhisperHallucinationFilter { logger.notice("🧹 Filtering hallucinations and filler words") var filteredText = text + // Remove ... blocks + let tagBlockPattern = #"<([A-Za-z][A-Za-z0-9:_-]*)[^>]*>[\s\S]*?"# + if let regex = try? NSRegularExpression(pattern: tagBlockPattern) { + let range = NSRange(filteredText.startIndex..., in: filteredText) + filteredText = regex.stringByReplacingMatches(in: filteredText, options: [], range: range, withTemplate: "") + } + // Remove bracketed hallucinations for pattern in hallucinationPatterns { if let regex = try? NSRegularExpression(pattern: pattern) {