Plugin Directory

Changeset 3206999


Ignore:
Timestamp:
12/12/2024 01:10:38 PM (16 months ago)
Author:
flag92
Message:

Add AI Instructions

Location:
click-n-chat
Files:
138 added
6 edited

Legend:

Unmodified
Added
Removed
  • click-n-chat/trunk/README.txt

    r3185652 r3206999  
    55Tested up to: 6.6
    66Requires PHP: 5.6.4
    7 Stable tag: 1.0.6
     7Stable tag: 1.0.7
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    117117== Changelog ==
    118118
     119= 1.0.7 12 December 2024 =
     120Add AI Instructions
     121
    119122= 1.0.6 11 November 2024 =
    120123Update pop style
  • click-n-chat/trunk/admin/includes/pages/click_n_chat_chatgpt.php

    r3180661 r3206999  
    2020        $click_n_chat_setting_chatgpt->frequency_penalty = sanitize_text_field($_POST['frequency_penalty']);
    2121        $click_n_chat_setting_chatgpt->ai_models = sanitize_text_field($_POST['ai_models']);
    22         $click_n_chat_setting_chatgpt->include_auto_reply = $_POST['include_auto_reply'] == "on" ? 1 : 0;
     22        $click_n_chat_setting_chatgpt->ai_instructions =  ($_POST['ai_instructions']);
    2323       
    2424        update_option('click_n_chat_setting_chatgpt', $click_n_chat_setting_chatgpt);
     
    8888                    <div class="form-field">
    8989                        <label for="is_active">Include Auto Reply: </label>
    90                         <label class="cnc-switch">
    91                             <input name="include_auto_reply" id="include_auto_reply" class="cnc-user-status" type="checkbox" <?php echo esc_html(($click_n_chat_setting_chatgpt->include_auto_reply == "1" ? "checked" : ""));  ?> >
     90                        <label class="cnc-switch cnc-pro-label">
     91                            <input name="include_auto_reply"   class="cnc-user-status" type="checkbox" disabled="disabled"  >
    9292                            <span class="cnc-switch-slider"></span>
    9393                        </label>
     
    105105            <div class="cnc-container cnc-bg-white cnc-shadow">
    106106                <div class="tab-pane fade" id="instructions" role="tabpanel" aria-labelledby="instructions-tab">
    107                      <div class="form-field cnc-pro-label">
    108                         <label for="is_active">Open AI Instructions: </label>
    109                         <textarea rows="10" style="width:100%" disabled="disabled">You are a virtual assistant for a clothing store, specifically designed to help customers with the checkout process. Assist customers by guiding them through each step of the checkout process, including reviewing their cart, applying discount codes, selecting shipping options, and completing payment. Provide clear and accurate information, and ensure a smooth and user-friendly checkout experience. Address any questions or issues they may have related to the checkout process.
    110 
    111 # Style
    112 Respond to the user inquiry in HTML format. Format the text with appropriate HTML tags, including <strong> for bold text, <ul> and <li> for lists, and <p> for paragraphs.</textarea>
     107                     <div class="form-field">
     108                        <label for="is_active">Open AI Instructions (max 1000 character): </label>
     109                        <textarea maxlength="1000" name="ai_instructions" rows="10" style="width:100%"><?php echo esc_html($click_n_chat_setting_chatgpt->ai_instructions);  ?></textarea>
    113110                        <p id="name-description">
    114111                            <b>Open AI Instructions:</b> is a message you give to an AI assistant to tell it how to behave or what role it should play. Think of it like setting instructions for a helper who's about to assist you. For instance, if you want the AI to act like a friendly shopping assistant who helps with online orders, you would include that information in the system content.
  • click-n-chat/trunk/assets/css/style.css

    r3198284 r3206999  
    166166    padding: 15px; 
    167167    /*text-align: center;*/ 
    168     border-radius: 10px 10px 0 0; 
     168    border-radius: 10px 10px 0 0;
    169169    margin-bottom: 10px; 
    170170    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.15); 
     
    249249.rcnc-message-icon {
    250250    position: absolute;
    251     left: -35px;
     251    left: -40px;
    252252    border-radius: 50%;
    253253    top:0px;
  • click-n-chat/trunk/classes/click_n_chat_setting_chatgpt.php

    r3180661 r3206999  
    1212        public $frequency_penalty = '1';
    1313        public $ai_models = 'gpt-3.5-turbo';
    14         public $include_auto_reply = '1';
     14        public $ai_instructions = 'You are a virtual assistant for a clothing store, specifically designed to help customers with the checkout process. Assist customers by guiding them through each step of the checkout process, including reviewing their cart, applying discount codes, selecting shipping options, and completing payment. Provide clear and accurate information, and ensure a smooth and user-friendly checkout experience. Address any questions or issues they may have related to the checkout process.';
    1515    }
    1616}
  • click-n-chat/trunk/click-n-chat.php

    r3185652 r3206999  
    44Plugin URI: http://www.flag92.com/
    55Description: Chat n Click allows you to connect with website visitors through their favorite social channels by displaying a floating chat icon at the bottom of your site. With features like AI chat, auto-reply, widget customization, you can ensure seamless communication and enhance visitor engagement across multiple platforms.
    6 Version: 1.0.6
     6Version: 1.0.7
    77Author: Flag92
    88Domain Path: /languages
  • click-n-chat/trunk/includes/ajax/click_n_chat_ajax_get_ai_reply.php

    r3180661 r3206999  
    1919   
    2020   
    21     $reply_message = "";
    22     if($click_n_chat_setting_chatgpt->include_auto_reply == "1")
     21     
     22    $url = 'https://api.openai.com/v1/chat/completions';
     23       
     24    $data = [
     25        'model' => $click_n_chat_setting_chatgpt->ai_models,
     26        'messages' => [
     27            ['role' => 'system', 'content' => 'Hello! How can I help you today?'],
     28            ['role' => 'user', 'content' => $message]
     29        ],
     30        'max_tokens' =>  (float)$click_n_chat_setting_chatgpt->max_token,
     31        'temperature' =>  (float)$click_n_chat_setting_chatgpt->temperature,
     32        'presence_penalty' =>  (float)$click_n_chat_setting_chatgpt->presence_penalty,
     33        'frequency_penalty' =>  (float)$click_n_chat_setting_chatgpt->frequency_penalty
     34    ];
     35   
     36    $args = [
     37        'headers' => [
     38            'Authorization' => 'Bearer ' . $click_n_chat_setting_chatgpt->api_key,
     39            'Content-Type'  => 'application/json',
     40        ],
     41        'body' => wp_json_encode($data),  // Ensure the data is in JSON format
     42        'method' => 'POST',
     43        'timeout' => 30, // Timeout in seconds
     44    ];
     45    $response = wp_remote_post($url, $args);
     46   
     47    if (is_wp_error($response)) {
     48        $reply_message = 'Error: ' . $response->get_error_message();
     49    }
     50    else
    2351    {
    24         $click_n_chat_setting_autoreply = get_option('click_n_chat_setting_autoreply');
    2552       
    26         $table_name = $wpdb->prefix . 'cnc_auto_reply';
    27         $autoreplies = $wpdb->get_results("SELECT * FROM $table_name");
    28         $response = (object)click_n_chat_calculate_similarities_ai($autoreplies, $message);
     53        $response_body = wp_remote_retrieve_body($response);
     54        $responseData = json_decode($response_body);
     55
     56        if(isset($responseData->choices[0]->message->content))
     57            $reply_message = $responseData->choices[0]->message->content;
     58        else
     59            $reply_message = $responseData->error->message;
    2960       
    30         if($response->query_similarity >= $click_n_chat_setting_autoreply->matching_percenage  || $response->keyword_similarity >= $click_n_chat_setting_autoreply->matching_percenage)
    31         {
    32             $reply_message = $response->reply;
    33         }
    3461    }
    35      
    36     if($reply_message == "")
    37     {
    38         $url = 'https://api.openai.com/v1/chat/completions';
    39        
    40         $data = [
    41             'model' => $click_n_chat_setting_chatgpt->ai_models,
    42             'messages' => [
    43                 ['role' => 'system', 'content' => 'Hello! How can I help you today?'],
    44                 ['role' => 'user', 'content' => $message]
    45             ],
    46             'max_tokens' =>  (float)$click_n_chat_setting_chatgpt->max_token,
    47             'temperature' =>  (float)$click_n_chat_setting_chatgpt->temperature,
    48             'presence_penalty' =>  (float)$click_n_chat_setting_chatgpt->presence_penalty,
    49             'frequency_penalty' =>  (float)$click_n_chat_setting_chatgpt->frequency_penalty
    50         ];
    51        
    52         $args = [
    53             'headers' => [
    54                 'Authorization' => 'Bearer ' . $click_n_chat_setting_chatgpt->api_key,
    55                 'Content-Type'  => 'application/json',
    56             ],
    57             'body' => wp_json_encode($data),  // Ensure the data is in JSON format
    58             'method' => 'POST',
    59             'timeout' => 30, // Timeout in seconds
    60         ];
    61         $response = wp_remote_post($url, $args);
    62        
    63         if (is_wp_error($response)) {
    64             $reply_message = 'Error: ' . $response->get_error_message();
    65         }
    66         else
    67         {
    68            
    69             $response_body = wp_remote_retrieve_body($response);
    70             $responseData = json_decode($response_body);
    7162
    72             if(isset($responseData->choices[0]->message->content))
    73                 $reply_message = $responseData->choices[0]->message->content;
    74             else
    75                 $reply_message = $responseData->error->message;
    76            
    77         }
    78     }
    7963 
    8064    wp_send_json([
     
    8266    ]);
    8367
    84 
    85 function click_n_chat_calculate_similarities_ai($array, $user_keyword) {
    86     $results = [];
    87 
    88     // Compare each query and keyword with the user_keyword
    89     foreach ($array as $item) {
    90         $query_similarity = 0;
    91         $keyword_similarity = 0;
    92 
    93         // Calculate similarity percentages
    94         similar_text(strtolower($item->query), strtolower($user_keyword), $query_similarity);
    95         similar_text(strtolower($item->keyword), strtolower($user_keyword), $keyword_similarity);
    96 
    97         // Add the results to the array
    98         $results[] = [
    99             'query' => $item->query,
    100             'keyword' => $item->keyword,
    101             'reply' => $item->reply,
    102             'query_similarity' => $query_similarity,
    103             'keyword_similarity' => $keyword_similarity
    104         ];
    105     }
    106 
    107     // Sort the results by query_similarity and keyword_similarity in descending order
    108     usort($results, function($a, $b) {
    109         // Compare by query_similarity first
    110         if ($a['query_similarity'] == $b['query_similarity']) {
    111             // If query_similarity is the same, compare by keyword_similarity
    112             return $b['keyword_similarity'] <=> $a['keyword_similarity'];
    113         }
    114         return $b['query_similarity'] <=> $a['query_similarity'];
    115     });
    116 
    117     return $results[0];
    118 }   
     68 
    11969 
    12070add_action('wp_ajax_click_n_chat_get_ai_action', 'click_n_chat_get_ai_action_handler'); 
Note: See TracChangeset for help on using the changeset viewer.