feat: controller supports vocabulary bias, prompt-echo guard, corrector and result hook

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-01 14:54:49 +02:00
co-authored by Claude Sonnet 5.5
parent aec4aa7a5b
commit 7fbc182fa7
5 changed files with 236 additions and 7 deletions
+21
View File
@@ -0,0 +1,21 @@
import Foundation
/// Whisper sometimes answers a vocabulary prompt with the prompt itself when there is little speech.
public enum PromptEcho {
static func normalize(_ text: String) -> String {
String(text.lowercased().map { $0.isLetter || $0.isNumber ? $0 : " " })
.split(separator: " ")
.joined(separator: " ")
}
/// True when `text` is nothing but the first k ≥ 2 terms of the prompt.
/// A single term on its own is valid speech ("Anthropic").
public static func isEcho(_ text: String, vocabulary: [String]) -> Bool {
guard vocabulary.count >= 2 else { return false }
let normalized = normalize(text)
guard !normalized.isEmpty else { return false }
return (2...vocabulary.count).contains { k in
normalize(vocabulary.prefix(k).joined(separator: " ")) == normalized
}
}
}