VoiceInk
VoiceInk copied to clipboard
Thinking tag removal is backwards. (Plus fix)
I was trying out using Qwen 3 using a custom endpoint with VoiceInk.
What I found is that instead of returning just the output, it will return only the content within the thinking tags.
I found a solution with code like the following:
import Foundation
struct AIEnhancementOutputFilter {
static func filter(_ text: String) -> String {
let patterns = [
#"(?s)<thinking>(.*?)</thinking>"#,
#"(?s)<think>(.*?)</think>"#,
#"(?s)<reasoning>(.*?)</reasoning>"#
]
var filteredText = text
// Remove thinking tags and their content
for pattern in patterns {
if let regex = try? NSRegularExpression(pattern: pattern) {
filteredText = regex.stringByReplacingMatches(
in: filteredText,
options: [],
range: NSRange(filteredText.startIndex..., in: filteredText),
withTemplate: ""
)
}
}
// Return the text with thinking tags removed, trimmed of whitespace
return filteredText.trimmingCharacters(in: .whitespacesAndNewlines)
}
}
This is now the entire file content of AIEnhancementOutputFilter.swift
Might be a good idea to allow one to return the entirity of the content if they want, but this as it is seems like a bug
Thanks for the heads up. Will be fixed in the next update
Cool thanks! Feel free to close this issue once you add the fix