PluginProbe
WPBot – AI ChatBot for Live Support, Lead Generation, WordPress Automation, AI Services / 8.2.3
WPBot – AI ChatBot for Live Support, Lead Generation, WordPress Automation, AI Services v8.2.3
8.8.0 8.7.9 8.7.8 8.7.7 8.7.6 8.7.5 8.7.4 8.7.3 8.7.2 8.7.1 8.7.0 8.6.9 8.6.8 8.6.7 8.6.6 8.6.5 8.6.4 8.6.2 8.6.1 8.6.0 8.5.9 8.5.8 8.5.7 8.5.6 8.5.5 All 536 releases
chatbot / includes / integration / grok / js / qcld-wp-grok-admin.js

qcld-wp-grok-admin.js in WPBot – AI ChatBot for Live Support, Lead Generation, WordPress Automation, AI Services 8.2.3, at includes/integration/grok/js/qcld-wp-grok-admin.js

160 lines 8.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 jQuery(document).ready(function($) {
2 // Function to fetch models from OpenRouter API
3 var settingsOpenrouter = document.getElementById("qcld_save_grok_setting");
4 if(settingsOpenrouter){
5 $('.qcl-openai').on('click', '#qcld_save_grok_setting', function(event){
6 event.preventDefault();
7 if ($('#qcld_grok_enabled').is(":checked")){
8 var grok_enabled = 1;
9 }else{
10 var grok_enabled = 0;
11 }
12 if ($('#qcld_grok_rag_enabled').is(":checked")){
13 var grok_rag_enabled = 1;
14 }else{
15 var grok_rag_enabled = 0;
16 }
17 var qcld_grok_page_suggestion_enabled = jQuery("#qcld_grok_page_suggestion_enabled").is(":checked") ? 1 : 0;
18 var qcld_grok_api_key = jQuery("#qcld_grok_api_key").val();
19 var qcld_grok_model = jQuery('#qcld_grok_model').val();
20 var post_grok_types = $.map($('input[name="site_grok_search_posttypes[]"]:checked'), function(c){return c.value; });
21 $.ajax({
22 url: ajax_object.ajax_url,
23 type:'POST',
24 data: {
25 action: 'qcld_grok_settings_option',
26 nonce: ajax_object.ajax_nonce,
27 grok_api_key: qcld_grok_api_key,
28 grok_management_api_key: jQuery("#qcld_grok_management_api_key").val(),
29 grok_model: qcld_grok_model,
30 grok_enabled: grok_enabled,
31 grok_collection_id: jQuery("#qcld_grok_collection_id").val(),
32 grok_stream_enabled: jQuery("#qcld_grok_stream_enabled").is(":checked") ? 1 : 0,
33 grok_rag_enabled: grok_rag_enabled,
34 qcld_grok_system_content: jQuery("#qcld_grok_system_content").val(),
35 qcld_grok_page_suggestion_enabled: qcld_grok_page_suggestion_enabled,
36 openai_post_type:post_grok_types
37 },
38 success: function(data){
39 $('#result').html(data);
40 Swal.fire({
41 title: 'Your settings are saved.',
42 html: '<p style=font-size:14px>Please clear your browser <b>cache</b> and <b>cookies</b> both and reload the front end before testing. Alternatively, you can launch a new browser window in <b>Incognito</b>/Private mode (Ctrl+Shift+N in chrome) to test.</p>',
43 width: 450,
44 icon: 'success',
45 confirmButtonText: 'Yes',
46 confirmButtonWidth: 100,
47 confirmButtonClass: 'btn btn-lg'
48 }).then((result) => {
49 if (result.isConfirmed) {
50 $.ajax({
51 url: ajax_object.ajax_url,
52 type: 'POST',
53 data: {
54 action: 'update_settings_option',
55 nonce: ajax_object.ajax_nonce,
56 disable_ss: 1
57 },
58
59 });
60 }
61 });
62 }
63 });
64 });
65 $('.qcl-openai').on('click', '#add_grok_collection', function(event) {
66 event.preventDefault();
67 event.stopImmediatePropagation();
68 event.stopPropagation();
69 $.ajax({
70 url: ajax_object.ajax_url,
71 type:'POST',
72 data: {
73 action: 'qcld_grok_add_collection',
74 nonce: ajax_object.ajax_nonce,
75 },
76 success: function(response){
77 alert('New collection added successfully.');
78 loadGrokCollections();
79 }
80 });
81 });
82 $('.qcl-openai').on('click', '.remove_grok_collection', function( event ) {
83 event.preventDefault();
84 event.stopImmediatePropagation();
85 event.stopPropagation();
86 var collection_id = $(this).data('id');
87 if (confirm('Are you sure you want to remove this collection?')) {
88 $.ajax({
89 url: ajax_object.ajax_url,
90 type:'POST',
91 data: {
92 action: 'qcld_grok_remove_collection',
93 nonce: ajax_object.ajax_nonce,
94 collection_id: collection_id
95 },
96 success: function( response ){
97 console.log( JSON.parse( response ).response );
98 loadGrokCollections();
99 }
100 });
101 }
102 });
103 $.ajax({
104 url: ajax_object.ajax_url,
105 type:'POST',
106 data: {
107 action: 'qcld_grok_collectionlist',
108 nonce: ajax_object.ajax_nonce,
109 },
110 success: function(response){
111 var data = JSON.parse(response).collections;
112 var text = "";
113 data.forEach(function (item) {
114 text += '<tr><td>' + item.collection_name + '</td><td>' + item.collection_id + '<form class="file_form_gpt" data-collection="' + item.collection_id + '"><input type="file" class="inputfile" id="grokfileinput_gpt" /><label for="grokfileinput_gpt" class="huge ui grey button"><i class="fa fa-upload"></i>Upload CSV/PDF/JSON</label></form></td><td><a class="btn-danger btn floated remove_grok_collection" data-id="' + item.collection_id + '">Remove</a></td></tr>';
115 });
116 document.getElementById("grokFileList").innerHTML = text;
117 }
118 });
119 jQuery('.table-responsive').on('change','#grokfileinput_gpt', function() {
120 var file_data = $(this).prop('files')[0];
121 if (!file_data) return; // Exit if no file was selected
122
123 var form_data = new FormData();
124 form_data.append('file', file_data);
125 form_data.append('name', file_data.name);
126 form_data.append('collection_id', $(this).parent().attr('data-collection'));
127 form_data.append('action', 'qcld_grok_file_upload');
128 form_data.append('purpose', 'assistant');
129 form_data.append('nonce', ajax_object.ajax_nonce);
130 $.ajax({
131 url: ajax_object.ajax_url,
132 type: 'POST',
133 data: form_data,
134 processData: false, // Critical
135 contentType: false, // Critical
136 success: function(response) {
137 console.log('Upload successful', response);
138 }
139 });
140 })
141 function loadGrokCollections() {
142 $.ajax({
143 url: ajax_object.ajax_url,
144 type:'POST',
145 data: {
146 action: 'qcld_grok_collectionlist',
147 nonce: ajax_object.ajax_nonce,
148 },
149 success: function(response){
150 var data = JSON.parse(response).collections;
151 var text = "";
152 data.forEach(function (item) {
153 text += '<tr><td>' + item.collection_name + '</td><td>' + item.collection_id + '<form class="file_grok_form" data-collection="'+ item.collection_id + '"><input type="file" (change)="fileEvent($event)" class="inputfile" id="grokfileinput" style="display:none"/></form><form class="file_form_gpt" data-collection="' + item.collection_id + '"><input type="file" (change)="fileEvent($event)" class="inputfile" id="grokfileinput_gpt" style="display:none"/><label for="grokfileinput_gpt" class="huge ui grey button"><i class="fa fa-upload"></i>Upload CSV/PDF/JSON</label></form></td><td><a class="btn-danger btn floated remove_grok_collection" data-id="' + item.collection_id + '">Remove</a></td></tr>';
154 });
155 document.getElementById("grokFileList").innerHTML = text;
156 }
157 });
158 }
159 }
160 });