ai-engine
Last commit date
app
1 year ago
archives
1 year ago
classes
1 year ago
common
1 year ago
constants
1 year ago
images
1 year ago
labs
1 year ago
themes
1 year ago
vendor
1 year ago
ai-engine.php
1 year ago
blueprint.json
2 years ago
dev-notes.md
1 year ago
readme.txt
1 year ago
uninstall.php
1 year 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: 2.8.5 |
| 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', '2.8.5' ); |
| 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-4.1-nano' ); |
| 26 | define( 'MWAI_FALLBACK_MODEL_VISION', 'gpt-4.1-nano' ); |
| 27 | define( 'MWAI_FALLBACK_MODEL_JSON', 'gpt-4.1-nano' ); |
| 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 |