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( $prompt, $options )
You can use this function to simply run a query against the default model (turbo, currently). 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, $chatId )
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 )
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 )
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.
moderationCheck( $text )
Simply return true if the message has been flagged as unsafe to use.