ai-engine
Last commit date
app
9 months ago
archives
11 months ago
classes
9 months ago
common
9 months ago
constants
10 months ago
images
11 months ago
labs
10 months ago
themes
10 months ago
vendor
10 months ago
ai-engine.php
9 months ago
blueprint.json
2 years ago
dev-notes.md
11 months ago
readme.txt
9 months ago
uninstall.php
11 months ago
ai-engine.php
56 lines
| 1 | <?php |
| 2 | |
| 3 | /* |
| 4 | Plugin Name: AI Engine |
| 5 | Plugin URI: https://wordpress.org/plugins/ai-engine/ |
| 6 | Description: AI meets WordPress. Your site can now chat, write poetry, solve problems, and maybe make you coffee. |
| 7 | Version: 3.0.7 |
| 8 | Author: Jordy Meow |
| 9 | Author URI: https://jordymeow.com |
| 10 | Text Domain: ai-engine |
| 11 | License: GPLv2 or later |
| 12 | License URI: https://www.gnu.org/licenses/gpl-2.0.html |
| 13 | */ |
| 14 | |
| 15 | define( 'MWAI_VERSION', '3.0.7' ); |
| 16 | define( 'MWAI_PREFIX', 'mwai' ); |
| 17 | define( 'MWAI_DOMAIN', 'ai-engine' ); |
| 18 | define( 'MWAI_ENTRY', __FILE__ ); |
| 19 | define( 'MWAI_PATH', dirname( __FILE__ ) ); |
| 20 | define( 'MWAI_URL', plugin_dir_url( __FILE__ ) ); |
| 21 | define( 'MWAI_ITEM_ID', 17631833 ); |
| 22 | if ( !defined( 'MWAI_TIMEOUT' ) ) { |
| 23 | define( 'MWAI_TIMEOUT', 60 * 5 ); |
| 24 | } |
| 25 | define( 'MWAI_FALLBACK_MODEL', 'gpt-5-chat-latest' ); |
| 26 | define( 'MWAI_FALLBACK_MODEL_VISION', 'gpt-5-chat-latest' ); |
| 27 | define( 'MWAI_FALLBACK_MODEL_JSON', 'gpt-5-mini' ); |
| 28 | |
| 29 | require_once( MWAI_PATH . '/classes/init.php' ); |
| 30 | |
| 31 | add_filter( 'mwai_ai_exception', function ( $exception ) { |
| 32 | try { |
| 33 | // Remove the service prefix if present |
| 34 | if ( strpos( $exception, 'OpenAI:' ) === 0 ) { |
| 35 | $exception = trim( substr( $exception, strlen( 'OpenAI:' ) ) ); |
| 36 | } |
| 37 | |
| 38 | // If the remaining string looks like JSON, try to decode it |
| 39 | $json = json_decode( $exception, true ); |
| 40 | if ( is_array( $json ) && isset( $json['error']['message'] ) ) { |
| 41 | $exception = $json['error']['message']; |
| 42 | } |
| 43 | |
| 44 | if ( strpos( $exception, 'OpenAI' ) !== false ) { |
| 45 | if ( strpos( $exception, 'API URL was not found' ) !== false ) { |
| 46 | return "Received the 'API URL was not found' error from OpenAI. This actually means that your OpenAI account has not been enabled for the Chat API. You need to either add some credits to OpenAI account, or link a credit card to it."; |
| 47 | } |
| 48 | } |
| 49 | return $exception; |
| 50 | } |
| 51 | catch ( Exception $e ) { |
| 52 | error_log( $e->getMessage() ); |
| 53 | } |
| 54 | return $exception; |
| 55 | } ); |
| 56 |