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