Set Limits

 

First, you need to enable the Statistics feature. Go to the dashboard of AI Engine and check the corresponding option:

Notion image

This will add a new tab in AI Engine settings. Now you can go to the "Queries" tab. Here, you will find a list of all the queries that are being made to your chatbot. You can also set limits here.

By the way, if you want to see the logs of any of these queries, you will need to go to the "Settings" tab and enable the "Queries Data" option.

Once you have enabled the limits, you have different settings that you can tweak, such as the number and type of credits (Queries, Tokens, and Dollars). You can also set the timeframe for each of these limits to reset.

Notion image

Be careful, there are three different settings tabs here: User, Guests, and System. Take a look at the message that will be sent by the chatbot when the user reaches its limit for each of those.

The "System" setting will apply to every type of user. It's kind of like your website's maximum limit, so make sure to set this up correctly as well.

Notion image
Notion image

If you want to customize the limits based on your users’ roles or any meta data please refer to our documentation on the matter : https://meowapps.com/ai-engine/faq/#limits-users-customers

 

If you are looking for ways to block access from different parameters, such as time (only available from 2 p.m to 4 p.m), currently, there are no out-of-the-box features to accomplish this. However, you can achieve it yourself by using AI Engine filters. By using the mwai_ai_allowed($allowed, $query, $limits) function, you can check the timing of the user's query and return an error message if the timeframe is not suitable for you.

You can also come up with a solution on the client side. Using JavaScript, you can check the current time and then select the chatbot using its ID to disable it. You can do this by either hiding it or disabling the input with CSS, or even deleting the DOM element. If you need help or an example, please reach out through the support link in this documentation! 😊

 

Can I use a credit system to limit my users ?

Sure ! Go read our documentation over there : FAQ | Meow Apps ! 🐈

 

Instead of setting limits in terms of "tokens" or "dollars," you can easily configure them based on "queries" for your users. This way, when using the filter, you'll be handling "questions" rather than a credit system. Although the underlying logic remains the same, where 1 credit equals 1 question, using the filter becomes more intuitive.

 

You have the flexibility to set a specific limit. Once this limit is reached, your user won't be able to make any more requests. However, you can dynamically adjust this limit by adding credits, perhaps through a purchase using Woocommerce or any other third-party plugin. Your role is simply to update the user-related value, and the system should seamlessly adapt.

 

Let's assume your user has a corresponding "custom_credits" value. When a user purchases credits, you just need to add them to this number.

add_filter( 'mwai_stats_credits', function ( $credits, $userId ) {
    $user = get_userdata( $userId );
    if ( !empty( $user->custom_credits ) ) {
        $credits = $user->custom_credits;
    }

    return $credits;
}, 10, 2);

This filter ensures that the user's custom credits value is considered, allowing for a smooth experience when managing queries or questions within your system.

 
ℹ️
Soon, the AI Engine will propose a new system for the Timeframes, which will make it easier for you to create subscription logics:

Rolling Window: Limits are based on the queries made in the preceding period, continuously updating. For example, within the last day up to the current moment. Ideal to avoid sudden spikes in number of queries.

 

Fixed Window: Limits are based on a defined calendar period, resetting at the start of each new period. For instance, limits reset daily at midnight. Ideal for predictable usage patterns.

 

Subscription Window: Limits reset based on the anniversary of the user's first query, e.g., monthly on the same day as the first ever query. This day can be overriden through a WordPress filter. Ideal for subscription-based services.

 
 

What if my user renew/change its subscription before the time period?

 

This code assumes you have a way to check the user's previous role and a way to know if a subscription has been renewed or not. But you can get the gist of the idea used here.

add_filter('mwai_stats_credits', function ($credits, $userId) {

    $roles_credits = array(
        'free' => 1,
        'trial' => 5,
        'pro' => 10,
        //...
    );

    $user = get_userdata( $userId );

    // Get the stored role (current/previous role)
    $stored_role = get_user_meta( $userId, 'role', true );
    $user_credits = $roles_credits[ $stored_role ];

    // Check if the user has changed roles
    if ( $user->roles[0] != $stored_role ) {
        // Update the stored role
        update_user_meta( $userId, 'role', $user->roles[0] );
    } else if ( get_user_meta( $userId, 'renew', true ) == 'yes' ) {
        // If the user has not changed roles and the 'renew' field is 'yes', add the new credits
        $user_credits += $roles_credits[ $user->roles[0] ];
        update_user_meta( $userId, 'renew', 'no' );
    }

    return $user_credits;
}, 10, 2);
Did this answer your question?
😞
😐
🤩