Enhance WordPress AI with AI Engine Plugin: API Integration and Custom Fields

November 13, 2024

Anne Allen

AI Engine Plugin: API Integration and Custom Fields

Unleashing the Power of AI Engine’s API and Customization Features to add custom fields to AI Engine

The AI Engine plugin by Jordy Meow offers powerful features for developers seeking to enhance their website’s AI capabilities. From extensive API access to specialized filters, the plugin is built to be adaptable, allowing WordPress developers to seamlessly integrate its functionalities with other WordPress plugins and themes. If you’re looking to fully harness the plugin’s potential, particularly in embedding AI-powered knowledge databases, here’s what you need to know about its API, customization features, and embedding functionality.

Extensive API and Filters for Deep Customization

With AI Engine’s extensive API and customization options, developers can tap into a robust set of tools for tailored functionality. The plugin provides filters and hooks that allow for the modification and enhancement of AI Engine’s responses, giving developers full control over how AI interacts with content and users. Here are a few key points:

  • API Integration: The API allows seamless connection with other tools and plugins, making it easy to incorporate AI functionalities into existing setups.
  • Customization Through Filters: Custom filters enable developers to modify input and output at multiple stages. This flexibility is invaluable for creating a user experience that aligns with your website’s unique needs.

Leveraging PHP Functions and Classes

AI Engine includes specific PHP functions and classes designed to interact with its features, opening the door for developers to craft custom AI-driven solutions. This is particularly helpful for embedding features, as WordPress developers can use these tools to create customized solutions that interact with the WordPress website content and user queries in innovative ways. Whether you need specific data parsing or advanced knowledge indexing, AI Engine’s PHP functions offer the flexibility to make it happen.

Embeddings: The Heart of AI-Powered Knowledge Databases

One of the standout features of AI Engine’s Pro Version is its support for embeddings. This feature allows the creation of a knowledge index – a structured database that the AI can use to form more precise answers. Embeddings can be generated manually or dynamically, acting as a searchable index that enhances the AI’s responses based on the content within the site.

How AI Engine Embeddings Work:

  • Content-Based Indexing: AI Engine can generate embeddings using content directly from the website it’s installed on, making it an efficient tool for creating an AI-responsive knowledge base without the need for external databases.
  • Customization Filters for Embedding Creation: Several filters, such as mwai_pre_post_content, allow developers to access and manipulate raw post content. This filter can be used to add custom fields and other relevant information before the content is processed into embeddings.
  • Content Cleaning and Final Modification: Once AI Engine cleans the content, developers can use the mwai_post_content filter to make any last modifications, ensuring the final embeddings are concise and well-suited to the AI’s processing capacity.
  • Query Matching with mwai_context_search: This filter enables the AI to retrieve the most relevant embedding in response to a user’s query. By optimizing this filter, developers can fine-tune how closely the AI’s responses match user intent, creating a more intuitive and user-centered experience.

Add Custom Fields data to your AI Engine embeds

A common requirement might be to add custom post data (Event dates, Product Price, Publication name, Staff Team member positions, contact details etc) to your embeds so that the AI can provide information specific to your website. This needs some customization as the default embed mechanism only includes the Post/Page Title and a summary of the whatever is in the content editor

Fortunately Jeordy has provided a filter, mwai_pre_post_content, that we can use to manipulate the post object and add custom fields and other relevant information before the content is processed into embeddings.

Step 1: Manipulate the raw data to be provided for the Embed
<?php

add_filter('mwai_pre_post_content','ns_add_extra_info', 10, 2);
function ns_add_extra_info($content, $postId){

    $customfield=''; //Set Custom field string to empty because not all post types have this field

    //Determine what the post type is and setup content for each posttype
    switch (get_post_type($postId)) {
        case 'post':
            // Handle regular blog posts
            $prefix =  'Post';
            break;
            
        case 'page':
            // Handle static pages
            $prefix =  'Page';
            break;
            
        case 'portfolio':
            // Handle media attachments
            $prefix = "portfolio";
            $customfield = ' Site Domain is: ' .get_post_meta($postId,'_ns_porto_site_domain', true);
            break;
            
        case 'code-snippet':
            // Handle post revisions
            $prefix = "Code Snippet";
            break;
            
        default:
            // Handle custom post types or unknown types
            $prefix = "default";
            break;
    }
    
    return  'The Post Number is '.$postId.' Post Genre: '.$prefix.$customfield.' '.$content;
   
}

In this snippet, for each post that is to become the source of an embed, the raw content returned will start with
Post Number is: XXX
Post Genre is: portfolio
and if the Custom field _ns_porto_site_domain has content (Portfolio only) then that will be added with as Site Domain is:domain name
and then the content

Step 2: Manipulate the raw data to be provided for the Embed

Adapt the “Rewrite Content” text in the settings tab to include the extra data points to make sure that the “rewrite” process doesn’t strip them out

Adding Custom Fields to AI Engine

Now when you synch content, you can send extra important data

Customize Your AI Engine Installation

AI Engine’s powerful API, extensive filters, and embedding capabilities make it a standout choice for developers looking to add sophisticated AI-driven interactions to their websites. By leveraging the plugin’s API, PHP functions, and embedding tools, you can create a fully customized AI solution that aligns perfectly with your website’s content and user needs.

Ready to take your AI Engine installation to the next level? Whether you need assistance with embedding creation, API integration, or advanced customization, we are here to help. Get in touch today, and let’s make your website’s AI experience seamless and powerful!

Anne Allen

About the author

Hi, I’m Anne Allen. I’ve spent the last 15 years living and breathing WordPress. I’m passionate about helping business owners demystify their websites—whether that means keeping your site secure with proper maintenance, setting up complex Gravity Forms, or ensuring your content is accessible through ADA compliance. Let’s make your site work for you.