| @@ -1,9 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * Plugin Name: MxChat |
| 4 | 4 | * Description: AI Chatbot for WordPress with support for OpenAI, X.AI, and Claude models. Includes features like custom knowledge submission, chat transcripts, and seamless integration with WooCommerce. Perfect for blogs, business sites, e-commerce platforms, and more, offering real-time intelligent interactions with advanced AI models. |
| 5 | - * Version: 1.3 | |
| 5 | + * Version: 1.4 | |
| 6 | 6 | * Author: MxChat |
| 7 | 7 | * Author URI: https://mxchat.ai |
| 8 | 8 | * License: GPLv2 or later |
| 9 | 9 | * License URI: https://www.gnu.org/licenses/gpl-2.0.html |
| @@ -27,27 +27,28 @@ | ||
| 27 | 27 | |
| 28 | 28 | // Chat Transcripts Table |
| 29 | 29 | $chat_transcripts_table = $wpdb->prefix . 'mxchat_chat_transcripts'; |
| 30 | 30 | $sql_chat_transcripts = "CREATE TABLE $chat_transcripts_table ( |
| 31 | - id mediumint(9) NOT NULL AUTO_INCREMENT, | |
| 32 | - user_id mediumint(9) DEFAULT 0, | |
| 33 | - session_id varchar(255) NOT NULL, | |
| 34 | - role varchar(255) NOT NULL, | |
| 35 | - message text NOT NULL, | |
| 36 | - timestamp timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL, | |
| 37 | - PRIMARY KEY (id) | |
| 38 | - );"; | |
| 31 | + id MEDIUMINT(9) NOT NULL AUTO_INCREMENT, | |
| 32 | + user_id MEDIUMINT(9) DEFAULT 0, | |
| 33 | + session_id VARCHAR(255) NOT NULL, | |
| 34 | + role VARCHAR(255) NOT NULL, | |
| 35 | + message TEXT NOT NULL, | |
| 36 | + timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, | |
| 37 | + PRIMARY KEY (id) | |
| 38 | + ) $charset_collate;"; | |
| 39 | 39 | |
| 40 | 40 | // System Prompt Content Table |
| 41 | 41 | $system_prompt_table = $wpdb->prefix . 'mxchat_system_prompt_content'; |
| 42 | 42 | $sql_system_prompt = "CREATE TABLE $system_prompt_table ( |
| 43 | - id mediumint(9) NOT NULL AUTO_INCREMENT, | |
| 44 | - url varchar(255) NOT NULL, | |
| 45 | - article_content longtext NOT NULL, | |
| 46 | - embedding_vector longtext, | |
| 47 | - timestamp timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL, | |
| 48 | - PRIMARY KEY (id) | |
| 49 | - );"; | |
| 43 | + id MEDIUMINT(9) NOT NULL AUTO_INCREMENT, | |
| 44 | + url VARCHAR(255) NOT NULL, | |
| 45 | + article_content LONGTEXT NOT NULL, | |
| 46 | + embedding_vector LONGTEXT, | |
| 47 | + source_url VARCHAR(255) DEFAULT NULL, | |
| 48 | + timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, | |
| 49 | + PRIMARY KEY (id) | |
| 50 | + ) $charset_collate;"; | |
| 50 | 51 | |
| 51 | 52 | // Intents Table |
| 52 | 53 | $intents_table = $wpdb->prefix . 'mxchat_intents'; |
| 53 | 54 | $sql_intents_table = "CREATE TABLE $intents_table ( |
| @@ -55,72 +56,43 @@ | ||
| 55 | 56 | intent_label VARCHAR(255) NOT NULL, |
| 56 | 57 | phrases TEXT NOT NULL, |
| 57 | 58 | embedding_vector LONGTEXT NOT NULL, |
| 58 | 59 | callback_function VARCHAR(255) NOT NULL, |
| 59 | - PRIMARY KEY (id) | |
| 60 | + similarity_threshold FLOAT DEFAULT 0.85, | |
| 61 | + PRIMARY KEY (id) | |
| 60 | 62 | ) $charset_collate;"; |
| 61 | 63 | |
| 62 | - require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); | |
| 64 | + require_once ABSPATH . 'wp-admin/includes/upgrade.php'; | |
| 63 | 65 | |
| 64 | - // Create or update the chat transcripts table | |
| 66 | + // Create or update tables | |
| 65 | 67 | dbDelta($sql_chat_transcripts); |
| 66 | - | |
| 67 | - // Create or update the system prompt content table | |
| 68 | 68 | dbDelta($sql_system_prompt); |
| 69 | - | |
| 70 | - // Create or update the intents table | |
| 71 | 69 | dbDelta($sql_intents_table); |
| 72 | 70 | |
| 73 | - // Ensure 'embedding_vector' column exists in the 'system_prompt_content' table | |
| 74 | - $column_exists = $wpdb->get_results($wpdb->prepare( | |
| 75 | - "SHOW COLUMNS FROM {$system_prompt_table} LIKE %s", | |
| 76 | - 'embedding_vector' | |
| 77 | - )); | |
| 78 | - if (empty($column_exists)) { | |
| 79 | - $wpdb->query( | |
| 80 | - "ALTER TABLE {$system_prompt_table} ADD COLUMN embedding_vector longtext" | |
| 81 | - ); | |
| 82 | - } | |
| 71 | + // Ensure additional columns in `mxchat_system_prompt_content` and `mxchat_chat_transcripts` | |
| 72 | + mxchat_add_missing_columns($system_prompt_table, 'embedding_vector', 'LONGTEXT'); | |
| 73 | + mxchat_add_missing_columns($system_prompt_table, 'source_url', 'VARCHAR(255) DEFAULT NULL'); | |
| 74 | + mxchat_add_missing_columns($chat_transcripts_table, 'user_identifier', 'VARCHAR(255)'); | |
| 75 | + mxchat_add_missing_columns($chat_transcripts_table, 'user_email', 'VARCHAR(255)'); | |
| 83 | 76 | |
| 84 | - // Ensure 'source_url' column exists in the 'system_prompt_content' table | |
| 85 | - $source_url_exists = $wpdb->get_results($wpdb->prepare( | |
| 86 | - "SHOW COLUMNS FROM {$system_prompt_table} LIKE %s", | |
| 87 | - 'source_url' | |
| 88 | - )); | |
| 89 | - if (empty($source_url_exists)) { | |
| 90 | - $wpdb->query( | |
| 91 | - "ALTER TABLE {$system_prompt_table} ADD COLUMN source_url VARCHAR(255) DEFAULT NULL" | |
| 92 | - ); | |
| 93 | - } | |
| 77 | + // Set default thresholds for existing intents | |
| 78 | + $wpdb->query("UPDATE {$intents_table} SET similarity_threshold = 0.85 WHERE similarity_threshold IS NULL"); | |
| 94 | 79 | |
| 95 | - // Ensure 'user_identifier' and 'user_email' columns exist in the 'chat_transcripts' table | |
| 96 | - $user_identifier_exists = $wpdb->get_results($wpdb->prepare( | |
| 97 | - "SHOW COLUMNS FROM {$chat_transcripts_table} LIKE %s", | |
| 98 | - 'user_identifier' | |
| 99 | - )); | |
| 100 | - if (empty($user_identifier_exists)) { | |
| 101 | - $wpdb->query( | |
| 102 | - "ALTER TABLE {$chat_transcripts_table} ADD COLUMN user_identifier VARCHAR(255)" | |
| 103 | - ); | |
| 104 | - } | |
| 80 | + // Update plugin version in the database | |
| 81 | + update_option('mxchat_plugin_version', '1.4'); | |
| 82 | +} | |
| 105 | 83 | |
| 106 | - $user_email_exists = $wpdb->get_results($wpdb->prepare( | |
| 107 | - "SHOW COLUMNS FROM {$chat_transcripts_table} LIKE %s", | |
| 108 | - 'user_email' | |
| 109 | - )); | |
| 110 | - if (empty($user_email_exists)) { | |
| 111 | - $wpdb->query( | |
| 112 | - "ALTER TABLE {$chat_transcripts_table} ADD COLUMN user_email VARCHAR(255)" | |
| 113 | - ); | |
| 84 | +function mxchat_add_missing_columns($table, $column_name, $column_type) { | |
| 85 | + global $wpdb; | |
| 86 | + $column_exists = $wpdb->get_results($wpdb->prepare("SHOW COLUMNS FROM $table LIKE %s", $column_name)); | |
| 87 | + if (empty($column_exists)) { | |
| 88 | + $wpdb->query("ALTER TABLE $table ADD COLUMN $column_name $column_type"); | |
| 114 | 89 | } |
| 115 | - | |
| 116 | - // Update the version number in the database | |
| 117 | - update_option('mxchat_plugin_version', '1.3'); | |
| 118 | 90 | } |
| 119 | 91 | |
| 120 | 92 | function mxchat_check_for_update() { |
| 121 | 93 | $current_version = get_option('mxchat_plugin_version'); |
| 122 | - $plugin_version = '1.3'; | |
| 94 | + $plugin_version = '1.4'; | |
| 123 | 95 | |
| 124 | 96 | if ($current_version !== $plugin_version) { |
| 125 | 97 | mxchat_activate(); // Run the activation script which includes database migrations |
| 126 | 98 | update_option('mxchat_plugin_version', $plugin_version); // Update to the latest version |