ai-engine
Last commit date
app
5 days ago
archives
7 months ago
classes
5 days ago
common
5 days ago
constants
5 days ago
images
2 months ago
labs
5 days ago
languages
5 months ago
notes
2 weeks ago
themes
1 month ago
vendor
1 year ago
ai-engine.php
5 days ago
changelog.txt
1 month ago
readme.txt
5 days ago
uninstall.php
11 months ago
ai-engine.php
73 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.7.3 |
| 8 | Requires at least: 6.0 |
| 9 | Requires PHP: 8.1 |
| 10 | Author: Jordy Meow |
| 11 | Author URI: https://jordymeow.com |
| 12 | Text Domain: ai-engine |
| 13 | License: GPLv2 or later |
| 14 | License URI: https://www.gnu.org/licenses/gpl-2.0.html |
| 15 | */ |
| 16 | |
| 17 | define( 'MWAI_VERSION', '3.7.3' ); |
| 18 | define( 'MWAI_PREFIX', 'mwai' ); |
| 19 | define( 'MWAI_DOMAIN', 'ai-engine' ); |
| 20 | define( 'MWAI_ENTRY', __FILE__ ); |
| 21 | define( 'MWAI_PATH', dirname( __FILE__ ) ); |
| 22 | define( 'MWAI_URL', plugin_dir_url( __FILE__ ) ); |
| 23 | define( 'MWAI_ITEM_ID', 17631833 ); |
| 24 | if ( !defined( 'MWAI_TIMEOUT' ) ) { |
| 25 | define( 'MWAI_TIMEOUT', 60 * 5 ); |
| 26 | } |
| 27 | if ( !defined( 'MWAI_SSL_VERIFY' ) ) { |
| 28 | // Verify TLS certificates by default (matches WordPress core). Outbound calls |
| 29 | // carry provider API keys, so disabling verification would expose them to MITM. |
| 30 | // Self-hosted endpoints with self-signed certs can opt out by defining this as |
| 31 | // false in wp-config.php. |
| 32 | define( 'MWAI_SSL_VERIFY', true ); |
| 33 | } |
| 34 | // What a fresh install lands on, and what anything without an explicit model falls back to. |
| 35 | // These must never point at a model tagged 'deprecated' in constants/models.php: the admin |
| 36 | // then shows a deprecation warning on a brand new site. Re-check them whenever a model is |
| 37 | // tagged deprecated there. |
| 38 | define( 'MWAI_FALLBACK_MODEL', 'gpt-5.6-terra' ); |
| 39 | define( 'MWAI_FALLBACK_MODEL_FAST', 'gpt-5.6-luna' ); |
| 40 | define( 'MWAI_FALLBACK_MODEL_VISION', 'gpt-5.6-luna' ); |
| 41 | define( 'MWAI_FALLBACK_MODEL_JSON', 'gpt-5.6-luna' ); |
| 42 | define( 'MWAI_FALLBACK_MODEL_IMAGES', 'gpt-image-2' ); |
| 43 | define( 'MWAI_FALLBACK_MODEL_AUDIO', 'whisper-1' ); |
| 44 | define( 'MWAI_FALLBACK_MODEL_EMBEDDINGS', 'text-embedding-3-small' ); |
| 45 | |
| 46 | require_once( MWAI_PATH . '/classes/init.php' ); |
| 47 | |
| 48 | add_filter( 'mwai_ai_exception', function ( $exception ) { |
| 49 | try { |
| 50 | // Remove the service prefix if present |
| 51 | if ( strpos( $exception, 'OpenAI:' ) === 0 ) { |
| 52 | $exception = trim( substr( $exception, strlen( 'OpenAI:' ) ) ); |
| 53 | } |
| 54 | |
| 55 | // If the remaining string looks like JSON, try to decode it |
| 56 | $json = json_decode( $exception, true ); |
| 57 | if ( is_array( $json ) && isset( $json['error']['message'] ) ) { |
| 58 | $exception = $json['error']['message']; |
| 59 | } |
| 60 | |
| 61 | if ( strpos( $exception, 'OpenAI' ) !== false ) { |
| 62 | if ( strpos( $exception, 'API URL was not found' ) !== false ) { |
| 63 | 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."; |
| 64 | } |
| 65 | } |
| 66 | return $exception; |
| 67 | } |
| 68 | catch ( Exception $e ) { |
| 69 | error_log( $e->getMessage() ); |
| 70 | } |
| 71 | return $exception; |
| 72 | } ); |
| 73 |