Changeset 3464404
- Timestamp:
- 02/18/2026 02:22:01 PM (5 weeks ago)
- Location:
- smartsearchwp/trunk
- Files:
-
- 5 edited
-
includes/addons/class-wdgpt-addons-manager.php (modified) (2 diffs)
-
includes/answers/class-wdgpt-answer-generator.php (modified) (4 diffs)
-
includes/answers/class-wdgpt-token-encoding.php (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
-
wdgpt.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
smartsearchwp/trunk/includes/addons/class-wdgpt-addons-manager.php
r3241701 r3464404 184 184 } 185 185 186 $response_code = wp_remote_retrieve_response_code($response); 186 187 $body = wp_remote_retrieve_body($response); 188 $body_length = is_string($body) ? strlen($body) : 0; 189 $content_type = wp_remote_retrieve_header($response, 'content-type'); 190 $content_type = is_array($content_type) ? ( $content_type[0] ?? '' ) : (string) $content_type; 191 192 if ( WDGPT_DEBUG_MODE ) { 193 $is_zip = ( is_string($body) && $body_length >= 4 && substr($body, 0, 2) === 'PK' ); 194 WDGPT_Error_Logs::wdgpt_log_error( 195 sprintf( 196 'Addon download response | HTTP %s | body_length=%d | content-type=%s | body_looks_zip=%s', 197 $response_code, 198 $body_length, 199 $content_type, 200 $is_zip ? 'yes' : 'no' 201 ), 202 200, 203 'install_addon' 204 ); 205 if ( (int) $response_code === 200 && ! $is_zip && $body_length > 0 && $body_length < 500 ) { 206 WDGPT_Error_Logs::wdgpt_log_error('Addon response body (non-zip) preview: ' . substr($body, 0, 200), 200, 'install_addon'); 207 } 208 } 209 210 if ( 403 === (int) $response_code || 404 === (int) $response_code ) { 211 $error_message = sprintf( 212 "Téléchargement addon refusé (HTTP %d): %s", 213 $response_code, 214 is_string($body) && strlen($body) < 500 ? $body : wp_remote_retrieve_response_message($response) 215 ); 216 if ( WDGPT_DEBUG_MODE ) { 217 WDGPT_Error_Logs::get_instance()->insert_error_log($error_message, 0, 'addon_install_error'); 218 } 219 if ( 403 === (int) $response_code ) { 220 delete_transient('wdgpt_license_transient'); 221 } 222 return false; 223 } 224 187 225 if (strpos($body, 'license key is expired') !== false) { 188 226 $error_message = "Échec de l'installation : Clé de licence expirée."; … … 208 246 } 209 247 248 if ( WDGPT_DEBUG_MODE ) { 249 WDGPT_Error_Logs::wdgpt_log_error( 250 sprintf( 'Plugin_Upgrader->install() | addon_id=%s | activation_slug=%s | action=%s', $id, $activation_slug, $action ), 251 200, 252 'install_addon' 253 ); 254 } 255 210 256 $result = $upgrader->install( $source ); 257 211 258 if ( WDGPT_DEBUG_MODE ) { 212 259 WDGPT_Error_Logs::wdgpt_log_error('Installation result : ' . print_r($result, true), 200, 'install_addon'); 260 WDGPT_Error_Logs::wdgpt_log_error( 261 'Zip processing result : ' . ( ( $result && ! is_wp_error( $result ) ) ? 'success' : 'failure' . ( is_wp_error( $result ) ? ' | ' . $result->get_error_message() : '' ) ), 262 200, 263 'install_addon' 264 ); 213 265 } 214 266 -
smartsearchwp/trunk/includes/answers/class-wdgpt-answer-generator.php
r3308086 r3464404 24 24 */ 25 25 private $api_key; 26 27 /** 28 * The OpenAI API client. 29 * 30 * @var OpenAi 31 */ 32 private $client; 26 33 27 34 /** … … 424 431 } catch ( Exception $e ) { 425 432 $this->wdgpt_insert_error_log_message( $e->getMessage(), $e->getCode(), 'retrieve_topic_embedding' ); 426 return new WP_Error( 'server_error', $ response, array( 'status' => 500 ) );433 return new WP_Error( 'server_error', $e->getMessage(), array( 'status' => 500 ) ); 427 434 } 428 435 } … … 554 561 $base_prompt = WDGPT_WooCommerce_OpenAI::instance()->wdgpt_woocommerce_format_base_prompt( $base_prompt, $contexts_with_embeddings ); 555 562 } 563 564 // Permet aux addons (ex. Prompt Override) d'ajouter du contexte en tête du prompt (ex. date/heure CAG). 565 $base_prompt = apply_filters( 'wdgpt_base_prompt_before_context', $base_prompt ); 556 566 557 567 $final_prompt = $base_prompt . ' [PROVIDED CONTEXT]: ***' . $context . '***' . $permalinks; … … 870 880 */ 871 881 private function wdgpt_cosine_similarity( $context, $topic ) { 872 // Vérifie que les paramètres sont bien des tableaux 873 if (!is_array($context) || !is_array($topic)) { 874 if (WDGPT_DEBUG_MODE) { 875 WDGPT_Error_Logs::wdgpt_log_error('Invalid embeddings data - Context or Topic is not an array', 500, 'wdgpt_cosine_similarity'); 882 if ( ! is_array( $context ) || ! is_array( $topic ) ) { 883 if ( WDGPT_DEBUG_MODE ) { 884 WDGPT_Error_Logs::wdgpt_log_error( 'Invalid embeddings data - Context or Topic is not an array', 500, 'wdgpt_cosine_similarity' ); 876 885 } 877 return 0.0; // Retourne 0 pour éviter un plantage886 return 0.0; 878 887 } 888 $context = array_values( $context ); 889 $topic = array_values( $topic ); 879 890 $dot_product = 0.0; 880 $count = count( $context);891 $count = min( count( $context ), count( $topic ) ); 881 892 for ( $i = 0; $i < $count; $i++ ) { 882 893 $dot_product += $context[ $i ] * $topic[ $i ]; -
smartsearchwp/trunk/includes/answers/class-wdgpt-token-encoding.php
r3199559 r3464404 61 61 return; 62 62 } 63 $raw_characters = wp_remote_get( plugin_dir_url( __FILE__ ) . 'data/characters.json' ); 64 if ( is_wp_error( $raw_characters ) ) { 63 $data_dir = plugin_dir_path( __FILE__ ) . 'data/'; 64 65 $raw_characters_content = file_get_contents( $data_dir . 'characters.json' ); 66 if ( false === $raw_characters_content ) { 65 67 throw new \RuntimeException( 'Unable to load characters.json' ); 66 68 } 67 $this->raw_characters = json_decode( wp_remote_retrieve_body( $raw_characters ), true, 512, JSON_THROW_ON_ERROR );68 69 $encoder = wp_remote_get( plugin_dir_url( __FILE__ ) . 'data/encoder.json' );70 if ( is_wp_error( $encoder )) {69 $this->raw_characters = json_decode( $raw_characters_content, true, 512, JSON_THROW_ON_ERROR ); 70 71 $encoder_content = file_get_contents( $data_dir . 'encoder.json' ); 72 if ( false === $encoder_content ) { 71 73 throw new \RuntimeException( 'Unable to load encoder.json' ); 72 74 } 73 $this->encoder = json_decode( wp_remote_retrieve_body( $encoder ), true, 512, JSON_THROW_ON_ERROR );74 75 $bpe_dictionary = wp_remote_get( plugin_dir_url( __FILE__ ) . 'data/vocab.bpe' );76 if ( is_wp_error( $bpe_dictionary )) {75 $this->encoder = json_decode( $encoder_content, true, 512, JSON_THROW_ON_ERROR ); 76 77 $bpe_dictionary_content = file_get_contents( $data_dir . 'vocab.bpe' ); 78 if ( false === $bpe_dictionary_content ) { 77 79 throw new \RuntimeException( 'Unable to load vocab.bpe' ); 78 80 } 79 81 80 $lines = preg_split( '#\r\n|\r|\n#', wp_remote_retrieve_body( $bpe_dictionary ));82 $lines = preg_split( '#\r\n|\r|\n#', $bpe_dictionary_content ); 81 83 if ( false === $lines ) { 82 84 throw new \RuntimeException( 'Unable to split vocab.bpe' ); -
smartsearchwp/trunk/readme.txt
r3395644 r3464404 5 5 Requires at least: 4.7 6 6 Tested up to: 6.8.3 7 Stable tag: 2.6. 27 Stable tag: 2.6.3 8 8 Requires PHP: 7.4 9 9 License: GPLv2 or later … … 95 95 96 96 == Changelog == 97 98 = 2.6.3 = 99 * Fix undefined property and variable in answer generator (OpenAI client, error handling) 100 * Fix cosine similarity when embedding vectors have non-sequential keys (prevents PHP notices) 97 101 98 102 = 2.6.2 = -
smartsearchwp/trunk/wdgpt.php
r3395644 r3464404 4 4 * Description: A chatbot that helps users navigate your website and find what they're looking for. 5 5 * Plugin URI: https://www.smartsearchwp.com/ 6 * Version: 2.6. 26 * Version: 2.6.3 7 7 * Author: Webdigit 8 8 * Author URI: https://www.smartsearchwp.com/ … … 19 19 } 20 20 21 define( 'WDGPT_CHATBOT_VERSION', '2.6. 2' );21 define( 'WDGPT_CHATBOT_VERSION', '2.6.3' ); 22 22 23 23 // Définition de la constante globale pour le mode debug
Note: See TracChangeset
for help on using the changeset viewer.