ai-engine
Last commit date
app
19 hours ago
archives
5 months ago
classes
19 hours ago
common
1 week ago
constants
19 hours ago
images
5 days ago
labs
19 hours ago
languages
3 months ago
themes
5 days ago
vendor
10 months ago
ai-engine.php
19 hours ago
blueprint.json
2 years ago
readme.txt
19 hours ago
uninstall.php
9 months ago
ai-engine.php
67 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.5.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.5.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 | if ( !defined( 'MWAI_SSL_VERIFY' ) ) { |
| 26 | // Verify TLS certificates by default (matches WordPress core). Outbound calls |
| 27 | // carry provider API keys, so disabling verification would expose them to MITM. |
| 28 | // Self-hosted endpoints with self-signed certs can opt out by defining this as |
| 29 | // false in wp-config.php. |
| 30 | define( 'MWAI_SSL_VERIFY', true ); |
| 31 | } |
| 32 | define( 'MWAI_FALLBACK_MODEL', 'gpt-5.5' ); |
| 33 | define( 'MWAI_FALLBACK_MODEL_FAST', 'gpt-5-mini' ); |
| 34 | define( 'MWAI_FALLBACK_MODEL_VISION', 'gpt-5-mini' ); |
| 35 | define( 'MWAI_FALLBACK_MODEL_JSON', 'gpt-5-mini' ); |
| 36 | define( 'MWAI_FALLBACK_MODEL_IMAGES', 'gpt-image-1.5' ); |
| 37 | define( 'MWAI_FALLBACK_MODEL_AUDIO', 'whisper-1' ); |
| 38 | define( 'MWAI_FALLBACK_MODEL_EMBEDDINGS', 'text-embedding-3-small' ); |
| 39 | |
| 40 | require_once( MWAI_PATH . '/classes/init.php' ); |
| 41 | |
| 42 | add_filter( 'mwai_ai_exception', function ( $exception ) { |
| 43 | try { |
| 44 | // Remove the service prefix if present |
| 45 | if ( strpos( $exception, 'OpenAI:' ) === 0 ) { |
| 46 | $exception = trim( substr( $exception, strlen( 'OpenAI:' ) ) ); |
| 47 | } |
| 48 | |
| 49 | // If the remaining string looks like JSON, try to decode it |
| 50 | $json = json_decode( $exception, true ); |
| 51 | if ( is_array( $json ) && isset( $json['error']['message'] ) ) { |
| 52 | $exception = $json['error']['message']; |
| 53 | } |
| 54 | |
| 55 | if ( strpos( $exception, 'OpenAI' ) !== false ) { |
| 56 | if ( strpos( $exception, 'API URL was not found' ) !== false ) { |
| 57 | 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."; |
| 58 | } |
| 59 | } |
| 60 | return $exception; |
| 61 | } |
| 62 | catch ( Exception $e ) { |
| 63 | error_log( $e->getMessage() ); |
| 64 | } |
| 65 | return $exception; |
| 66 | } ); |
| 67 |