VoiceInk icon indicating copy to clipboard operation
VoiceInk copied to clipboard

Thinking tag removal is backwards. (Plus fix)

Open mallorbc opened this issue 5 months ago • 2 comments

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

mallorbc avatar Jul 23 '25 06:07 mallorbc

Thanks for the heads up. Will be fixed in the next update

Beingpax avatar Jul 25 '25 09:07 Beingpax

Cool thanks! Feel free to close this issue once you add the fix

mallorbc avatar Jul 28 '25 18:07 mallorbc