2 min read 2 days ago

PHP Filters

Backend Filters PHP

Interactions with AI

  • mwai_ai_query( $query ) => Modify a query before it’s made
  • mwai_ai_instructions( $instructions ) => Modify the instructions (you can add the current day, time, information about the current user, etc)
  • mwai_ai_allowed( $allowed, $query, $limits ) => Allow a query to be made or not
  • mwai_ai_reply( $reply, $query ) => Modify the answer before it’s sent (or do something at that time)
  • mwai_ai_function( $value, $funcName, $funcArgs ) => Inject the result of your own function, if in the case the function has been registered (function calling) and called by the model
  • mwai_ai_exception( $message ) => Modify the error message
  • mwai_estimate_tokens( $tokens, $text ) => Modify the estimated number of tokens for the given text (you can modify the default algorithm) used to calculate the tokens usage estimation.

Chatbot

  • mwai_chatbot_params( $params ) => Modify the final params just before the query is made
  • mwai_chatbot_takeover( $takeoverText, $query, $params )
  • mwai_contentaware_content( $content ) => Handle extra use cases, like looking for content in specific fields, or handling page builders, etc
  • mwai_chatbot_reply( $rawText, $query, $params, $extra ) => Modify the answer before it’s sent.

Embeddings

  • mwai_pre_post_content( $content, $postId ): Get the raw content from the post. You can modify it to add your custom field, etc. AI Engine will clean that content further, and make sure it’s not too large for the AI model.
  • mwai_post_content( $content, $postId ): The final content that will be used. You can also modify this.
  • mwai_context_search( $query, $embeddingIndex = null ): Returns the embedding the most related to the query.

Forms

  • mwai_form_params( $params ) => Modify the final params
  • mwai_form_reply( $rawText ) => Modify the answer before it’s sent

Limits

  • mwai_stats_credits( $credits, $userId ) => Modify the number of credits (that allows you to create your own system)
  • mwai_stats_coins( $price, $stats, $atts ) => Modify the coins (that allows you to convert the price you personally pay to OpenAI to your own system of coins that you share with your users)

Others

  • mwai_languages( $languages ) => Modify the list of languages
  • mwai_allow_setup( $hasAccess ) => Allow access to the Settings of AI Engine in the Admin
  • mwai_allow_usage( $hasAccess ) => Allow access to the various screens of AI Engine in the Admin