Changeset 3440069
- Timestamp:
- 01/15/2026 07:05:57 AM (2 months ago)
- Location:
- click-n-chat/trunk
- Files:
-
- 8 edited
-
README.txt (modified) (8 diffs)
-
admin/assets/js/admin-script.js (modified) (1 diff)
-
admin/includes/click_n_chat_menu.php (modified) (1 diff)
-
admin/includes/pages/click_n_chat_chatgpt.php (modified) (5 diffs)
-
admin/includes/pages/click_n_chat_setting.php (modified) (12 diffs)
-
classes/click_n_chat_setting_chatgpt.php (modified) (2 diffs)
-
click-n-chat.php (modified) (1 diff)
-
includes/ajax/click_n_chat_ajax_get_ai_reply.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
click-n-chat/trunk/README.txt
r3433801 r3440069 5 5 Tested up to: 6.9 6 6 Requires PHP: 5.6.4 7 Stable tag: 1. 0.97 Stable tag: 1.1.0 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html 10 10 11 11 12 Connect with your website visitors using a free floating chat widget that supports WhatsApp, Telegram, Messenger, Instagram, Email, SMS, and more.12 All-in-one floating chat widget with social platforms, smart auto replies, AI chatbot integration, analytics tracking, and full customization. 13 13 14 14 == Description == … … 56 56 --- 57 57 58 ### 2. Social User Profile Management 58 ### 2. AI-Powered Chatbot (Multi-Provider) 59 - **Enhance conversations using modern AI providers** 60 - Supported AI Providers 61 - OpenAI (ChatGPT) 62 - Claude (Anthropic) 63 - Google Gemini 64 - HuggingFace Inference API 65 - Cohere 66 - DeepSeek 67 - **Key Highlights** 68 - Switch AI providers anytime from settings 69 - Only required API fields appear dynamically 70 - Unified AI engine (single backend class) 71 - HTML-formatted AI responses for clean chat display 72 - Compatible with PHP 7.4+ 73 74 --- 75 76 ### 3. Social User Profile Management 59 77 - Create multiple chat profiles 60 78 - Set agent name, role, and description … … 66 84 --- 67 85 68 ### 3. Floating Chat Widget86 ### 4. Floating Chat Widget 69 87 - Clean bottom-right popup chat button 70 88 - Displays all active chat platforms … … 74 92 --- 75 93 76 ### 4. Auto-Reply Chatbot94 ### 5. Auto-Reply Chatbot 77 95 - Keyword and query-based auto replies 78 96 - Percentage-based matching for accuracy … … 82 100 --- 83 101 84 ### 5. Design & Customization102 ### 6. Design & Customization 85 103 - Popup header text and colors 86 104 - Padding, borders, and icons … … 90 108 --- 91 109 92 ### 6. Google Analytics Integration110 ### 7. Google Analytics Integration 93 111 - Track chat widget clicks 94 112 - Supports GA4 and Universal Analytics … … 97 115 --- 98 116 99 ### 7. Responsive & Developer-Friendly117 ### 8. Responsive & Developer-Friendly 100 118 - Works on desktop, tablet, and mobile 101 119 - Cross-browser compatible … … 137 155 == Changelog == 138 156 139 = 1.0.9 12 December 2024 = 157 = 1.1.0 15 January 2026 = 158 * Updated chat icon 159 * AI Provider Integration (Multi-AI Support) 160 161 = 1.0.9 12 December 2025 = 140 162 * Updated chat icon 141 163 * Tested with latest WordPress version -
click-n-chat/trunk/admin/assets/js/admin-script.js
r3267900 r3440069 387 387 $('#' + tabId).show(); 388 388 }); 389 390 function toggleApiFields() { 391 const provider = document.getElementById('ai_provider').value; 392 393 document.querySelectorAll('.cnc-ai-key').forEach(function (el) { 394 el.style.display = 'none'; 395 }); 396 397 const active = document.querySelector( 398 '.cnc-ai-key[data-provider="' + provider + '"]' 399 ); 400 401 if (active) { 402 active.style.display = 'block'; 403 } 404 } 405 406 document.getElementById('ai_provider').addEventListener( 407 'change', 408 toggleApiFields 409 ); 410 411 // Run on page load 412 toggleApiFields(); 389 413 }); 390 414 -
click-n-chat/trunk/admin/includes/click_n_chat_menu.php
r3267900 r3440069 85 85 <a href="?page=wa-clicknchat&tab=woocommerce" class="cnc-nav-tab <?php echo esc_html($active_tab == 'woocommerce' ? 'nav-tab-is-active' : ''); ?>">WooCommerce</a> 86 86 87 <a href="?page=wa-clicknchat&tab=chatgpt" class="cnc-nav-tab <?php echo esc_html($active_tab == 'chatgpt' ? 'nav-tab-is-active' : ''); ?>"> ChatGPT</a>87 <a href="?page=wa-clicknchat&tab=chatgpt" class="cnc-nav-tab <?php echo esc_html($active_tab == 'chatgpt' ? 'nav-tab-is-active' : ''); ?>">AI Integration</a> 88 88 89 89 <a href="?page=wa-clicknchat&tab=autoreply" class="cnc-nav-tab <?php echo esc_html($active_tab == 'autoreply' ? 'nav-tab-is-active' : ''); ?>">Auto Reply</a> -
click-n-chat/trunk/admin/includes/pages/click_n_chat_chatgpt.php
r3267900 r3440069 14 14 } 15 15 $click_n_chat_setting_chatgpt = new click_n_chat_setting_chatgpt(); 16 $click_n_chat_setting_chatgpt->api_key = sanitize_text_field($_POST['api_key']); 16 17 $click_n_chat_setting_chatgpt->ai_provider = sanitize_text_field($_POST['ai_provider']); 18 19 $click_n_chat_setting_chatgpt->openai_api_key = sanitize_text_field($_POST['openai_api_key']); 20 $click_n_chat_setting_chatgpt->claude_api_key = sanitize_text_field($_POST['claude_api_key']); 21 $click_n_chat_setting_chatgpt->huggingface_api_key = sanitize_text_field($_POST['huggingface_api_key']); 22 $click_n_chat_setting_chatgpt->gemini_api_key = sanitize_text_field($_POST['gemini_api_key']); 23 $click_n_chat_setting_chatgpt->cohere_api_key = sanitize_text_field($_POST['cohere_api_key']); 24 $click_n_chat_setting_chatgpt->deepseek_api_key = sanitize_text_field($_POST['deepseek_api_key']); 25 17 26 $click_n_chat_setting_chatgpt->max_token = sanitize_text_field($_POST['max_token']); 18 27 $click_n_chat_setting_chatgpt->temperature = sanitize_text_field($_POST['temperature']); … … 20 29 $click_n_chat_setting_chatgpt->frequency_penalty = sanitize_text_field($_POST['frequency_penalty']); 21 30 $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;23 $click_n_chat_setting_chatgpt->ai_instructions = ($_POST['ai_instructions']);31 $click_n_chat_setting_chatgpt->include_auto_reply = isset($_POST['include_auto_reply']) ? 1 : 0; 32 $click_n_chat_setting_chatgpt->ai_instructions = wp_kses_post($_POST['ai_instructions']); 24 33 25 34 update_option('click_n_chat_setting_chatgpt', $click_n_chat_setting_chatgpt); … … 41 50 <div class="tab-pane fade show active" id="chatgpt" role="tabpanel" aria-labelledby="chatgpt-tab"> 42 51 <div class="form-field"> 43 <label for="is_active">API Key: </label> 44 <input name="api_key" type="password" id="api_key" value="<?php echo esc_html($click_n_chat_setting_chatgpt->api_key); ?>" class="regular-text"> 45 </div> 52 <label>AI Provider:</label> 53 <select name="ai_provider" id="ai_provider" class="form-select cnc-select"> 54 <option value="openai" <?php selected($click_n_chat_setting_chatgpt->ai_provider, 'openai'); ?>>OpenAI</option> 55 <option value="claude" <?php selected($click_n_chat_setting_chatgpt->ai_provider, 'claude'); ?>>Claude (Anthropic)</option> 56 <option value="huggingface" <?php selected($click_n_chat_setting_chatgpt->ai_provider, 'huggingface'); ?>>HuggingFace</option> 57 <option value="gemini" <?php selected($click_n_chat_setting_chatgpt->ai_provider, 'gemini'); ?>>Google Gemini</option> 58 <option value="cohere" <?php selected($click_n_chat_setting_chatgpt->ai_provider, 'cohere'); ?>>Cohere</option> 59 <option value="deepseek" <?php selected($click_n_chat_setting_chatgpt->ai_provider, 'deepseek'); ?>>DeepSeek</option> 60 </select> 61 </div> 62 <div class="form-field cnc-ai-key" data-provider="openai"> 63 <label>OpenAI API Key</label> 64 <input type="password" name="openai_api_key" 65 value="<?php echo esc_attr($click_n_chat_setting_chatgpt->openai_api_key); ?>" 66 class="regular-text"> 67 </div> 68 69 70 <div class="form-field cnc-ai-key" data-provider="claude"> 71 <label>Claude API Key</label> 72 <input type="password" name="claude_api_key" 73 value="<?php echo esc_attr($click_n_chat_setting_chatgpt->claude_api_key); ?>" 74 class="regular-text"> 75 </div> 76 77 78 <div class="form-field cnc-ai-key" data-provider="huggingface"> 79 <label>HuggingFace API Key</label> 80 <input type="password" name="huggingface_api_key" 81 value="<?php echo esc_attr($click_n_chat_setting_chatgpt->huggingface_api_key); ?>" 82 class="regular-text"> 83 </div> 84 85 86 <div class="form-field cnc-ai-key" data-provider="gemini"> 87 <label>Gemini API Key</label> 88 <input type="password" name="gemini_api_key" 89 value="<?php echo esc_attr($click_n_chat_setting_chatgpt->gemini_api_key); ?>" 90 class="regular-text"> 91 </div> 92 93 94 <div class="form-field cnc-ai-key" data-provider="cohere"> 95 <label>Cohere API Key</label> 96 <input type="password" name="cohere_api_key" 97 value="<?php echo esc_attr($click_n_chat_setting_chatgpt->cohere_api_key); ?>" 98 class="regular-text"> 99 </div> 100 101 102 <div class="form-field cnc-ai-key" data-provider="deepseek"> 103 <label>DeepSeek API Key</label> 104 <input type="password" name="deepseek_api_key" 105 value="<?php echo esc_attr($click_n_chat_setting_chatgpt->deepseek_api_key); ?>" 106 class="regular-text"> 107 </div> 108 <div class="form-field"> 109 <select name="ai_models" class="form-select cnc-select"> 110 111 <optgroup label="OpenAI"> 112 <option value="gpt-3.5-turbo">GPT-3.5 Turbo</option> 113 <option value="gpt-4">GPT-4</option> 114 <option value="gpt-4o">GPT-4o</option> 115 </optgroup> 116 117 <optgroup label="Claude"> 118 <option value="claude-3-opus">Claude 3 Opus</option> 119 <option value="claude-3-sonnet">Claude 3 Sonnet</option> 120 </optgroup> 121 122 <optgroup label="HuggingFace"> 123 <option value="meta-llama/Llama-3-8b-chat-hf">LLaMA-3</option> 124 <option value="mistralai/Mistral-7B-Instruct">Mistral</option> 125 </optgroup> 126 127 <optgroup label="Gemini"> 128 <option value="gemini-1.5-flash">Gemini Flash</option> 129 <option value="gemini-1.5-pro">Gemini Pro</option> 130 </optgroup> 131 132 <optgroup label="Cohere"> 133 <option value="command-r">Command-R</option> 134 <option value="command-r-plus">Command-R+</option> 135 </optgroup> 136 137 <optgroup label="DeepSeek"> 138 <option value="deepseek-chat">DeepSeek Chat</option> 139 </optgroup> 140 141 </select> 142 </div> 143 46 144 <div class="form-field"> 47 145 <label for="is_active">Max Tokens (0 - 4000): </label> … … 75 173 </p> 76 174 </div> 77 <div class="form-field"> 78 <label for="is_active">ChatGPT AI Models: </label> 79 <select name="ai_models" class="form-select cnc-select"> 80 <option <?php echo esc_html($click_n_chat_setting_chatgpt->ai_models == "gpt-3.5-turbo" ? 'selected' : ''); ?> value="gpt-3.5-turbo">GPT-3 turbo</option> 81 <option <?php echo esc_html($click_n_chat_setting_chatgpt->ai_models == "gpt-4" ? 'selected' : ''); ?> value="gpt-4">GPT-4</option> 82 </select> 83 </div> 175 84 176 <div class="form-field"> 85 177 <label for="is_active">Include Auto Reply: </label> … … 95 187 </div> 96 188 <p class="submit"> 97 <input type="submit" name="submit" id="submit" class="button button-primary" value="Update ChatGPTSetting">189 <input type="submit" name="submit" id="submit" class="button button-primary" value="Update AI Setting"> 98 190 </p> 99 191 </div> -
click-n-chat/trunk/admin/includes/pages/click_n_chat_setting.php
r3267900 r3440069 261 261 <br /> 262 262 <p style="color:#3d3d3d; font-size:11px; color:#FFFFFF"> 263 <b>Click n Chat</b> Social Solution with AI-driven ChatGPTChatbot.263 <b>Click n Chat</b> Social Solution with AI-driven AI Chatbot. 264 264 </p> 265 265 </div> … … 535 535 <span class="pop_type_hover"> 536 536 <input type="radio" name="pop_type" value="chatgpt" <?php echo esc_html($click_n_chat_setting_popup->pop_type == "chatgpt" ? 'checked="checked"' : ''); ?> data-img="chatgpt"> 537 ChatGPT537 AI 538 538 </span> 539 539 … … 549 549 <input name="socialwidgets_no_availability" <?php echo esc_html($click_n_chat_setting_popup->socialwidgets_no_availability == "autoreply" ? 'checked="checked"' : ''); ?> type="radio" value="autoreply" /> Auto Reply 550 550 551 <input name="socialwidgets_no_availability" <?php echo esc_html($click_n_chat_setting_popup->socialwidgets_no_availability == "chatgpt" ? 'checked="checked"' : ''); ?> type="radio" value="chatgpt" /> ChatGPT551 <input name="socialwidgets_no_availability" <?php echo esc_html($click_n_chat_setting_popup->socialwidgets_no_availability == "chatgpt" ? 'checked="checked"' : ''); ?> type="radio" value="chatgpt" /> AI 552 552 553 553 </div> … … 567 567 <option <?php echo esc_html($click_n_chat_setting_popup->display_front_page == "0" ? 'selected' : ''); ?> value="0">None</option> 568 568 <option <?php echo esc_html($click_n_chat_setting_popup->display_front_page == "1" ? 'selected' : ''); ?> value="1">Auto Reply</option> 569 <option <?php echo esc_html($click_n_chat_setting_popup->display_front_page == "2" ? 'selected' : ''); ?> value="2"> ChatGPT</option>569 <option <?php echo esc_html($click_n_chat_setting_popup->display_front_page == "2" ? 'selected' : ''); ?> value="2">AI</option> 570 570 <option <?php echo esc_html($click_n_chat_setting_popup->display_front_page == "3" ? 'selected' : ''); ?> value="3">Social Icon</option> 571 571 <option <?php echo esc_html($click_n_chat_setting_popup->display_front_page == "4" ? 'selected' : ''); ?> value="4">Social Widgets</option> … … 578 578 <option <?php echo esc_html($click_n_chat_setting_popup->display_home == "0" ? 'selected' : ''); ?> value="0">None</option> 579 579 <option <?php echo esc_html($click_n_chat_setting_popup->display_home == "1" ? 'selected' : ''); ?> value="1">Auto Reply</option> 580 <option <?php echo esc_html($click_n_chat_setting_popup->display_home == "2" ? 'selected' : ''); ?> value="2"> ChatGPT</option>580 <option <?php echo esc_html($click_n_chat_setting_popup->display_home == "2" ? 'selected' : ''); ?> value="2">AI</option> 581 581 <option <?php echo esc_html($click_n_chat_setting_popup->display_home == "3" ? 'selected' : ''); ?> value="3">Social Icon</option> 582 582 <option <?php echo esc_html($click_n_chat_setting_popup->display_home == "4" ? 'selected' : ''); ?> value="4">Social Widgets</option> … … 588 588 <option <?php echo esc_html($click_n_chat_setting_popup->display_cart == "0" ? 'selected' : ''); ?> value="0">None</option> 589 589 <option <?php echo esc_html($click_n_chat_setting_popup->display_cart == "1" ? 'selected' : ''); ?> value="1">Auto Reply</option> 590 <option <?php echo esc_html($click_n_chat_setting_popup->display_cart == "2" ? 'selected' : ''); ?> value="2"> ChatGPT</option>590 <option <?php echo esc_html($click_n_chat_setting_popup->display_cart == "2" ? 'selected' : ''); ?> value="2">AI</option> 591 591 <option <?php echo esc_html($click_n_chat_setting_popup->display_cart == "3" ? 'selected' : ''); ?> value="3">Social Icon</option> 592 592 <option <?php echo esc_html($click_n_chat_setting_popup->display_cart == "4" ? 'selected' : ''); ?> value="4">Social Widgets</option> … … 598 598 <option <?php echo esc_html($click_n_chat_setting_popup->display_checkout == "0" ? 'selected' : ''); ?> value="0">None</option> 599 599 <option <?php echo esc_html($click_n_chat_setting_popup->display_checkout == "1" ? 'selected' : ''); ?> value="1">Auto Reply</option> 600 <option <?php echo esc_html($click_n_chat_setting_popup->display_checkout == "2" ? 'selected' : ''); ?> value="2"> ChatGPT</option>600 <option <?php echo esc_html($click_n_chat_setting_popup->display_checkout == "2" ? 'selected' : ''); ?> value="2">AI</option> 601 601 <option <?php echo esc_html($click_n_chat_setting_popup->display_checkout == "3" ? 'selected' : ''); ?> value="3">Social Icon</option> 602 602 <option <?php echo esc_html($click_n_chat_setting_popup->display_checkout == "4" ? 'selected' : ''); ?> value="4">Social Widgets</option> … … 608 608 <option <?php echo esc_html($click_n_chat_setting_popup->display_page == "0" ? 'selected' : ''); ?> value="0">None</option> 609 609 <option <?php echo esc_html($click_n_chat_setting_popup->display_page == "1" ? 'selected' : ''); ?> value="1">Auto Reply</option> 610 <option <?php echo esc_html($click_n_chat_setting_popup->display_page == "2" ? 'selected' : ''); ?> value="2"> ChatGPT</option>610 <option <?php echo esc_html($click_n_chat_setting_popup->display_page == "2" ? 'selected' : ''); ?> value="2">AI</option> 611 611 <option <?php echo esc_html($click_n_chat_setting_popup->display_page == "3" ? 'selected' : ''); ?> value="3">Social Icon</option> 612 612 <option <?php echo esc_html($click_n_chat_setting_popup->display_page == "4" ? 'selected' : ''); ?> value="4">Social Widgets</option> … … 618 618 <option <?php echo esc_html($click_n_chat_setting_popup->display_account_page == "0" ? 'selected' : ''); ?> value="0">None</option> 619 619 <option <?php echo esc_html($click_n_chat_setting_popup->display_account_page == "1" ? 'selected' : ''); ?> value="1">Auto Reply</option> 620 <option <?php echo esc_html($click_n_chat_setting_popup->display_account_page == "2" ? 'selected' : ''); ?> value="2"> ChatGPT</option>620 <option <?php echo esc_html($click_n_chat_setting_popup->display_account_page == "2" ? 'selected' : ''); ?> value="2">AI</option> 621 621 <option <?php echo esc_html($click_n_chat_setting_popup->display_account_page == "3" ? 'selected' : ''); ?> value="3">Social Icon</option> 622 622 <option <?php echo esc_html($click_n_chat_setting_popup->display_account_page == "4" ? 'selected' : ''); ?> value="4">Social Widgets</option> … … 628 628 <option <?php echo esc_html($click_n_chat_setting_popup->display_shop == "0" ? 'selected' : ''); ?> value="0">None</option> 629 629 <option <?php echo esc_html($click_n_chat_setting_popup->display_shop == "1" ? 'selected' : ''); ?> value="1">Auto Reply</option> 630 <option <?php echo esc_html($click_n_chat_setting_popup->display_shop == "2" ? 'selected' : ''); ?> value="2"> ChatGPT</option>630 <option <?php echo esc_html($click_n_chat_setting_popup->display_shop == "2" ? 'selected' : ''); ?> value="2">AI</option> 631 631 <option <?php echo esc_html($click_n_chat_setting_popup->display_shop == "3" ? 'selected' : ''); ?> value="3">Social Icon</option> 632 632 <option <?php echo esc_html($click_n_chat_setting_popup->display_shop == "4" ? 'selected' : ''); ?> value="4">Social Widgets</option> … … 638 638 <option <?php echo esc_html($click_n_chat_setting_popup->display_product == "0" ? 'selected' : ''); ?> value="0">None</option> 639 639 <option <?php echo esc_html($click_n_chat_setting_popup->display_product == "1" ? 'selected' : ''); ?> value="1">Auto Reply</option> 640 <option <?php echo esc_html($click_n_chat_setting_popup->display_product == "2" ? 'selected' : ''); ?> value="2"> ChatGPT</option>640 <option <?php echo esc_html($click_n_chat_setting_popup->display_product == "2" ? 'selected' : ''); ?> value="2">AI</option> 641 641 <option <?php echo esc_html($click_n_chat_setting_popup->display_product == "3" ? 'selected' : ''); ?> value="3">Social Icon</option> 642 642 <option <?php echo esc_html($click_n_chat_setting_popup->display_product == "4" ? 'selected' : ''); ?> value="4">Social Widgets</option> … … 660 660 </p> 661 661 <p> 662 <b> ChatGPT: </b> Onclick chat popup opens chat using <a href="?page=wa-clicknchat&tab=chatgpt">ChatGPT</a>662 <b>AI: </b> Onclick chat popup opens chat using <a href="?page=wa-clicknchat&tab=chatgpt">AI</a> 663 663 </p> 664 664 <p> -
click-n-chat/trunk/classes/click_n_chat_setting_chatgpt.php
r3267891 r3440069 1 1 <?php 2 if (!defined('ABSPATH')) { 3 exit; // Exit if accessed directly 4 } 2 if (!defined('ABSPATH')) exit; 5 3 6 4 if (!class_exists('click_n_chat_setting_chatgpt')) { 7 5 class click_n_chat_setting_chatgpt { 8 public $api_key = 'Flag92'; 6 7 /* Provider */ 8 public $ai_provider = 'openai'; 9 10 /* API Keys */ 11 public $openai_api_key = ''; 12 public $claude_api_key = ''; 13 public $huggingface_api_key = ''; 14 public $gemini_api_key = ''; 15 public $cohere_api_key = ''; 16 public $deepseek_api_key = ''; 17 18 /* Common */ 9 19 public $max_token = '500'; 10 20 public $temperature = '0.5'; … … 13 23 public $ai_models = 'gpt-3.5-turbo'; 14 24 public $include_auto_reply = '1'; 15 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.';25 public $ai_instructions = 'You are a helpful AI assistant.'; 16 26 } 17 27 } -
click-n-chat/trunk/click-n-chat.php
r3433801 r3440069 4 4 Plugin URI: http://www.flag92.com/ 5 5 Description: 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.96 Version: 1.1.0 7 7 Author: Flag92 8 8 Domain Path: /languages -
click-n-chat/trunk/includes/ajax/click_n_chat_ajax_get_ai_reply.php
r3267900 r3440069 36 36 if($reply_message == "") 37 37 { 38 $url = 'https://api.openai.com/v1/chat/completions'; 39 $htmlInstructions = '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.'; 40 41 $data = [ 42 'model' => $click_n_chat_setting_chatgpt->ai_models, 43 'messages' => [ 44 ['role' => 'system', 'content' => $click_n_chat_setting_chatgpt->ai_instructions.' '.$htmlInstructions], 45 ['role' => 'user', 'content' => $message] 46 ], 47 'max_tokens' => (float)$click_n_chat_setting_chatgpt->max_token, 48 'temperature' => (float)$click_n_chat_setting_chatgpt->temperature, 49 'presence_penalty' => (float)$click_n_chat_setting_chatgpt->presence_penalty, 50 'frequency_penalty' => (float)$click_n_chat_setting_chatgpt->frequency_penalty 51 ]; 52 53 $args = [ 54 'headers' => [ 55 'Authorization' => 'Bearer ' . $click_n_chat_setting_chatgpt->api_key, 56 'Content-Type' => 'application/json', 57 ], 58 'body' => wp_json_encode($data), // Ensure the data is in JSON format 59 'method' => 'POST', 60 'timeout' => 30, // Timeout in seconds 61 ]; 62 $response = wp_remote_post($url, $args); 63 64 if (is_wp_error($response)) { 65 $reply_message = 'Error: ' . $response->get_error_message(); 66 } 67 else 68 { 69 70 $response_body = wp_remote_retrieve_body($response); 71 $responseData = json_decode($response_body); 72 73 if(isset($responseData->choices[0]->message->content)) 74 $reply_message = $responseData->choices[0]->message->content; 75 else 76 $reply_message = $responseData->error->message; 77 78 } 38 $ai = new Click_N_Chat_AI_Provider($settings); 39 $reply_message = $ai->reply($message); 79 40 } 80 41 … … 117 78 118 79 return $results[0]; 119 } 80 } 120 81 121 82 add_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.