Plugin Directory

Changeset 3464404


Ignore:
Timestamp:
02/18/2026 02:22:01 PM (5 weeks ago)
Author:
webdigit
Message:

Version 2.6.3 : correctifs mineurs et optimisation interne

Location:
smartsearchwp/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • smartsearchwp/trunk/includes/addons/class-wdgpt-addons-manager.php

    r3241701 r3464404  
    184184        }
    185185
     186        $response_code = wp_remote_retrieve_response_code($response);
    186187        $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
    187225        if (strpos($body, 'license key is expired') !== false) {
    188226            $error_message = "Échec de l'installation : Clé de licence expirée.";
     
    208246        }
    209247
     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
    210256        $result = $upgrader->install( $source );
     257
    211258        if ( WDGPT_DEBUG_MODE ) {
    212259            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            );
    213265        }
    214266
  • smartsearchwp/trunk/includes/answers/class-wdgpt-answer-generator.php

    r3308086 r3464404  
    2424     */
    2525    private $api_key;
     26
     27    /**
     28     * The OpenAI API client.
     29     *
     30     * @var OpenAi
     31     */
     32    private $client;
    2633
    2734    /**
     
    424431        } catch ( Exception $e ) {
    425432            $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 ) );
    427434        }
    428435    }
     
    554561            $base_prompt = WDGPT_WooCommerce_OpenAI::instance()->wdgpt_woocommerce_format_base_prompt( $base_prompt, $contexts_with_embeddings );
    555562        }
     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 );
    556566
    557567        $final_prompt = $base_prompt . ' [PROVIDED CONTEXT]: ***' . $context . '***' . $permalinks;
     
    870880     */
    871881    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' );
    876885            }
    877             return 0.0; // Retourne 0 pour éviter un plantage
     886            return 0.0;
    878887        }
     888        $context = array_values( $context );
     889        $topic   = array_values( $topic );
    879890        $dot_product = 0.0;
    880         $count       = count( $context );
     891        $count       = min( count( $context ), count( $topic ) );
    881892        for ( $i = 0; $i < $count; $i++ ) {
    882893            $dot_product += $context[ $i ] * $topic[ $i ];
  • smartsearchwp/trunk/includes/answers/class-wdgpt-token-encoding.php

    r3199559 r3464404  
    6161            return;
    6262        }
    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 ) {
    6567            throw new \RuntimeException( 'Unable to load characters.json' );
    6668        }
    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 ) {
    7173            throw new \RuntimeException( 'Unable to load encoder.json' );
    7274        }
    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 ) {
    7779            throw new \RuntimeException( 'Unable to load vocab.bpe' );
    7880        }
    7981
    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 );
    8183        if ( false === $lines ) {
    8284            throw new \RuntimeException( 'Unable to split vocab.bpe' );
  • smartsearchwp/trunk/readme.txt

    r3395644 r3464404  
    55Requires at least: 4.7
    66Tested up to: 6.8.3
    7 Stable tag: 2.6.2
     7Stable tag: 2.6.3
    88Requires PHP: 7.4
    99License: GPLv2 or later
     
    9595
    9696== 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)
    97101
    98102= 2.6.2 =
  • smartsearchwp/trunk/wdgpt.php

    r3395644 r3464404  
    44 * Description: A chatbot that helps users navigate your website and find what they're looking for.
    55 * Plugin URI:  https://www.smartsearchwp.com/
    6  * Version:     2.6.2
     6 * Version:     2.6.3
    77 * Author:      Webdigit
    88 * Author URI:  https://www.smartsearchwp.com/
     
    1919}
    2020
    21 define( 'WDGPT_CHATBOT_VERSION', '2.6.2' );
     21define( 'WDGPT_CHATBOT_VERSION', '2.6.3' );
    2222
    2323// Définition de la constante globale pour le mode debug
Note: See TracChangeset for help on using the changeset viewer.