Simplify hallucination filter angle tags

This commit is contained in:
Beingpax 2025-09-16 17:38:48 +05:45
parent 2b787e8e64
commit cb74f2fb12

View File

@ -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 <TAG>...</TAG> blocks
let tagBlockPattern = #"<([A-Za-z][A-Za-z0-9:_-]*)[^>]*>[\s\S]*?</\1>"#
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) {