AI Engine Translating Image Queries

How to automatically translate AI Engine image generation queries into English for better results.

add_filter('mwai_ai_query', function($query) {
    if ($query instanceof Meow_MWAI_Query_Image) {
        global $mwai;
        $prompt = 'Translate the following text in <text>{{text}}</text> to English, outputting the English text in <english></english> tags:';
        $prompt = str_replace('{{text}}', $query->message, $prompt);
        $params = array(
            'model' => 'gpt-4o-mini',
            'temperature' => 0.1,
        );
        $summary = $mwai->simpleTextQuery(
            $prompt,
            $params
        );
        if ($summary) {
            // extract text from <english></english>
            $message = preg_replace('/<english>(.*?)<\/english>/', '$1', $summary);
            $query->message = $message;
        }
    }
    return $query;
}, 10, 1);

Let’s enhance your business! I can help you develop custom AI engine extensions or broader AI strategies.

Contact me.

Leave a Reply

Your email address will not be published. Required fields are marked *