If you would like to access AI features easily through AI Engine, simply use the mwaiglobal. There will be more and more functions available to use. The API uses the whole AI Engine system, so you’ll get the statistics and limitations features as well.
simpleTextQuery( $message, $params = [] )
You can use this function to simply run a query against the default model of your default AI environment, as set in the AI Engine settings. It’s as simple as that!
add_filter( 'the_content', function ( $content ) {
global $mwai;
$extra = $mwai->simpleTextQuery( "Write an one-liner about a cat introducing itself." );
return $extra . $content;
} );
simpleChatbotQuery( $botId, $message, $params = [], $onlyReply = true )
You can use this to discuss with one of your chatbots. The chatId is optional, but allows you to create a conversation. All the messages exchanged under the same chatId will be stored as a conversation. For this to work, you will need the Discussions to be enabled in the Settings.
simpleJsonQuery( $message, $url = null, $path = null, $params = [] )
This is similar to simpleTextQuery, except that it will return an array directly, representing the JSON. You can describe the attributes that you would like in the JSON in the prompt.
simpleVisionQuery( $message, $url, $path = null, $params = [] )
This is used to transcribe an image to text, based on your needs stated in the prompt. It is recommended to use an URL that points to your image, otherwise the path can be used and should point to a local file in your WordPress.
simpleFileUpload( $file = null, $base64 = null, $filename = null, $purpose = ‘analysis’, $ttl = 3600, $target = null, $metadata = [] )
This allows you to upload a file either with a link or using base64, the same way AI Engine would do it through a chatbot, meaning you will get a refId and a URL for the uploaded file. With it, you can easily integrate this uploaded file into a chatbot query.
global $mwai;
// Download
$image_url = 'https://jordymeow.com/wp-content/uploads/2018/12/31081620120504.jpg';
$image_data = file_get_contents($image_url);
$base64 = base64_encode($image_data);
// Upload
$upload = $mwai->simpleFileUpload(
null, // $file (null for base64)
$base64, // $base64 data
'gunkanjima.jpg', // $filename (required for base64)
'vision' // $purpose
);
$file_id = $upload['id'];
echo "File ID: " . $file_id;
// Request
$answer = $mwai->simpleChatbotQuery(
'default',
'What do you see in this image?',
[ 'fileId' => $file_id ]
);
echo $answer;
moderationCheck( $text )
Simply return true if the message has been flagged as unsafe to use.
simpleFastTextQuery( $message, $params = [] )
Same as simpleTextQuery, but it uses the Default (Fast) model and environment instead of the default one. Handy for short, cheap tasks such as titles, summaries or classification.
simpleImageQuery( $message, $params = [] )
Generates one or more images from your prompt, and returns their URLs.
simpleImageEditQuery( $message, $mediaId, $params = [] )
Edits an image that is already in your Media Library, based on your prompt. The $mediaId is the attachment ID.
imageQueryForMediaLibrary( $message, $params = [], $postId = null )
Same as simpleImageQuery, except the generated image is imported into the Media Library and you get the attachment ID back. If a $postId is given, the image is attached to that post.
simpleTranscribeAudio( $url = null, $path = null, $params = [] )
Transcribes an audio file to text. Use an URL, or a path pointing to a local file in your WordPress.
getStatus() / hasAI() / hasMCP()
Small helpers to check how AI Engine is configured before you call anything else. hasAI() returns true when at least one AI environment has an API key, hasMCP() returns true when the MCP module is enabled, and getStatus() returns both of those plus the list of the available provider types.
The older checkStatus() is deprecated since AI Engine 3.5.0, please use the three functions above instead.