PluginProbe
WPBot – AI ChatBot for Live Support, Lead Generation, WordPress Automation, AI Services / 8.5.4
WPBot – AI ChatBot for Live Support, Lead Generation, WordPress Automation, AI Services v8.5.4
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 8.5.4 8.5.3 8.5.2 8.5.0 All 532 releases
chatbot / js / openai_settings1.js

openai_settings1.js in WPBot – AI ChatBot for Live Support, Lead Generation, WordPress Automation, AI Services 8.5.4, at js/openai_settings1.js

185 lines 8.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function($) {
2
3 $(document).ready(function () {
4 var flieElementOpenAi = document.getElementById("openfileinput");
5
6 if(flieElementOpenAi){
7 $('.error-message').hide();
8 $('.success-message').hide();
9 $(".file_form").on('change','#openfileinput',function(){
10 var file_data = $('#openfileinput').prop('files')[0];
11 var form_data = new FormData();
12 form_data.append('file', file_data);
13 form_data.append('action', 'openai_file_upload');
14 form_data.append('purpose','answers');
15 $('.success-message').html('File is Proccesing');
16 $('.success-message').show();
17 $.ajax({
18 url: openai_ajax.url,
19 type: 'post',
20 contentType: false,
21 processData: false,
22 data: form_data,
23 success: function (response) {
24 console.log(response[0].status)
25 if(response[0].status == "success"){
26 // $('.success').html(response.message)
27 $('.success-message').hide();
28 $('.success-message').html(response[0].message);
29 $('.success-message').show();
30 setTimeout(function(){
31 $('.success-message').hide();
32 },5000);
33 location.reload();
34 }
35 if(response[0].status === "error"){
36 console.log(response[0].status)
37 //$('.success-message').html(response.message)
38 jQuery('.success-message').hide();
39 jQuery('.error-message').show();
40 jQuery('.error-message').html(response[0].message);
41 setTimeout(function(){
42 jQuery('.error-message').hide();
43 },5000);
44 location.reload();
45 }
46 },
47 });
48
49 });
50
51 $("#openaiFileList").on('click','.remove_file_openai',function(){
52 $(this).hide();
53 var file_id = $('.remove_file_openai').attr('data-id');
54 jQuery('.error-message').show();
55 jQuery('.error-message').html(file_id+'is deleting');
56 setTimeout(function(){
57 jQuery('.error-message').hide();
58 },5000);
59 $.ajax({
60 url: openai_ajax.url,
61 type: 'POST',
62 dataType: "JSON",
63 data: {
64 action : 'openai_file_delete',
65 file_id: file_id
66 },
67 success: function (response) {
68 location.reload();
69 },
70 });
71
72 });
73 $.ajax({
74 url: openai_ajax.url,
75 type: "POST",
76 dataType: "JSON",
77 data: {
78 action : 'openai_file_list',
79 },
80 success: function(res) {
81 if((res.data != undefined)){
82 data = res.data;
83 let text = "";
84 data.forEach(itemfunction);
85 function itemfunction(item) {
86 text += '<tr><td>'+item.filename +'</td><td>' +item.id+'</td><td><a class="btn-success btn floated create_ft_model_modal" data-id="'+item.id+'">Create FT Model</a> <a class="btn-danger btn floated remove_file_openai" data-id="'+item.id+'">Remove</a></td></tr>';
87 }
88 document.getElementById("openaiFileList").innerHTML = text;
89 }
90 }
91 });
92 }
93
94
95
96 // $('').on('click', '#save_setting', function(){
97
98
99 // })
100 var file_save = document.getElementById("save_file_id");
101 if(file_save){
102 $('.qcl-openai').on('click', '#save_file_id', function(){
103 var file_id = $("input[name='file_id']" ).val();
104 $.ajax({
105 url: openai_ajax.url,
106 type:'POST',
107 data: ({action : 'openai_settings_option',file_id:file_id}),
108 success: function(data){
109 $('#result').html(data);
110 // location.reload();
111 }
112 });
113 })
114 }
115 var settingsOpenAi = document.getElementById("save_setting");
116 if(settingsOpenAi){
117
118 $('.qcl-openai').on('change','#qcld_openai_prompt', function() {
119
120 if( ($("[id*='qcld_openai_prompt'] :selected").val()) == 'custom_prompt'){
121 console.log(this.value)
122 $('#custom_prompt_wrapper').html('<input type="field" id="qcld_openai_prompt_custom" class="form-control my-2" placeholder="Add custom prompt here. Custom prompt will be appended before the user`s queries"/>');
123 }else{
124 $('#custom_prompt_wrapper').empty('')
125 }
126 })
127 setTimeout(() => {
128 var custom_promt_value =$("#custom_promt_value").val();
129 if( $("[id*='qcld_openai_prompt'] :selected").val() == 'custom_prompt' ){
130
131 // $("#custom_promt_value").filter('[value=any_command]').prop('selected', true);
132 $('select option[value="custom_prompt"]').attr('selected', 'selected');
133 // $('select option[value="any_command"]').attr('selected', 'selected');
134
135 $('#custom_prompt_wrapper').html('<input type="field" id="qcld_openai_prompt_custom" class="form-control my-2" />');
136 $('#qcld_openai_prompt_custom').val(custom_promt_value)
137
138 }
139 }, 500);
140 $('.qcl-openai').on('click', '#save_setting', function(){
141 console.log('ss')
142 if ($('#is_ai_enabled').is(":checked")){
143 var is_ai_enabled = 1;
144 }else{
145 var is_ai_enabled = 0;
146 }
147 if($('#is_ai_only_mode').is(":checked")){
148 var is_ai_only_mode = 1;
149 }else{
150 var is_ai_only_mode = 0;
151 }
152 if($('#is_relevant_enabled').is(":checked")){
153 var is_relevant_enabled = 1;
154 }else{
155 var is_relevant_enabled = 0;
156 }
157 var api_key = $( "input[name='api_key']" ).val();
158 var openai_engines = $("[id*='openai_engines'] :selected").val();
159 var qcld_openai_prompt = $("[id*='qcld_openai_prompt'] :selected").val();
160 var max_tokens = $("input[name='max_tokens']" ).val();
161 var file_id = $("input[name='file_id']" ).val();
162 var temperature = $("input[name='temperature']" ).val();
163 var presence_penalty = $("input[name='presence_penalty']" ).val();
164 if(qcld_openai_prompt == "custom_prompt"){
165 var qcld_openai_prompt_custom = $("#qcld_openai_prompt_custom").val();
166 console.log(qcld_openai_prompt)
167 }
168 var frequency_penalty = $("input[name='frequency_penalty']" ).val();
169 $.ajax({
170 url: openai_ajax.url,
171 type:'POST',
172 data: ({action : 'openai_settings_option',nonce: qcld_gemini_admin_data.ajax_nonce,api_key: api_key,openai_engines:openai_engines,qcld_openai_prompt: qcld_openai_prompt,max_tokens:max_tokens,file_id:file_id,temperature:temperature,presence_penalty:presence_penalty,frequency_penalty:frequency_penalty,qcld_openai_prompt_custom: qcld_openai_prompt_custom,openai_exclude_keyword:openai_exclude_keyword,is_relevant_enabled:is_relevant_enabled,openai_include_keyword:openai_include_keyword,ai_enabled:is_ai_enabled,ai_only_mode: is_ai_only_mode,conversation_continuity:conversation_continuity, disable_ss: 1}),
173 success: function(data){
174 $('#result').html(data);
175 // location.reload();
176 }
177 });
178
179 })
180 }
181
182 });
183
184
185 })(jQuery);