PluginProbe
WPBot – AI ChatBot for Live Support, Lead Generation, WordPress Automation, AI Services / 7.9.6
WPBot – AI ChatBot for Live Support, Lead Generation, WordPress Automation, AI Services v7.9.6
8.8.2 8.8.1 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 All 538 releases
chatbot / includes / integration / gemini / assets / js / qcld-wp-gemini-admin.js

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

125 lines 5.9 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 Google API
3 $(document).on('click', '#qcld_gemini_fetch_models', function(e) {
4 e.preventDefault();
5 var api_key = $('#qcld_gemini_api_key').val();
6 if (!api_key) {
7 Swal.fire({
8 icon: 'error',
9 title: 'Oops...',
10 text: 'Please enter your API Key first!'
11 });
12 return;
13 }
14
15 var $btn = $(this);
16 var originalText = $btn.text();
17 $btn.text('Fetching...').prop('disabled', true);
18
19 $.ajax({
20 url: qcld_gemini_admin_data.ajax_url,
21 type: 'POST',
22 data: {
23 action: 'qcld_gemini_get_model_list',
24 nonce: qcld_gemini_admin_data.ajax_nonce,
25 api_key: api_key
26 },
27 success: function(response) {
28 if (response.success) {
29 var $select = $('#qcld_gemini_model');
30 var currentModel = $select.val();
31 $select.empty();
32 response.data.models.forEach(function(model) {
33 var selected = (model.id === currentModel) ? 'selected' : '';
34 $select.append('<option value="' + model.id + '" ' + selected + '>' + model.name + ' (' + model.id + ')</option>');
35 });
36 Swal.fire({
37 icon: 'success',
38 title: 'Success',
39 text: 'Models fetched successfully!'
40 });
41 } else {
42 Swal.fire({
43 icon: 'error',
44 title: 'Error',
45 text: response.data.msg || 'Failed to fetch models'
46 });
47 }
48 },
49 error: function() {
50 Swal.fire({
51 icon: 'error',
52 title: 'Error',
53 text: 'An error occurred while fetching models.'
54 });
55 },
56 complete: function() {
57 $btn.text(originalText).prop('disabled', false);
58 }
59 });
60 });
61
62 // Function to fetch models from OpenRouter API
63
64 var settingsGemini = document.getElementById("qcld_save_gemini_setting");
65 if(settingsGemini){
66 $('.qcl-openai').on('click', '#qcld_save_gemini_setting', function(){
67 if ($('#qcld_gemini_enabled').is(":checked")){
68 var gemini_enabled = 1;
69 }else{
70 var gemini_enabled = 0;
71 }
72 var qcld_gemini_page_suggestion_enabled = jQuery("#qcld_gemini_page_suggestion_enabled").is(":checked") ? 1 : 0;
73 var gemini_is_context_awareness_enabled = jQuery("#gemini_is_context_awareness_enabled").is(":checked") ? 1 : 0;
74 var qcld_gemini_api_key = jQuery("#qcld_gemini_api_key").val();
75 var qcld_gemini_model = jQuery('#qcld_gemini_model').val();
76 var qcld_gemini_append_content = jQuery('#qcld_gemini_append_content').val();
77 var qcld_gemini_prepend_content = jQuery('#qcld_gemini_prepend_content').val();
78 var is_page_rag_enabled = jQuery("#is_page_rag_enabled_gemini").is(":checked") ? 1 : 0;
79 var post_gemini_types = $.map($('input[name="site_gemini_search_posttypes[]"]:checked'), function(c){return c.value; });
80 $.ajax({
81 url: qcld_gemini_admin_data.ajax_url,
82 type:'POST',
83 data: {
84 action: 'qcld_gemini_settings_option',
85 nonce: qcld_gemini_admin_data.ajax_nonce,
86 gemini_api_key: qcld_gemini_api_key,
87 gemini_model: qcld_gemini_model,
88 gemini_enabled: gemini_enabled,
89 qcld_gemini_page_suggestion_enabled: qcld_gemini_page_suggestion_enabled,
90 gemini_is_context_awareness_enabled: gemini_is_context_awareness_enabled,
91 qcld_gemini_append_content: qcld_gemini_append_content,
92 qcld_gemini_prepend_content: qcld_gemini_prepend_content,
93 openai_post_type:post_gemini_types,
94 is_page_rag_enabled: is_page_rag_enabled
95 },
96 success: function(data){
97 $('#result').html(data);
98 var color = data.status === 'success' ? 'color:green;' : 'color:red;';
99 Swal.fire({
100 title: 'Your settings are saved.',
101 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></b><p><span style="'+ color +'">'+ data.msg+'</span></p>',
102 width: 450,
103 icon: 'success',
104 confirmButtonText: 'Got it',
105 confirmButtonWidth: 100,
106 confirmButtonClass: 'btn btn-lg',
107 }).then((result) => {
108 if (result.isConfirmed) {
109 $.ajax({
110 url: qcld_gemini_admin_data.ajax_url,
111 type: 'POST',
112 data: {
113 action: 'update_settings_option',
114 nonce: qcld_gemini_admin_data.ajax_nonce,
115 disable_ss: 1
116 },
117
118 });
119 }
120 });
121 }
122 });
123 });
124 }
125 });