Changeset 3274880
- Timestamp:
- 04/16/2025 03:04:15 PM (12 months ago)
- Location:
- s2b-ai-assistant/trunk
- Files:
-
- 9 edited
-
lib/S2bAia.php (modified) (1 diff)
-
lib/controllers/AdminChatBotController.php (modified) (2 diffs)
-
lib/controllers/ChatBotController.php (modified) (7 diffs)
-
lib/helpers/WpHttpClient.php (modified) (1 diff)
-
readme.txt (modified) (3 diffs)
-
s2b-ai-assistant.php (modified) (1 diff)
-
views/backend/chatbot/chatbot_chatbots.php (modified) (1 diff)
-
views/backend/chatbot/chatbot_general.php (modified) (1 diff)
-
views/resources/js/s2baia-admin-v2.js (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
s2b-ai-assistant/trunk/lib/S2bAia.php
r3252391 r3274880 18 18 19 19 public function enqueueScripts() { 20 wp_enqueue_script('s2baia_backend', S2BAIA_URL . '/views/resources/js/s2baia-admin.js', [], '2.3 5', true);21 wp_enqueue_script('s2baia_backendv2', S2BAIA_URL . '/views/resources/js/s2baia-admin-v2.js', [], '2.3 5', true);20 wp_enqueue_script('s2baia_backend', S2BAIA_URL . '/views/resources/js/s2baia-admin.js', [], '2.37', true); 21 wp_enqueue_script('s2baia_backendv2', S2BAIA_URL . '/views/resources/js/s2baia-admin-v2.js', [], '2.37', true); 22 22 } 23 23 -
s2b-ai-assistant/trunk/lib/controllers/AdminChatBotController.php
r3252391 r3274880 316 316 } 317 317 318 if (isset($_POST[ 's2baia_chatbot_rag_keywords'])) {//-- 319 $data['rag_keywords'] = sanitize_text_field(wp_unslash($_POST[ 's2baia_chatbot_rag_keywords'])); 320 } 318 321 319 322 … … 337 340 if (isset($_POST[ 's2baia_rag_index'])) {//-- 338 341 $data['rag_index'] = sanitize_text_field(wp_unslash($_POST[ 's2baia_rag_index'])); 342 } 343 344 if (isset($_POST[ 's2baia_chatbot_rag_keywords'])) {//-- 345 $data['rag_keywords'] = sanitize_text_field(wp_unslash($_POST[ 's2baia_chatbot_rag_keywords'])); 339 346 } 340 347 -
s2b-ai-assistant/trunk/lib/controllers/ChatBotController.php
r3252391 r3274880 52 52 53 53 wp_enqueue_script( 's2baia', S2BAIA_URL . '/views/frontend/resources/js/chatbot.js', array( 'jquery' ), S2BAIA_VERSION, false ); 54 $new_script = apply_filters( 's2baia_chatbot_enqueue_script',['include' => false,'handle'=>'','src'=>'','deps'=>[],'ver'=>false,'args'=>[]] ); 55 if(is_array($new_script) && isset($new_script['include']) && $new_script['include']){ 56 wp_enqueue_script( $new_script['handle'], $new_script['src'], $new_script['deps'], $new_script['ver'], $new_script['args'] ); 57 } 54 58 } 55 59 … … 68 72 '1.0.2' 69 73 ); 74 $new_style = apply_filters( 's2baia_chatbot_enqueue_style',['include' => false,'handle'=>'','src'=>'','deps'=>[],'ver'=>false,'media'=>'all'] ); 75 if(is_array($new_style) && isset($new_style['include']) && $new_style['include']){ 76 wp_enqueue_style( 77 $new_style['handle'], 78 $new_style['src'], 79 $new_style['deps'], 80 $new_style['ver'], 81 $new_style['media'] 82 ); 83 } 70 84 } 71 85 … … 126 140 if(isset($chat_bot_styles->bot_options['rag_index'])){ 127 141 unset($chat_bot_styles->bot_options['rag_index']); 142 } 143 if(isset($chat_bot_styles->bot_options['rag_keywords'])){ 144 unset($chat_bot_styles->bot_options['rag_keywords']); 128 145 } 129 146 } … … 234 251 default: 235 252 236 $data_parameters['bot_view'] = 1; 237 //$content = $this->showClassicChatGPTDefaultHistory($data_par,$data_parameters); 238 253 //$data_parameters['bot_view'] = 1; 254 $content = apply_filters( 's2baia_chatbot_render_view', [$data_par,$data_parameters] ); 255 return $content; 256 257 239 258 } 240 259 if($view !== 'default'){ … … 632 651 $rag_provider = sanitize_text_field($params['s2baia_chatbot_opt_rag_index']); 633 652 $use_rag = true; 653 634 654 $search_content_success = false; 635 655 $s2baia_config_embedding_break_not_found = (int) get_option(S2BAIA_PREFIX_LOW . 'config_embedding_break_not_found', 0); … … 642 662 $config_pinecone_confidence = (int) (get_option(S2BAIA_PREFIX_LOW . 'config_pinecone_confidence', 50)); 643 663 $config_pinecone_namespace = sanitize_text_field(get_option(S2BAIA_PREFIX_LOW . 'config_pinecone_namespace', '')); 644 645 $embedded_res = S2bAia_RagUtils::makeEmbedingCall($new_message); 664 $emb_new_msg = $new_message; 665 $rag_keywords = sanitize_text_field($params['s2baia_chatbot_opt_rag_keywords']); 666 if(strlen($rag_keywords) > 0){ 667 $emb_new_msg = $new_message.' '.$rag_keywords; 668 } 669 $embedded_res = S2bAia_RagUtils::makeEmbedingCall($emb_new_msg); 646 670 if (isset($embedded_res['status']) && $embedded_res['status'] == 200) { 647 671 $embedded_question = $embedded_res['embedding']; … … 844 868 $config_pinecone_confidence = (int) (get_option(S2BAIA_PREFIX_LOW . 'config_pinecone_confidence', 50)); 845 869 $config_pinecone_namespace = sanitize_text_field(get_option(S2BAIA_PREFIX_LOW . 'config_pinecone_namespace', '')); 846 847 $embedded_res = S2bAia_RagUtils::makeEmbedingCall($new_message); 870 $emb_new_msg = $new_message; 871 $rag_keywords = sanitize_text_field($params['s2baia_chatbot_opt_rag_keywords']); 872 if(strlen($rag_keywords) > 0){ 873 $emb_new_msg = $new_message.' '.$rag_keywords; 874 } 875 $embedded_res = S2bAia_RagUtils::makeEmbedingCall($emb_new_msg); 848 876 if (isset($embedded_res['status']) && $embedded_res['status'] == 200) { 849 877 $embedded_question = $embedded_res['embedding']; -
s2b-ai-assistant/trunk/lib/helpers/WpHttpClient.php
r3252391 r3274880 23 23 24 24 public static function handleEvent($data) { 25 //$debugger = S2bAia_Utils::$global_logger;26 //$debug_log = (get_option( 's2baia_debug', 0 ) > 0) && is_object($debugger) && strlen(S2bAia_Utils::$log_id) > 0;25 $debugger = S2bAia_Utils::$global_logger; 26 $debug_log = (get_option( 's2baia_debug', 0 ) > 0) && is_object($debugger) && strlen(S2bAia_Utils::$log_id) > 0; 27 27 28 28 29 29 30 30 if (!empty($data)) { 31 $obj = json_decode($data, true); 32 33 if (!class_exists('S2bAia_FileExtender')) { 34 require_once S2BAIA_PATH . '/lib/classes/FileExtender.php'; 35 } 36 37 $fext = new S2bAia_FileExtender(); 38 39 // 🔹 Handle Regular Text Responses 40 if ($obj && isset($obj['delta']['content'])) { 41 foreach ($obj['delta']['content'] as $content) { 42 if ($content['type'] === 'text' && isset($content['text']['value'])) { 43 $text_value = $content['text']['value']; 44 $annotations = isset($content['text']['annotations']) ? $content['text']['annotations'] : []; 45 foreach ($annotations as $annotation) { 46 self::$annotations[] = $annotation; 47 } 48 // Process text with annotations (e.g., file citations) 49 $filtered_text = $text_value; //$fext->assistantapiFilterResponseStream($text_value, $annotations, $obj,self::$annotations); 50 self::$stream_answer .= $filtered_text; 51 } 52 } 53 } 54 // 🔹 2. Handle `tool_calls` from Final API Response 55 if ($obj && isset($obj['step_details']['tool_calls'])) { 56 $fl2 = __DIR__ . "/tool_calls" . rand(10000, 99999) . ".txt"; 57 $logvar = $obj; 58 //error_log(print_r($logvar, true), 3, $fl2); 59 if($debug_log){ 60 $ldata = []; 61 $ldata['id_user'] = get_current_user_id(); 62 $ldata['typeof_message'] = 1; 63 $ldata['id_actor'] = ''; 64 $ldata['messages'] = wp_json_encode($obj); 65 $ldata['sourcetable'] = 's2baia_messages_log'; 66 $ldata['ipaddress'] = sanitize_text_field(S2bAia_Utils::getIpAddress()); 67 $ldata['event_id'] = sanitize_text_field(S2bAia_Utils::$log_id); 68 $ldata['comments'] = sanitize_text_field('handleEvent debug $object'); 69 $debugger->insertDebugRecord($ldata); 70 } 71 foreach ($obj['step_details']['tool_calls'] as $tool_call) { 72 if ($tool_call['type'] === 'code_interpreter' && isset($tool_call['code_interpreter']['outputs'])) { 73 foreach ($tool_call['code_interpreter']['outputs'] as $output) { 74 if (isset($output['file_id'])) { 75 $file_id = $output['file_id']; 76 77 // 🔹 Handle the file link properly 78 $filtered_text = $fext->assistantapiFilterResponseStream("", [], ["file_id" => $file_id, "file_name" => basename($file_id)]); 79 self::$stream_answer .= $filtered_text; 80 } 81 } 82 } 83 84 if ($tool_call['type'] === 'code_interpreter' && isset($tool_call['code_interpreter']['input'])) { 85 $input_text = trim($tool_call['code_interpreter']['input']); 86 //self::$partial_file_path .= $input_text; 87 // 🔹 Check if the input contains a file path instead of Python code 88 $matches = []; 89 if (preg_match('/\/mnt\/data\/.*\.(docx|pdf|txt|csv)$/', self::$partial_file_path, $matches)) { 90 $file_id = $matches[0]; // Extract full file path 91 self::$partial_file_path = ''; // Reset buffer 92 // 🔹 Process only actual filenames (ignore Python code) 93 $filtered_text = $fext->assistantapiFilterResponseStream("", [], ["file_id" => $file_id, "file_name" => basename($file_id)]); 94 self::$stream_answer .= $filtered_text; 95 } else { 96 // 🔹 Ignore Python execution commands (they are not file paths) 97 self::$partial_file_path .= $input_text; 98 } 99 } 100 } 101 } 102 103 104 if ($obj && isset($obj['object']) && $obj['object'] == 'thread.message' && isset($obj['status']) && $obj['status'] == 'completed' && isset($obj['content'])) { 105 $fl2 = __DIR__ . "/response_assistant_message_completed" . rand(10000, 99999) . ".txt"; 106 $logvar = $obj; 107 //error_log(print_r($logvar, true), 3, $fl2); 108 if($debug_log){ 109 $ldata = []; 110 $ldata['id_user'] = get_current_user_id(); 111 $ldata['typeof_message'] = 1; 112 $ldata['id_actor'] = ''; 113 $ldata['messages'] = wp_json_encode($obj); 114 $ldata['sourcetable'] = 's2baia_messages_log'; 115 $ldata['ipaddress'] = sanitize_text_field(S2bAia_Utils::getIpAddress()); 116 $ldata['event_id'] = sanitize_text_field(S2bAia_Utils::$log_id); 117 $ldata['comments'] = sanitize_text_field('handleEvent debug $object'); 118 $debugger->insertDebugRecord($ldata); 119 } 120 $content = $obj['content']; 121 if (is_array($content) && count($content) > 0) { 122 123 $content = $content[0]; 124 if (isset($content['type']) && $content['type'] == 'text' && is_array($content['text'])) { 125 $text = $content['text']; 126 if (is_array($text) && isset($text['value']) && isset($text['annotations'])) { 127 $annotations = $text['annotations']; 128 foreach ($annotations as $annotation) { 129 self::$annotations[] = $annotation; 130 } 131 $text_value = $text['value']; 132 //$filtered_text = $fext->assistantapiFilterResponseStream($text_value, $annotations, $content,self::$annotations); 133 //self::$stream_answer .= $filtered_text; 134 self::$thread_message = $obj; 135 } 136 } 137 } 138 } 139 140 return $obj; 141 } 31 142 return $data; 32 143 } -
s2b-ai-assistant/trunk/readme.txt
r3252391 r3274880 4 4 Tags: chatbot, gpt, AI, content generator, openai 5 5 Requires at least: 5.6 6 Tested up to: 6. 76 Tested up to: 6.8 7 7 Requires PHP: 7.0 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html 10 Stable tag: 1.7. 010 Stable tag: 1.7.1 11 11 12 12 Create multiple AI chatbots with OpenAI and xAI models, with different styles and behavior, content aware features ... … … 39 39 * Summarizing 40 40 * Finish the sentence 41 * Improve your writing skills42 * Engaging questions43 41 * Answering All Inquiries 44 42 * Create product descriptions 45 * Intent Recognition46 43 * Code Understanding 47 44 * Select any model you want from ChatGpt 48 45 * Create a blog intro for your next article 49 * Create blog outlines50 * Change the tone of your sentences51 46 * Create brand names, startup ideas and slogans 52 47 * Generate a list of marketing ideas … … 271 266 == Changelog == 272 267 268 = 1.7.1 = 269 * Refining queries by adding keywords to each search request that is sent to the semantic database 270 * Adding native way of communication between Chatbot and Assistant API. 271 273 272 = 1.7.0 = 274 273 * Add xAI Grok model support for chatbot -
s2b-ai-assistant/trunk/s2b-ai-assistant.php
r3252391 r3274880 8 8 Text Domain: s2b-ai-assistant 9 9 Domain Path: /lang 10 Version: 1.7. 010 Version: 1.7.1 11 11 License: GPL-2.0+ 12 12 License URI: http://www.gnu.org/licenses/gpl-2.0.txt -
s2b-ai-assistant/trunk/views/backend/chatbot/chatbot_chatbots.php
r3252391 r3274880 897 897 <p class="s2baia_input_description"> 898 898 <span style="display: inline;"><?php esc_html_e('Select embedding index', 's2b-ai-assistant'); ?></span> 899 </p> 900 </div> 901 </div> 902 903 <div class="s2baia_block_content"> 904 <div class="s2baia_row_header"> 905 <label for="s2baia_rag_keywords" font-weight: 700;"><?php esc_html_e('Additional Keywords', 's2b-ai-assistant'); ?> *:</label> 906 </div> 907 <div class="s2baia_row_content s2baia_pr"> 908 <div style="position: relative;"> 909 <?php $rag_keywords = isset($chat_bot_options['rag_keywords']) ? $chat_bot_options['rag_keywords'] : ''; ?> 910 <input type="text" id="s2baia_chatbot_rag_keywords" 911 name="s2baia_chatbot_rag_keywords" 912 value="<?php echo esc_html($rag_keywords); ?>" /> 913 </div> 914 <p class="s2baia_input_description"> 915 <span style="display: inline;"> 916 <?php esc_html_e('Additional keywords will be added to each user requests which are sent to semantic database. This is useful when for example user enters question: Which attributes of order item? But when you add Woocommerce as Additional keyword then next text will be sent to semantic database: "Which attributes of order item? Woocommerce". So additional keywords improve context. Note that additional keywords are not sent to chat bot provider. They are only sent to semantic search database. ', 's2b-ai-assistant'); ?> 917 </span> 899 918 </p> 900 919 </div> -
s2b-ai-assistant/trunk/views/backend/chatbot/chatbot_general.php
r3252391 r3274880 674 674 </div> 675 675 <?php 676 if( false){676 if(true){ 677 677 ?> 678 678 <div class="s2baia_block_header"> -
s2b-ai-assistant/trunk/views/resources/js/s2baia-admin-v2.js
r3252391 r3274880 508 508 document.querySelector('#s2baia_rag_index'+itmsuffix).value = bot_options['rag_index']; 509 509 510 let s2brag_keywords = document.querySelector('#s2baia_chatbot_rag_keywords'+itmsuffix); 511 if(s2brag_keywords){ 512 if(bot_options['rag_keywords']){ 513 document.querySelector('#s2baia_chatbot_rag_keywords'+itmsuffix).value = bot_options['rag_keywords']; 514 }else{ 515 document.querySelector('#s2baia_chatbot_rag_keywords'+itmsuffix).value = ''; 516 } 517 } 510 518 511 519 let buttons = {'s2baia_submit_edit_instruction': [1, 1, 'Save'], 's2baia_saveasnew_instruction': [1, 1, ''],
Note: See TracChangeset
for help on using the changeset viewer.