Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/aimogen-pro/scripts/training.js
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
"use strict";
2
+
var moder_gpt_models_aiomatic = aiomatic_object.moder_gpt_models;
3
+
function aiomatic_training_data_changed()
4
+
{
5
+
var select = jQuery('#model_selector_data_training').val();
6
+
if(moder_gpt_models_aiomatic.includes(select))
7
+
{
8
+
var aiomatic_legacy_data = jQuery('#aiomatic_legacy_data');
9
+
var aiomatic_gpt_data = jQuery('#aiomatic_gpt_data');
10
+
aiomatic_legacy_data.hide();
11
+
aiomatic_gpt_data.show();
12
+
}
13
+
else
14
+
{
15
+
var aiomatic_legacy_data = jQuery('#aiomatic_legacy_data');
16
+
var aiomatic_gpt_data = jQuery('#aiomatic_gpt_data');
17
+
aiomatic_legacy_data.show();
18
+
aiomatic_gpt_data.hide();
19
+
}
20
+
}
21
+
jQuery(document).ready(function ($){
22
+
function aiomatic_stripslashes (str)
23
+
{
24
+
return (str + '').replace(/\\(.?)/g, function (s, n1) {
25
+
switch (n1) {
26
+
case '\\':
27
+
return '\\';
28
+
case '0':
29
+
return '\u0000';
30
+
case '':
31
+
return '';
32
+
default:
33
+
return n1;
34
+
}
35
+
});
36
+
}
37
+
$('.aiomatic_modal_close').on('click', function (){
38
+
$('.aiomatic_modal_close').closest('.aiomatic_modal').hide();
39
+
$('.aiomatic_modal_close').closest('.aiomatic_modal').removeClass('aiomatic-small-modal');
40
+
$('.aiomatic-overlay').hide();
41
+
});
42
+
function aiomaticLoading(btn){
43
+
btn.attr('disabled','disabled');
44
+
if(!btn.find('spinner').length){
45
+
btn.append('<span class="spinner"></span>');
46
+
}
47
+
btn.find('.spinner').css('visibility','unset');
48
+
}
49
+
function aiomaticRmLoading(btn){
50
+
btn.removeAttr('disabled');
51
+
btn.find('.spinner').remove();
52
+
}
53
+
var aiomatic_max_file_size = aiomatic_object.maxfilesize;
54
+
var aiomatic_max_size_in_mb = aiomatic_object.maxfilesize / (1024 ** 2);
55
+
var aiomatic_file_button = $('#aiomatic_file_button');
56
+
var aiomatic_file_upload = $('#aiomatic_file_upload');
57
+
var aiomatic_file_purpose = $('#aiomatic_file_purpose');
58
+
var aiomatic_file_name = $('#aiomatic_file_name');
59
+
var aiomatic_file_model = $('#aiomatic_file_model');
60
+
var aiomatic_progress = $('.aiomatic_progress');
61
+
var aiomatic_error_message = $('.aiomatic-error-msg');
62
+
var aiomatic_create_fine_tune = $('.aiomatic_create_fine_tune');
63
+
var aiomatic_retrieve_content = $('.aiomatic_retrieve_content');
64
+
var aiomatic_delete_file = $('.aiomatic_delete_file');
65
+
var aiomatic_ajax_url = aiomatic_object.ajax_url;
66
+
var aiomatic_upload_success = $('.aiomatic_upload_success');
67
+
aiomatic_file_button.on('click', function (){
68
+
if(aiomatic_file_upload[0].files.length === 0){
69
+
alert('Please select a file!');
70
+
}
71
+
else{
72
+
var aiomatic_file = aiomatic_file_upload[0].files[0];
73
+
var aiomatic_file_extension = aiomatic_file.name.substr( (aiomatic_file.name.lastIndexOf('.') +1) );
74
+
if(aiomatic_file_extension !== 'jsonl'){
75
+
aiomatic_file_upload.val('');
76
+
alert('This feature only accepts JSONL file type!');
77
+
}
78
+
else if(aiomatic_file.size > aiomatic_max_file_size){
79
+
aiomatic_file_upload.val('');
80
+
alert('Dataset allowed maximum size (MB): '+ aiomatic_max_size_in_mb)
81
+
}
82
+
else{
83
+
var formData = new FormData();
84
+
formData.append('action', 'aiomatic_finetune_upload');
85
+
formData.append('file', aiomatic_file);
86
+
formData.append('purpose', aiomatic_file_purpose.val());
87
+
formData.append('model', aiomatic_file_model.val());
88
+
formData.append('name', aiomatic_file_name.val());
89
+
formData.append('nonce', aiomatic_object.nonce);
90
+
$.ajax({
91
+
url: aiomatic_ajax_url,
92
+
type: 'POST',
93
+
dataType: 'JSON',
94
+
data: formData,
95
+
beforeSend: function (){
96
+
aiomatic_progress.find('span').css('width','0');
97
+
aiomatic_progress.show();
98
+
aiomaticLoading(aiomatic_file_button);
99
+
aiomatic_error_message.hide();
100
+
aiomatic_upload_success.hide();
101
+
},
102
+
xhr: function() {
103
+
var xhr = $.ajaxSettings.xhr();
104
+
xhr.upload.addEventListener("progress", function(evt) {
105
+
if (evt.lengthComputable) {
106
+
var percentComplete = evt.loaded / evt.total;
107
+
aiomatic_progress.find('span').css('width',(Math.round(percentComplete * 100))+'%');
108
+
}
109
+
}, false);
110
+
return xhr;
111
+
},
112
+
success: function(res) {
113
+
if(res.status === 'success'){
114
+
aiomaticRmLoading(aiomatic_file_button);
115
+
aiomatic_progress.hide();
116
+
aiomatic_file_upload.val('');
117
+
aiomatic_upload_success.show();
118
+
}
119
+
else{
120
+
aiomaticRmLoading(aiomatic_file_button);
121
+
aiomatic_progress.find('small').html('Error');
122
+
aiomatic_progress.addClass('aiomatic_error');
123
+
aiomatic_error_message.html(res.msg);
124
+
aiomatic_error_message.show();
125
+
}
126
+
},
127
+
cache: false,
128
+
contentType: false,
129
+
processData: false,
130
+
error: function (r, s, error){
131
+
aiomatic_file_upload.val('');
132
+
aiomaticRmLoading(aiomatic_file_button);
133
+
aiomatic_progress.addClass('aiomatic_error');
134
+
aiomatic_progress.find('small').html('Error');
135
+
alert('Error in processing finetune uploading: ' + error);
136
+
aiomatic_error_message.show();
137
+
}
138
+
});
139
+
}
140
+
}
141
+
});
142
+
function aiomaticSortData(){
143
+
$('.aiomatic_data').each(function (idx, item){
144
+
$(item).find('.aiomatic_data_prompt').attr('name','data['+idx+'][prompt]');
145
+
$(item).find('.aiomatic_data_completion').attr('name','data['+idx+'][completion]');
146
+
});
147
+
$('.aiomatic_new_data').each(function (idx, item){
148
+
$(item).find('.aiomatic_new_data_system').attr('name','new_data['+idx+'][system]');
149
+
$(item).find('.aiomatic_new_data_prompt').attr('name','new_data['+idx+'][prompt]');
150
+
$(item).find('.aiomatic_new_data_completion').attr('name','new_data['+idx+'][completion]');
151
+
});
152
+
}
153
+
var aiomatic_item = '<div class="aiomatic_data_item aiomatic_data"><div><textarea rows="1" name="data[0][prompt]" class="regular-text aiomatic_data_prompt aiomatic_height" placeholder="Prompt"></textarea> </div><div><textarea rows="1" name="data[0][completion]" class="regular-text aiomatic_data_completion aiomatic_height" placeholder="Completion"></textarea><span class="button button-link-delete">×</span></div></div>';
154
+
var aiomatic_new_item = '<div class="aiomatic_new_data_item aiomatic_new_data"><div><textarea rows="1" name="new_data[0][system]" class="regular-text aiomatic_new_data_system aiomatic_height" placeholder="System"></textarea> </div><div><textarea rows="1" name="new_data[0][prompt]" class="regular-text aiomatic_new_data_prompt aiomatic_height" placeholder="User"></textarea> </div><div><textarea rows="1" name="new_data[0][completion]" class="regular-text aiomatic_new_data_completion aiomatic_height" placeholder="Assistant"></textarea><span class="button button-link-delete">×</span></div></div>';
155
+
var aiomatic_data_restore = window.localStorage.getItem('aiomatic_data_list');
156
+
if(aiomatic_data_restore !== null && aiomatic_data_restore !== "")
157
+
{
158
+
var appendData = '';
159
+
var oldobj = '';
160
+
try{
161
+
oldobj = JSON.parse(aiomatic_data_restore);
162
+
oldobj.forEach(function (element){if(element.prompt !== null && element.completion !== null && element.prompt !== undefined && element.completion !== undefined){appendData += '<div class="aiomatic_data_item aiomatic_data"><div><textarea rows="1" name="data[0][prompt]" class="regular-text aiomatic_data_prompt aiomatic_height" placeholder="Prompt">' + element.prompt + '</textarea> </div><div><textarea rows="1" name="data[0][completion]" class="regular-text aiomatic_data_completion aiomatic_height" placeholder="Completion">' + element.completion + '</textarea><span class="button button-link-delete">×</span></div></div>';}});
163
+
appendData += aiomatic_item;
164
+
$('#aiomatic_data_list').html(appendData);
165
+
}
166
+
catch(e)
167
+
{
168
+
alert(e);
169
+
}
170
+
}
171
+
var aiomatic_new_data_restore = window.localStorage.getItem('aiomatic_new_data_list');
172
+
if(aiomatic_new_data_restore !== null && aiomatic_new_data_restore !== "")
173
+
{
174
+
var appendData = '';
175
+
var oldobj = '';
176
+
try{
177
+
oldobj = JSON.parse(aiomatic_new_data_restore);
178
+
oldobj.forEach(function (element){if(element.prompt !== null && element.completion !== null && element.prompt !== undefined && element.completion !== undefined){appendData += '<div class="aiomatic_new_data_item aiomatic_new_data"><div><textarea rows="1" name="new_data[0][system]" class="regular-text aiomatic_new_data_system aiomatic_height" placeholder="System">' + element.system + '</textarea> </div><div><textarea rows="1" name="new_data[0][prompt]" class="regular-text aiomatic_new_data_prompt aiomatic_height" placeholder="User">' + element.prompt + '</textarea> </div><div><textarea rows="1" name="new_data[0][completion]" class="regular-text aiomatic_new_data_completion aiomatic_height" placeholder="Assistant">' + element.completion + '</textarea><span class="button button-link-delete">×</span></div></div>';}});
179
+
appendData += aiomatic_new_item;
180
+
$('#aiomatic_new_data_list').html(appendData);
181
+
}
182
+
catch(e)
183
+
{
184
+
alert(e);
185
+
}
186
+
}
187
+
var progressBar = $('.aiomatic-convert-bar');
188
+
var aiomatic_add_data = $('.aiomatic_add_data');
189
+
var aiomatic_clear_data = $('.aiomatic_clear_data');
190
+
var aiomatic_download_data = $('.aiomatic_download_data');
191
+
var aiomatic_load_data = $('.aiomatic_load_data');
192
+
var form = $('#aiomatic_form_data');
193
+
aiomatic_add_data.on('click', function (){
194
+
var select = jQuery('#model_selector_data_training').val();
195
+
if(moder_gpt_models_aiomatic.includes(select))
196
+
{
197
+
$('#aiomatic_new_data_list').append(aiomatic_new_item);
198
+
}
199
+
else
200
+
{
201
+
$('#aiomatic_data_list').append(aiomatic_item);
202
+
}
203
+
aiomaticSortData();
204
+
var total = 0;
205
+
var lists = [];
206
+
$('.aiomatic_data').each(function (idx, item){
207
+
var item_prompt = $(item).find('.aiomatic_data_prompt').val();
208
+
var item_completion = $(item).find('.aiomatic_data_completion').val();
209
+
if(item_prompt !== '' && item_completion !== ''){
210
+
total += 1;
211
+
lists.push({prompt: item_prompt, completion: item_completion});
212
+
}
213
+
});
214
+
if(total > 0){
215
+
try
216
+
{
217
+
var jsonstr = JSON.stringify(lists);
218
+
window.localStorage.setItem('aiomatic_data_list', jsonstr);
219
+
}
220
+
catch(e)
221
+
{
222
+
alert(e);
223
+
}
224
+
}
225
+
var new_total = 0;
226
+
var new_lists = [];
227
+
$('.aiomatic_new_data').each(function (idx, item){
228
+
var item_system = $(item).find('.aiomatic_new_data_system').val();
229
+
var item_prompt = $(item).find('.aiomatic_new_data_prompt').val();
230
+
var item_completion = $(item).find('.aiomatic_new_data_completion').val();
231
+
if(item_prompt !== '' && item_completion !== ''){
232
+
new_total += 1;
233
+
new_lists.push({system: item_system, prompt: item_prompt, completion: item_completion});
234
+
}
235
+
});
236
+
if(new_total > 0){
237
+
try
238
+
{
239
+
var jsonstr = JSON.stringify(new_lists);
240
+
window.localStorage.setItem('aiomatic_new_data_list', jsonstr);
241
+
}
242
+
catch(e)
243
+
{
244
+
alert(e);
245
+
}
246
+
}
247
+
});
248
+
aiomatic_clear_data.on('click', function ()
249
+
{
250
+
var select = jQuery('#model_selector_data_training').val();
251
+
if(moder_gpt_models_aiomatic.includes(select))
252
+
{
253
+
$('#aiomatic_new_data_list').html('<div class="aiomatic_new_data_item aiomatic_new_data"><div><textarea rows="1" name="new_data[0][system]" class="regular-text aiomatic_new_data_system aiomatic_height" placeholder="System"></textarea></div><div><textarea rows="1" name="new_data[0][prompt]" class="regular-text aiomatic_new_data_prompt aiomatic_height" placeholder="User"></textarea></div><div><textarea rows="1" name="new_data[0][completion]" class="regular-text aiomatic_new_data_completion aiomatic_height" placeholder="Assistant"></textarea><span class="button button-link-delete">×</span></div></div>');
254
+
window.localStorage.removeItem('aiomatic_new_data_list');
255
+
}
256
+
else
257
+
{
258
+
$('#aiomatic_data_list').html('<div class="aiomatic_data_item aiomatic_data"><div><textarea rows="1" name="data[0][prompt]" class="regular-text aiomatic_data_prompt aiomatic_height" placeholder="Prompt"></textarea></div><div><textarea rows="1" name="data[0][completion]" class="regular-text aiomatic_data_completion aiomatic_height" placeholder="Completion"></textarea><span class="button button-link-delete">×</span></div></div>');
259
+
window.localStorage.removeItem('aiomatic_data_list');
260
+
}
261
+
});
262
+
var Download =
263
+
{
264
+
click : function(node) {
265
+
var ev = new MouseEvent("click", {
266
+
bubbles: true,
267
+
cancelable: false,
268
+
view: window,
269
+
detail: 0,
270
+
screenX: 0,
271
+
screenY: 0,
272
+
clientX: 0,
273
+
clientY: 0,
274
+
ctrlKey: false,
275
+
altKey: false,
276
+
shiftKey: false,
277
+
metaKey: false,
278
+
button: 0,
279
+
relatedTarget: null
280
+
});
281
+
return node.dispatchEvent(ev);
282
+
},
283
+
encode : function(data) {
284
+
return 'data:application/octet-stream;base64,' + btoa( data );
285
+
},
286
+
link : function(data, name){
287
+
var a = document.createElement('a');
288
+
a.download = name || self.location.pathname.slice(self.location.pathname.lastIndexOf('/')+1);
289
+
a.href = data || self.location.href;
290
+
return a;
291
+
}
292
+
};
293
+
Download.save = function(data, name)
294
+
{
295
+
this.click(
296
+
this.link(
297
+
this.encode( data ),
298
+
name
299
+
)
300
+
);
301
+
};
302
+
aiomatic_download_data.on('click', function (){
303
+
var select = jQuery('#model_selector_data_training').val();
304
+
if(moder_gpt_models_aiomatic.includes(select))
305
+
{
306
+
var total = 0;
307
+
var lists = '';
308
+
$('.aiomatic_new_data').each(function (idx, item){
309
+
var item_system = $(item).find('.aiomatic_new_data_system').val();
310
+
var item_prompt = $(item).find('.aiomatic_new_data_prompt').val();
311
+
var item_completion = $(item).find('.aiomatic_new_data_completion').val();
312
+
if(item_prompt !== '' && item_completion !== ''){
313
+
total += 1;
314
+
var messages = [
315
+
{
316
+
role: "system",
317
+
content: item_system
318
+
},
319
+
{
320
+
role: "user",
321
+
content: item_prompt
322
+
},
323
+
{
324
+
role: "assistant",
325
+
content: item_completion
326
+
}
327
+
];
328
+
var json_arr = {
329
+
messages: messages
330
+
};
331
+
try
332
+
{
333
+
var myJsonString = JSON.stringify(json_arr);
334
+
lists += myJsonString + '\n';
335
+
}
336
+
catch(e)
337
+
{
338
+
alert(e);
339
+
}
340
+
}
341
+
});
342
+
lists = lists.trim();
343
+
if(total > 0){
344
+
try
345
+
{
346
+
Download.save(lists, "new_data.jsonl");
347
+
}
348
+
catch(e)
349
+
{
350
+
alert(e);
351
+
}
352
+
}
353
+
else
354
+
{
355
+
alert('No data to download!');
356
+
}
357
+
}
358
+
else
359
+
{
360
+
var total = 0;
361
+
var lists = '';
362
+
$('.aiomatic_data').each(function (idx, item){
363
+
var item_prompt = $(item).find('.aiomatic_data_prompt').val();
364
+
var item_completion = $(item).find('.aiomatic_data_completion').val();
365
+
if(item_prompt !== '' && item_completion !== ''){
366
+
total += 1;
367
+
var json_arr = {};
368
+
json_arr['prompt'] = item_prompt;
369
+
json_arr['completion'] = item_completion;
370
+
try
371
+
{
372
+
var myJsonString = JSON.stringify(json_arr);
373
+
lists += myJsonString + '\n';
374
+
}
375
+
catch(e)
376
+
{
377
+
alert(e);
378
+
}
379
+
}
380
+
});
381
+
lists = lists.trim();
382
+
if(total > 0){
383
+
try
384
+
{
385
+
Download.save(lists, "data.jsonl");
386
+
}
387
+
catch(e)
388
+
{
389
+
alert(e);
390
+
}
391
+
}
392
+
else
393
+
{
394
+
alert('No data to download!');
395
+
}
396
+
}
397
+
});
398
+
aiomatic_load_data.on('click', function (event){
399
+
event.preventDefault();
400
+
var aiomatic_file_load = $('#aiomatic_file_load');
401
+
if(aiomatic_file_load[0].files.length === 0){
402
+
alert('Please select a file first!');
403
+
}
404
+
else
405
+
{
406
+
var aiomatic_file = aiomatic_file_load[0].files[0];
407
+
var aiomatic_file_extension = aiomatic_file.name.substr( (aiomatic_file.name.lastIndexOf('.') +1) );
408
+
if(aiomatic_file_extension !== 'jsonl' && aiomatic_file_extension !== 'csv')
409
+
{
410
+
aiomatic_file_load.val('');
411
+
alert('This feature only accepts JSONL or CSV file type!');
412
+
}
413
+
else if(aiomatic_file.size > aiomatic_max_file_size)
414
+
{
415
+
aiomatic_file_load.val('');
416
+
alert('Dataset allowed maximum size (MB): '+ aiomatic_max_size_in_mb)
417
+
}
418
+
else
419
+
{
420
+
var select = jQuery('#model_selector_data_training').val();
421
+
if(moder_gpt_models_aiomatic.includes(select))
422
+
{
423
+
var reader = new FileReader();
424
+
reader.readAsText(aiomatic_file, "UTF-8");
425
+
var thehtml = '';
426
+
reader.onload = function (evt) {
427
+
if(aiomatic_file_extension == 'jsonl')
428
+
{
429
+
var explodefile = evt.target.result.split(/\r?\n/);
430
+
explodefile.forEach(function (element){if(element.trim() !== ''){var oldobj = '';try{oldobj = JSON.parse(element.trim());}catch(e) {alert(e);}if(oldobj.hasOwnProperty("messages")){if(oldobj.messages[0].role !== null && oldobj.messages[1].role !== null && oldobj.messages[2].role !== null && oldobj.messages[0].role !== undefined && oldobj.messages[1].role !== undefined && oldobj.messages[2].role !== undefined){thehtml += '<div class="aiomatic_new_data_item aiomatic_new_data"><div><textarea rows="1" name="new_data[0][prompt]" class="regular-text aiomatic_new_data_system aiomatic_height" placeholder="System">' + oldobj.messages[0].content + '</textarea> </div><div><textarea rows="1" name="new_data[0][prompt]" class="regular-text aiomatic_new_data_prompt aiomatic_height" placeholder="User">' + oldobj.messages[1].content + '</textarea> </div><div><textarea rows="1" name="new_data[0][completion]" class="regular-text aiomatic_new_data_completion aiomatic_height" placeholder="Assistant">' + oldobj.messages[2].content + '</textarea><span class="button button-link-delete">×</span></div></div>';}}}});
431
+
if(thehtml !== '')
432
+
{
433
+
thehtml += '<div class="aiomatic_new_data_item aiomatic_new_data"><div><textarea rows="1" name="new_data[0][system]" class="regular-text aiomatic_new_data_system aiomatic_height" placeholder="System"></textarea> </div><div><textarea rows="1" name="new_data[0][prompt]" class="regular-text aiomatic_new_data_prompt aiomatic_height" placeholder="User"></textarea> </div><div><textarea rows="1" name="new_data[0][completion]" class="regular-text aiomatic_new_data_completion aiomatic_height" placeholder="Assistant"></textarea><span class="button button-link-delete">×</span></div></div>';
434
+
$('#aiomatic_new_data_list').html(thehtml);
435
+
var total = 0;
436
+
var lists = [];
437
+
$('.aiomatic_new_data').each(function (idx, item){
438
+
var item_system = $(item).find('.aiomatic_new_data_system').val();
439
+
var item_prompt = $(item).find('.aiomatic_new_data_prompt').val();
440
+
var item_completion = $(item).find('.aiomatic_new_data_completion').val();
441
+
if(item_prompt !== '' && item_completion !== ''){
442
+
total += 1;
443
+
lists.push({system: item_system, prompt: item_prompt, completion: item_completion});
444
+
}
445
+
});
446
+
if(total > 0){
447
+
try
448
+
{
449
+
var jsonstr = JSON.stringify(lists);
450
+
window.localStorage.setItem('aiomatic_new_data_list', jsonstr);
451
+
alert("Data loaded successfully!");
452
+
}
453
+
catch(e)
454
+
{
455
+
alert(e);
456
+
}
457
+
}
458
+
}
459
+
else
460
+
{
461
+
alert("Invalid file submitted: " + aiomatic_file.name);
462
+
}
463
+
}
464
+
else
465
+
{
466
+
let data = evt.target.result.split("\r\n");
467
+
for (let i in data) {
468
+
data[i] = data[i].split(",");
469
+
}
470
+
data.forEach(function (element){if(element[0] !== null && element[0] != '' && element[1] != '' && element[1] !== null && element[2] != '' && element[2] !== null){thehtml += '<div class="aiomatic_new_data_item aiomatic_new_data"><div><textarea rows="1" name="new_data[0][system]" class="regular-text aiomatic_new_data_system aiomatic_height" placeholder="System">' + element[0] + '</textarea> </div><div><textarea rows="1" name="new_data[0][prompt]" class="regular-text aiomatic_new_data_prompt aiomatic_height" placeholder="User">' + element[1] + '</textarea> </div><div><textarea rows="1" name="new_data[0][completion]" class="regular-text aiomatic_new_data_completion aiomatic_height" placeholder="Assistant">' + element[2] + '</textarea><span class="button button-link-delete">×</span></div></div>';}});
471
+
if(thehtml !== '')
472
+
{
473
+
thehtml += '<div class="aiomatic_new_data_item aiomatic_new_data"><div><textarea rows="1" name="new_data[0][system]" class="regular-text aiomatic_new_data_system aiomatic_height" placeholder="System"></textarea> </div><div><textarea rows="1" name="new_data[0][prompt]" class="regular-text aiomatic_new_data_prompt aiomatic_height" placeholder="User"></textarea> </div><div><textarea rows="1" name="new_data[0][completion]" class="regular-text aiomatic_new_data_completion aiomatic_height" placeholder="Assistant"></textarea><span class="button button-link-delete">×</span></div></div>';
474
+
$('#aiomatic_new_data_list').html(thehtml);
475
+
var total = 0;
476
+
var lists = [];
477
+
$('.aiomatic_new_data').each(function (idx, item){
478
+
var item_system = $(item).find('.aiomatic_new_data_system').val();
479
+
var item_prompt = $(item).find('.aiomatic_new_data_prompt').val();
480
+
var item_completion = $(item).find('.aiomatic_new_data_completion').val();
481
+
if(item_prompt !== '' && item_completion !== ''){
482
+
total += 1;
483
+
lists.push({system: item_system, prompt: item_prompt, completion: item_completion});
484
+
}
485
+
});
486
+
if(total > 0){
487
+
try
488
+
{
489
+
var jsonstr = JSON.stringify(lists);
490
+
window.localStorage.setItem('aiomatic_new_data_list', jsonstr);
491
+
alert("Data loaded successfully!");
492
+
}
493
+
catch(e)
494
+
{
495
+
alert(e);
496
+
}
497
+
}
498
+
}
499
+
else
500
+
{
501
+
alert("Invalid file submitted: " + aiomatic_file.name);
502
+
}
503
+
}
504
+
}
505
+
reader.onerror = function (evt) {
506
+
alert("Error reading file: " + aiomatic_file.name + ' - ' + reader.error);
507
+
}
508
+
}
509
+
else
510
+
{
511
+
var reader = new FileReader();
512
+
reader.readAsText(aiomatic_file, "utf-8");
513
+
var thehtml = '';
514
+
reader.onload = function (evt) {
515
+
if(aiomatic_file_extension == 'jsonl')
516
+
{
517
+
var explodefile = evt.target.result.split(/\r?\n/);
518
+
explodefile.forEach(function (element){if(element.trim() !== ''){var oldobj = '';try{oldobj = JSON.parse(element.trim());}catch(e) {alert(e);}if(oldobj.hasOwnProperty("prompt")){if(oldobj.prompt !== null && oldobj.completion !== null){thehtml += '<div class="aiomatic_data_item aiomatic_data"><div><textarea rows="1" name="data[0][prompt]" class="regular-text aiomatic_data_prompt aiomatic_height" placeholder="Prompt">' + oldobj.prompt + '</textarea> </div><div><textarea rows="1" name="data[0][completion]" class="regular-text aiomatic_data_completion aiomatic_height" placeholder="Completion">' + oldobj.completion + '</textarea><span class="button button-link-delete">×</span></div></div>';}}}});
519
+
if(thehtml !== '')
520
+
{
521
+
thehtml += '<div class="aiomatic_data_item aiomatic_data"><div><textarea rows="1" name="data[0][prompt]" class="regular-text aiomatic_data_prompt aiomatic_height" placeholder="Prompt"></textarea> </div><div><textarea rows="1" name="data[0][completion]" class="regular-text aiomatic_data_completion aiomatic_height" placeholder="Completion"></textarea><span class="button button-link-delete">×</span></div></div>';
522
+
$('#aiomatic_data_list').html(thehtml);
523
+
var total = 0;
524
+
var lists = [];
525
+
$('.aiomatic_data').each(function (idx, item){
526
+
var item_prompt = $(item).find('.aiomatic_data_prompt').val();
527
+
var item_completion = $(item).find('.aiomatic_data_completion').val();
528
+
if(item_prompt !== '' && item_completion !== ''){
529
+
total += 1;
530
+
lists.push({prompt: item_prompt, completion: item_completion});
531
+
}
532
+
});
533
+
if(total > 0){
534
+
try
535
+
{
536
+
var jsonstr = JSON.stringify(lists);
537
+
window.localStorage.setItem('aiomatic_data_list', jsonstr);
538
+
alert("Data loaded successfully!");
539
+
}
540
+
catch(e)
541
+
{
542
+
alert(e);
543
+
}
544
+
}
545
+
}
546
+
else
547
+
{
548
+
alert("Invalid file submitted: " + aiomatic_file.name);
549
+
}
550
+
}
551
+
else
552
+
{
553
+
let data = evt.target.result.split("\r\n");
554
+
for (let i in data) {
555
+
data[i] = data[i].split(",");
556
+
}
557
+
data.forEach(function (element){if(element[0] !== null && element[0] != '' && element[1] != '' && element[1] !== null){thehtml += '<div class="aiomatic_data_item aiomatic_data"><div><textarea rows="1" name="data[0][prompt]" class="regular-text aiomatic_data_prompt aiomatic_height" placeholder="Prompt">' + element[0] + '</textarea> </div><div><textarea rows="1" name="data[0][completion]" class="regular-text aiomatic_data_completion aiomatic_height" placeholder="Completion">' + element[1] + '</textarea><span class="button button-link-delete">×</span></div></div>';}});
558
+
if(thehtml !== '')
559
+
{
560
+
thehtml += '<div class="aiomatic_data_item aiomatic_data"><div><textarea rows="1" name="data[0][prompt]" class="regular-text aiomatic_data_prompt aiomatic_height" placeholder="Prompt"></textarea> </div><div><textarea rows="1" name="data[0][completion]" class="regular-text aiomatic_data_completion aiomatic_height" placeholder="Completion"></textarea><span class="button button-link-delete">×</span></div></div>';
561
+
$('#aiomatic_data_list').html(thehtml);
562
+
var total = 0;
563
+
var lists = [];
564
+
$('.aiomatic_data').each(function (idx, item){
565
+
var item_prompt = $(item).find('.aiomatic_data_prompt').val();
566
+
var item_completion = $(item).find('.aiomatic_data_completion').val();
567
+
if(item_prompt !== '' && item_completion !== ''){
568
+
total += 1;
569
+
lists.push({prompt: item_prompt, completion: item_completion});
570
+
}
571
+
});
572
+
if(total > 0){
573
+
try
574
+
{
575
+
var jsonstr = JSON.stringify(lists);
576
+
window.localStorage.setItem('aiomatic_data_list', jsonstr);
577
+
alert("Data loaded successfully!");
578
+
}
579
+
catch(e)
580
+
{
581
+
alert(e);
582
+
}
583
+
}
584
+
}
585
+
else
586
+
{
587
+
alert("Invalid file submitted: " + aiomatic_file.name);
588
+
}
589
+
}
590
+
}
591
+
reader.onerror = function (evt) {
592
+
alert("Error reading file: " + aiomatic_file.name + ' - ' + reader.error);
593
+
}
594
+
}
595
+
}
596
+
}
597
+
});
598
+
$(document).on('click','.aiomatic_data span', function (e){
599
+
$(e.currentTarget).parent().parent().remove();
600
+
var total = 0;
601
+
var lists = [];
602
+
$('.aiomatic_data').each(function (idx, item){
603
+
var item_prompt = $(item).find('.aiomatic_data_prompt').val();
604
+
var item_completion = $(item).find('.aiomatic_data_completion').val();
605
+
if(item_prompt !== '' && item_completion !== ''){
606
+
total += 1;
607
+
lists.push({prompt: item_prompt, completion: item_completion});
608
+
}
609
+
});
610
+
if(total > 0){
611
+
try
612
+
{
613
+
var jsonstr = JSON.stringify(lists);
614
+
window.localStorage.setItem('aiomatic_data_list', jsonstr);
615
+
}
616
+
catch(e)
617
+
{
618
+
alert(e);
619
+
}
620
+
}
621
+
else
622
+
{
623
+
window.localStorage.removeItem('aiomatic_data_list');
624
+
}
625
+
aiomaticSortData();
626
+
});
627
+
628
+
$(document).on('click','.aiomatic_new_data span', function (e){
629
+
$(e.currentTarget).parent().parent().remove();
630
+
var total = 0;
631
+
var lists = [];
632
+
$('.aiomatic_new_data').each(function (idx, item){
633
+
var item_system = $(item).find('.aiomatic_new_data_system').val();
634
+
var item_prompt = $(item).find('.aiomatic_new_data_prompt').val();
635
+
var item_completion = $(item).find('.aiomatic_new_data_completion').val();
636
+
if(item_prompt !== '' && item_completion !== ''){
637
+
total += 1;
638
+
lists.push({system: item_system, prompt: item_prompt, completion: item_completion});
639
+
}
640
+
});
641
+
if(total > 0){
642
+
try
643
+
{
644
+
var jsonstr = JSON.stringify(lists);
645
+
window.localStorage.setItem('aiomatic_new_data_list', jsonstr);
646
+
}
647
+
catch(e)
648
+
{
649
+
alert(e);
650
+
}
651
+
}
652
+
else
653
+
{
654
+
window.localStorage.removeItem('aiomatic_new_data_list');
655
+
}
656
+
aiomaticSortData();
657
+
});
658
+
659
+
function aiomaticFileUpload(data, btn){
660
+
var aiomatic_upload_convert_index = parseInt($('#aiomatic_upload_convert_index').val());
661
+
$.ajax({
662
+
url: aiomatic_ajax_url,
663
+
data: data,
664
+
type: 'POST',
665
+
dataType: 'JSON',
666
+
success: function (res){
667
+
if(res.status === 'success'){
668
+
if(res.next === 'DONE'){
669
+
var select = jQuery('#model_selector_data_training').val();
670
+
if(moder_gpt_models_aiomatic.includes(select))
671
+
{
672
+
$('#aiomatic_new_data_list').html(aiomatic_new_item);
673
+
}
674
+
else
675
+
{
676
+
$('#aiomatic_data_list').html(aiomatic_item);
677
+
}
678
+
$('.aiomatic-upload-message').html('The upload was successfully completed!');
679
+
progressBar.find('small').html('100%');
680
+
progressBar.find('span').css('width','100%');
681
+
aiomaticRmLoading(btn);
682
+
setTimeout(function (){
683
+
$('#aiomatic_upload_convert_line').val('0');
684
+
$('#aiomatic_upload_convert_index').val('1');
685
+
progressBar.hide();
686
+
progressBar.removeClass('aiomatic_error')
687
+
progressBar.find('span').css('width',0);
688
+
progressBar.find('small').html('0%');
689
+
},2000);
690
+
691
+
}
692
+
else{
693
+
$('#aiomatic_upload_convert_line').val(res.next);
694
+
$('#aiomatic_upload_convert_index').val(aiomatic_upload_convert_index+1);
695
+
var data = $('#aiomatic_upload_convert').serialize();
696
+
aiomaticFileUpload(data, btn);
697
+
}
698
+
}
699
+
else{
700
+
progressBar.addClass('aiomatic_error');
701
+
aiomaticRmLoading(btn);
702
+
alert(res.msg);
703
+
}
704
+
},
705
+
error: function (r, s, error){
706
+
progressBar.addClass('aiomatic_error');
707
+
aiomaticRmLoading(btn);
708
+
alert('Error in processing upload: ' + error);
709
+
}
710
+
})
711
+
}
712
+
713
+
function aiomaticProcessData(lists, start, file, btn){
714
+
var purpose = $('select[name=purpose]').val();
715
+
var model = $('select[name=model]').val();
716
+
var name = $('#file-name-holder').val();
717
+
if(file == '' && name != '')
718
+
{
719
+
file = name;
720
+
}
721
+
var data = {
722
+
action: 'aiomatic_data_insert',
723
+
prompt: aiomatic_stripslashes(lists[start].prompt),
724
+
completion: aiomatic_stripslashes(lists[start].completion),
725
+
file: file,
726
+
nonce: aiomatic_object.nonce
727
+
};
728
+
$.ajax({
729
+
url: aiomatic_ajax_url,
730
+
data: data,
731
+
dataType: 'JSON',
732
+
type: 'POST',
733
+
success: function (res){
734
+
if(res.status === 'success'){
735
+
var percent = Math.ceil((start+1)*90/lists.length);
736
+
progressBar.find('small').html(percent+'%');
737
+
progressBar.find('span').css('width',percent+'%');
738
+
if((start + 1) === lists.length){
739
+
$('#aiomatic_upload_convert input[name=model]').val(model);
740
+
$('#aiomatic_upload_convert input[name=purpose]').val(purpose);
741
+
$('#aiomatic_upload_convert input[name=custom]').val(name);
742
+
$('#aiomatic_upload_convert input[name=file]').val(res.file);
743
+
var data = $('#aiomatic_upload_convert').serialize();
744
+
aiomaticFileUpload(data, btn);
745
+
}
746
+
else{
747
+
aiomaticProcessData(lists, (start+1), file, btn);
748
+
}
749
+
}
750
+
else{
751
+
progressBar.addClass('aiomatic_error');
752
+
aiomaticRmLoading(btn);
753
+
alert(res.msg);
754
+
}
755
+
},
756
+
error: function (r, s, error){
757
+
progressBar.addClass('aiomatic_error');
758
+
aiomaticRmLoading(btn);
759
+
alert('Error in processing data: ' + error);
760
+
}
761
+
});
762
+
}
763
+
function aiomaticNewProcessData(lists, start, file, btn){
764
+
var purpose = $('select[name=purpose]').val();
765
+
var model = $('select[name=model]').val();
766
+
var name = $('#file-name-holder').val();
767
+
if(file == '' && name != '')
768
+
{
769
+
file = name;
770
+
}
771
+
var data = {
772
+
action: 'aiomatic_new_data_insert',
773
+
system: aiomatic_stripslashes(lists[start].system),
774
+
prompt: aiomatic_stripslashes(lists[start].prompt),
775
+
completion: aiomatic_stripslashes(lists[start].completion),
776
+
file: file,
777
+
nonce: aiomatic_object.nonce
778
+
};
779
+
$.ajax({
780
+
url: aiomatic_ajax_url,
781
+
data: data,
782
+
dataType: 'JSON',
783
+
type: 'POST',
784
+
success: function (res){
785
+
if(res.status === 'success'){
786
+
var percent = Math.ceil((start+1)*90/lists.length);
787
+
progressBar.find('small').html(percent+'%');
788
+
progressBar.find('span').css('width',percent+'%');
789
+
if((start + 1) === lists.length){
790
+
$('#aiomatic_upload_convert input[name=model]').val(model);
791
+
$('#aiomatic_upload_convert input[name=purpose]').val(purpose);
792
+
$('#aiomatic_upload_convert input[name=custom]').val(name);
793
+
$('#aiomatic_upload_convert input[name=file]').val(res.file);
794
+
var data = $('#aiomatic_upload_convert').serialize();
795
+
aiomaticFileUpload(data, btn);
796
+
}
797
+
else{
798
+
aiomaticNewProcessData(lists, (start+1), file, btn);
799
+
}
800
+
}
801
+
else{
802
+
progressBar.addClass('aiomatic_error');
803
+
aiomaticRmLoading(btn);
804
+
alert(res.msg);
805
+
}
806
+
},
807
+
error: function (r, s, error){
808
+
progressBar.addClass('aiomatic_error');
809
+
aiomaticRmLoading(btn);
810
+
alert('Error in processing data: ' + error);
811
+
}
812
+
});
813
+
}
814
+
form.on('submit', function (){
815
+
var select = jQuery('#model_selector_data_training').val();
816
+
if(moder_gpt_models_aiomatic.includes(select))
817
+
{
818
+
var total = 0;
819
+
var lists = [];
820
+
var btn = form.find('.aiomatic_submit');
821
+
$('.aiomatic_new_data').each(function (idx, item){
822
+
var item_system = $(item).find('.aiomatic_new_data_system').val();
823
+
var item_prompt = $(item).find('.aiomatic_new_data_prompt').val();
824
+
var item_completion = $(item).find('.aiomatic_new_data_completion').val();
825
+
if(item_prompt !== '' && item_completion !== ''){
826
+
total += 1;
827
+
lists.push({system: item_system, prompt: item_prompt, completion: item_completion })
828
+
}
829
+
});
830
+
if(total > 0){
831
+
$('#aiomatic_upload_convert_line').val('0');
832
+
$('#aiomatic_upload_convert_index').val('1');
833
+
$('.aiomatic-upload-message').empty();
834
+
progressBar.show();
835
+
progressBar.removeClass('aiomatic_error')
836
+
progressBar.find('span').css('width',0);
837
+
progressBar.find('small').html('0%');
838
+
aiomaticLoading(btn);
839
+
aiomaticNewProcessData(lists, 0, '', btn);
840
+
}
841
+
else{
842
+
alert('Please insert at least one row');
843
+
}
844
+
}
845
+
else
846
+
{
847
+
var total = 0;
848
+
var lists = [];
849
+
var btn = form.find('.aiomatic_submit');
850
+
$('.aiomatic_data').each(function (idx, item){
851
+
var item_prompt = $(item).find('.aiomatic_data_prompt').val();
852
+
var item_completion = $(item).find('.aiomatic_data_completion').val();
853
+
if(item_prompt !== '' && item_completion !== ''){
854
+
total += 1;
855
+
lists.push({prompt: item_prompt, completion: item_completion })
856
+
}
857
+
});
858
+
if(total > 0){
859
+
$('#aiomatic_upload_convert_line').val('0');
860
+
$('#aiomatic_upload_convert_index').val('1');
861
+
$('.aiomatic-upload-message').empty();
862
+
progressBar.show();
863
+
progressBar.removeClass('aiomatic_error')
864
+
progressBar.find('span').css('width',0);
865
+
progressBar.find('small').html('0%');
866
+
aiomaticLoading(btn);
867
+
aiomaticProcessData(lists, 0, '', btn);
868
+
}
869
+
else{
870
+
alert('Please insert at least one row');
871
+
}
872
+
}
873
+
return false;
874
+
});
875
+
$('.aiomatic_modal_close').on('click', function (){
876
+
$('.aiomatic_modal_close').closest('.aiomatic_modal').hide();
877
+
$('.aiomatic_modal_close').closest('.aiomatic_modal').removeClass('aiomatic-small-modal');
878
+
$('.aiomatic-overlay').hide();
879
+
});
880
+
var form = $('#aiomatic_data_converter');
881
+
var btn = $('.aiomatic_converter_button');
882
+
var progressBar = $('.aiomatic-convert-bar');
883
+
var aiomatic_convert_upload = $('.aiomatic_convert_upload');
884
+
var aiomatic_delete_upload = $('.aiomatic_delete_upload');
885
+
function aiomaticConverter(data){
886
+
$.ajax({
887
+
url: aiomatic_ajax_url,
888
+
data: data,
889
+
type: 'POST',
890
+
dataType: 'JSON',
891
+
success: function (res){
892
+
if(res.status === 'success'){
893
+
if(res.next_page === 'DONE'){
894
+
aiomaticRmLoading(btn);
895
+
progressBar.find('small').html('100%');
896
+
progressBar.find('span').css('width','100%');
897
+
setTimeout(function (){
898
+
window.location.reload();
899
+
},1000);
900
+
}
901
+
else{
902
+
var percent = Math.ceil(data.page*100/data.total);
903
+
progressBar.find('small').html(percent+'%');
904
+
progressBar.find('span').css('width',percent+'%');
905
+
data.page = res.next_page;
906
+
data.file = res.file;
907
+
data.id = res.id;
908
+
aiomaticConverter(data);
909
+
}
910
+
}
911
+
else{
912
+
progressBar.addClass('aiomatic_error');
913
+
aiomaticRmLoading(btn);
914
+
alert(res.msg);
915
+
}
916
+
},
917
+
error: function (request, status, error){
918
+
progressBar.addClass('aiomatic_error');
919
+
aiomaticRmLoading(btn);
920
+
alert('Error in processing: ' + error);
921
+
}
922
+
});
923
+
}
924
+
form.on('submit', function (){
925
+
if(!$('.aiomatic_converter_data:checked').length){
926
+
alert('Please select least one data to convert');
927
+
}
928
+
else{
929
+
var data = form.serialize();
930
+
$.ajax({
931
+
url: aiomatic_ajax_url,
932
+
data: data,
933
+
dataType: 'JSON',
934
+
type: 'POST',
935
+
beforeSend: function (){
936
+
progressBar.show();
937
+
progressBar.removeClass('aiomatic_error')
938
+
progressBar.find('span').css('width',0);
939
+
progressBar.find('small').html('0%');
940
+
aiomaticLoading(btn);
941
+
},
942
+
success: function (res){
943
+
if(res.status === 'success'){
944
+
if(res.count > 0){
945
+
aiomaticConverter({action: 'aiomatic_data_converter', types: res.types, category: res.category, model: res.model, total: res.count, page: 1, per_page: 100, content_excerpt: res.content_excerpt, nonce: aiomatic_object.nonce});
946
+
}
947
+
else{
948
+
progressBar.addClass('aiomatic_error');
949
+
aiomaticRmLoading(btn);
950
+
alert('Nothing to convert');
951
+
}
952
+
}
953
+
else{
954
+
progressBar.addClass('aiomatic_error');
955
+
aiomaticRmLoading(btn);
956
+
alert(res.msg);
957
+
}
958
+
},
959
+
error: function (request, status, error) {
960
+
progressBar.addClass('aiomatic_error');
961
+
aiomaticRmLoading(btn);
962
+
alert('Error in processing: ' + error);
963
+
}
964
+
});
965
+
}
966
+
return false;
967
+
});
968
+
aiomatic_convert_upload.on('click', function (){
969
+
var btn = $(this);
970
+
var file = btn.attr('data-file');
971
+
var lines = btn.attr('data-lines');
972
+
$('.aiomatic-overlay').show();
973
+
$('.aiomatic_modal').show();
974
+
$('.aiomatic_modal_title').html('File Setting');
975
+
$('.aiomatic_modal').addClass('aiomatic-small-modal');
976
+
$('.aiomatic_modal_content').empty();
977
+
var html = '<form id="aiomatic_upload_convert" action="" method="post"><input type="hidden" name="action" value="aiomatic_upload_convert"><input type="hidden" name="nonce" value="' + aiomatic_object.nonce + '"><input type="hidden" id="aiomatic_upload_convert_index" name="index" value="1"><input id="aiomatic_upload_convert_line" type="hidden" name="line" value="0"><input id="aiomatic_upload_convert_lines" type="hidden" value="'+lines+'"><input type="hidden" name="file" value="'+file+'"><p><label>Purpose</label> <select class="coderevolution_gutenberg_select" name="purpose"><option value="fine-tune">Fine-Tune</option></select></p>';
978
+
html += '<p><label>Model Base</label> <select class="coderevolution_gutenberg_select" name="model">';
979
+
aiomatic_object.all_training_models.forEach(model =>
980
+
{
981
+
const isSelected = model === aiomatic_object.default_training_model ? 'selected' : '';
982
+
html += `<option value="${model}" ${isSelected}>${model}</option>`;
983
+
});
984
+
html += '</select></p>';
985
+
html += '<p><label>Custom Name</label> <input class="coderevolution_gutenberg_select" type="text" name="custom"></p>';
986
+
html += '<div class="aiomatic-convert-progress aiomatic-upload-bar"><span></span><small>0%</small></div>';
987
+
html += '<div class="aiomatic-upload-message"></div><p><button class="button button-primary coderevolution_gutenberg_select">Upload</button></p>'
988
+
$('.aiomatic_modal_content').append(html);
989
+
});
990
+
aiomatic_delete_upload.on('click', function (){
991
+
var btn = $(this);
992
+
var file = btn.attr('data-file');
993
+
$.ajax({
994
+
url: aiomatic_ajax_url,
995
+
data: {
996
+
action: 'aiomatic_file_delete',
997
+
file: file,
998
+
nonce: aiomatic_object.nonce
999
+
},
1000
+
type: 'POST',
1001
+
beforeSend: function (){
1002
+
progressBar.show();
1003
+
progressBar.removeClass('aiomatic_error')
1004
+
progressBar.find('span').css('width',0);
1005
+
progressBar.find('small').html('0%');
1006
+
aiomaticLoading(btn);
1007
+
},
1008
+
success: function (res){
1009
+
if(res.status === 'success'){
1010
+
window.location.reload();
1011
+
}
1012
+
else{
1013
+
progressBar.addClass('aiomatic_error');
1014
+
aiomaticRmLoading(btn);
1015
+
alert(res.msg);
1016
+
}
1017
+
},
1018
+
error: function (request, status, error) {
1019
+
progressBar.addClass('aiomatic_error');
1020
+
aiomaticRmLoading(btn);
1021
+
alert('Error in deleting: ' + error);
1022
+
}
1023
+
});
1024
+
});
1025
+
function aiomaticFileUpload(data, btn){
1026
+
var aiomatic_upload_convert_index = parseInt($('#aiomatic_upload_convert_index').val());
1027
+
var total_lines = parseInt($('#aiomatic_upload_convert_lines').val());
1028
+
if(total_lines === 0)
1029
+
{
1030
+
total_lines = 1;
1031
+
}
1032
+
var aiomatic_upload_bar = $('.aiomatic-convert-bar');
1033
+
$.ajax({
1034
+
url: aiomatic_ajax_url,
1035
+
data: data,
1036
+
type: 'POST',
1037
+
dataType: 'JSON',
1038
+
success: function (res){
1039
+
if(res.status === 'success'){
1040
+
if(res.next === 'DONE'){
1041
+
$('.aiomatic-upload-message').html('Upload was successful!');
1042
+
res.next = total_lines;
1043
+
var percent = Math.ceil(res.next*100/total_lines);
1044
+
aiomatic_upload_bar.find('small').html(percent+'%');
1045
+
aiomatic_upload_bar.find('span').css('width',percent+'%');
1046
+
aiomaticRmLoading(btn);
1047
+
}
1048
+
else{
1049
+
var percent = Math.ceil(res.next*100/total_lines);
1050
+
aiomatic_upload_bar.find('small').html(percent+'%');
1051
+
aiomatic_upload_bar.find('span').css('width',percent+'%');
1052
+
$('#aiomatic_upload_convert_line').val(res.next);
1053
+
$('#aiomatic_upload_convert_index').val(aiomatic_upload_convert_index+1);
1054
+
var data = $('#aiomatic_upload_convert').serialize();
1055
+
aiomaticFileUpload(data,btn);
1056
+
}
1057
+
}
1058
+
else{
1059
+
aiomatic_upload_bar.addClass('aiomatic_error');
1060
+
aiomaticRmLoading(btn);
1061
+
alert(res.msg);
1062
+
}
1063
+
},
1064
+
error: function (r, s, error){
1065
+
aiomatic_upload_bar.addClass('aiomatic_error');
1066
+
aiomaticRmLoading(btn);
1067
+
alert('Error in processing file upload: ' + error);
1068
+
}
1069
+
});
1070
+
}
1071
+
$(document).on('submit','#aiomatic_upload_convert', function (e){
1072
+
$('#aiomatic_upload_convert_index').val(1);
1073
+
$('#aiomatic_upload_convert_line').val(0);
1074
+
$('.aiomatic-upload-message').empty();
1075
+
var form = $(e.currentTarget);
1076
+
var data = form.serialize();
1077
+
var btn = form.find('button');
1078
+
aiomaticLoading(btn);
1079
+
var aiomatic_upload_bar = $('.aiomatic-upload-bar');
1080
+
aiomatic_upload_bar.show();
1081
+
aiomatic_upload_bar.removeClass('aiomatic_error')
1082
+
aiomatic_upload_bar.find('span').css('width',0);
1083
+
aiomatic_upload_bar.find('small').html('0%');
1084
+
aiomaticFileUpload(data,btn);
1085
+
return false;
1086
+
});
1087
+
$('.aiomatic_modal_close').on('click', function (){
1088
+
$('.aiomatic_modal_close').closest('.aiomatic_modal').hide();
1089
+
$('.aiomatic_modal_close').closest('.aiomatic_modal').removeClass('aiomatic-small-modal');
1090
+
$('.aiomatic-overlay').hide();
1091
+
})
1092
+
var aiomaticAjaxRunning = false;
1093
+
$('.aiomatic_sync_files').on('click', function (){
1094
+
var btn = $(this);
1095
+
if(!aiomaticAjaxRunning) {
1096
+
$.ajax({
1097
+
url: aiomatic_ajax_url,
1098
+
data: {action: 'aiomatic_fetch_finetune_files', nonce: aiomatic_object.nonce},
1099
+
dataType: 'JSON',
1100
+
type: 'POST',
1101
+
beforeSend: function () {
1102
+
aiomaticAjaxRunning = true;
1103
+
aiomaticLoading(btn);
1104
+
},
1105
+
success: function (res) {
1106
+
aiomaticAjaxRunning = false;
1107
+
aiomaticRmLoading(btn);
1108
+
if (res.status === 'success') {
1109
+
window.location.reload();
1110
+
} else {
1111
+
alert(res.msg);
1112
+
}
1113
+
},
1114
+
error: function (r, s, error) {
1115
+
aiomaticAjaxRunning = false;
1116
+
aiomaticRmLoading(btn);
1117
+
alert('Error in processing sync: ' + error);
1118
+
}
1119
+
});
1120
+
}
1121
+
});
1122
+
aiomatic_delete_file.on('click', function (){
1123
+
if(!aiomaticAjaxRunning) {
1124
+
var conf = confirm('Are you sure that you want to delete this file?');
1125
+
if (conf) {
1126
+
var btn = $(this);
1127
+
var id = btn.attr('data-id');
1128
+
$.ajax({
1129
+
url: aiomatic_ajax_url,
1130
+
data: {action: 'aiomatic_delete_finetune_file', id: id, nonce: aiomatic_object.nonce},
1131
+
dataType: 'JSON',
1132
+
type: 'POST',
1133
+
beforeSend: function () {
1134
+
aiomaticAjaxRunning = true;
1135
+
aiomaticLoading(btn);
1136
+
},
1137
+
success: function (res) {
1138
+
aiomaticAjaxRunning = false;
1139
+
aiomaticRmLoading(btn);
1140
+
if (res.status === 'success') {
1141
+
window.location.reload();
1142
+
} else {
1143
+
alert(res.msg);
1144
+
}
1145
+
},
1146
+
error: function (r, s, error) {
1147
+
aiomaticAjaxRunning = false;
1148
+
aiomaticRmLoading(btn);
1149
+
alert('Error in processing finetune removal: ' + error);
1150
+
}
1151
+
});
1152
+
}
1153
+
else{
1154
+
aiomaticAjaxRunning = false;
1155
+
}
1156
+
}
1157
+
});
1158
+
$(document).on('click','#aiomatic_create_finetune_btn', function (e){
1159
+
if(!aiomaticAjaxRunning) {
1160
+
var btn = $(e.currentTarget);
1161
+
var id = $('#aiomatic_create_finetune_id').val();
1162
+
var model = $('#aiomatic_create_finetune_model').val();
1163
+
var hyper_epochs = $('#hyper_epochs').val();
1164
+
var hyper_batch = $('#hyper_batch').val();
1165
+
var hyper_rate = $('#hyper_rate').val();
1166
+
var hyper_loss = $('#hyper_loss').val();
1167
+
var hyper_suffix = $('#hyper_suffix').val();
1168
+
$.ajax({
1169
+
url: aiomatic_ajax_url,
1170
+
data: {action: 'aiomatic_create_finetune', id: id, model: model, hyper_epochs: hyper_epochs, hyper_batch: hyper_batch, hyper_rate: hyper_rate, hyper_loss: hyper_loss, hyper_suffix: hyper_suffix, nonce: aiomatic_object.nonce},
1171
+
dataType: 'JSON',
1172
+
type: 'POST',
1173
+
beforeSend: function () {
1174
+
aiomaticAjaxRunning = true;
1175
+
aiomaticLoading(btn);
1176
+
},
1177
+
success: function (res) {
1178
+
aiomaticRmLoading(btn);
1179
+
aiomaticAjaxRunning = false;
1180
+
if (res.status === 'success') {
1181
+
window.location.reload();
1182
+
} else {
1183
+
alert(res.msg);
1184
+
}
1185
+
},
1186
+
error: function (r, s, error) {
1187
+
aiomaticAjaxRunning = false;
1188
+
aiomaticRmLoading(btn);
1189
+
alert('Error in processing new finetune: ' + error);
1190
+
}
1191
+
});
1192
+
}
1193
+
});
1194
+
aiomatic_create_fine_tune.on('click', function (){
1195
+
if(!aiomaticAjaxRunning) {
1196
+
var btn = $(this);
1197
+
var id = btn.attr('data-id');
1198
+
$.ajax({
1199
+
url: aiomatic_ajax_url,
1200
+
data: {action: 'aiomatic_create_finetune_modal', nonce: aiomatic_object.nonce},
1201
+
dataType: 'JSON',
1202
+
type: 'POST',
1203
+
beforeSend: function () {
1204
+
aiomaticAjaxRunning = true;
1205
+
aiomaticLoading(btn);
1206
+
},
1207
+
success: function (res) {
1208
+
aiomaticAjaxRunning = false;
1209
+
aiomaticRmLoading(btn);
1210
+
if (res.status === 'success') {
1211
+
$('.aiomatic_modal_content').empty();
1212
+
$('.aiomatic-overlay').show();
1213
+
$('.aiomatic_modal').show();
1214
+
$('.aiomatic_modal_title').html('Choose Model');
1215
+
$('.aiomatic_modal').addClass('aiomatic-small-modal');
1216
+
var html = '<input type="hidden" id="aiomatic_create_finetune_id" value="' + id + '"><p><label>Select Model</label>';
1217
+
html += '<select class="coderevolution_gutenberg_select" id="aiomatic_create_finetune_model">';
1218
+
html += '<option value="">New Model</option>';
1219
+
$.each(res.data, function (idx, item) {
1220
+
html += '<option value="' + item + '">' + item + '</option>';
1221
+
})
1222
+
html += '</select>';
1223
+
html += '</p>';
1224
+
html += '<p>Enable Hyperparameters: <input type="checkbox" id="hyper_switcher" onchange="aiomatic_switcher_change()"></p>';
1225
+
html += '<div id="hyper_div" style="display:none;">'
1226
+
html += '<p>Number of Epochs: <input type="number" min="1" max="999" step="1" id="hyper_epochs" class="coderevolution_gutenberg_input" placeholder="The number of epochs to train the model for"></p>';
1227
+
html += '<p>Batch Size: <input type="number" min="1" max="999" step="1" id="hyper_batch" class="coderevolution_gutenberg_input" placeholder="The batch size to use for training"></p>';
1228
+
html += '<p>Learning Rate Multiplier: <input type="number" min="0" max="1" step="0.01" id="hyper_rate" class="coderevolution_gutenberg_input" placeholder="The learning rate multiplier to use for training"></p>';
1229
+
html += '<p>Prompt Loss Weight: <input type="number" min="0" max="1" step="0.01" id="hyper_loss" class="coderevolution_gutenberg_input" placeholder="The weight to use for loss on the prompt tokens"></p>';
1230
+
html += '<p>Model Suffix: <input type="text" id="hyper_suffix" class="coderevolution_gutenberg_input" placeholder="A string of up to 40 characters that will be added to your fine-tuned model name"></p>';
1231
+
html += '</div>';
1232
+
html += '<p><button class="button button-primary coderevolution_gutenberg_select" id="aiomatic_create_finetune_btn">Create</button></p>';
1233
+
html += '<script>function aiomatic_switcher_change() {if(jQuery(\'#hyper_switcher\').is(":checked")) {jQuery("#hyper_div").show();} else {jQuery("#hyper_div").hide();}};</script>';
1234
+
$('.aiomatic_modal_content').append(html);
1235
+
} else {
1236
+
alert(res.msg);
1237
+
}
1238
+
},
1239
+
error: function (r, s, error) {
1240
+
aiomaticAjaxRunning = false;
1241
+
aiomaticRmLoading(btn);
1242
+
alert('Error in processing new finetune modal: ' + error);
1243
+
}
1244
+
});
1245
+
}
1246
+
});
1247
+
aiomatic_retrieve_content.on('click', function (){
1248
+
if(!aiomaticAjaxRunning) {
1249
+
var btn = $(this);
1250
+
var id = btn.attr('data-id');
1251
+
$.ajax({
1252
+
url: aiomatic_ajax_url,
1253
+
data: {action: 'aiomatic_get_finetune_file', id: id, nonce: aiomatic_object.nonce},
1254
+
dataType: 'JSON',
1255
+
type: 'POST',
1256
+
beforeSend: function () {
1257
+
aiomaticAjaxRunning = true;
1258
+
aiomaticLoading(btn);
1259
+
},
1260
+
success: function (res) {
1261
+
aiomaticAjaxRunning = false;
1262
+
aiomaticRmLoading(btn);
1263
+
if (res.status === 'success') {
1264
+
$('.aiomatic_modal_title').html('File Content');
1265
+
$('.aiomatic_modal_content').html('<pre>' + res.data + '</pre>');
1266
+
$('.aiomatic-overlay').show();
1267
+
$('.aiomatic_modal').show();
1268
+
} else {
1269
+
alert(res.msg);
1270
+
}
1271
+
},
1272
+
error: function (r, s, error) {
1273
+
aiomaticAjaxRunning = false;
1274
+
aiomaticRmLoading(btn);
1275
+
alert('Error in processing finetune file: ' + error);
1276
+
}
1277
+
});
1278
+
}
1279
+
});
1280
+
var aiomaticAjaxRunning = false;
1281
+
$('.aiomatic_modal_close').on('click', function (){
1282
+
$('.aiomatic_modal_close').closest('.aiomatic_modal').hide();
1283
+
$('.aiomatic-overlay').hide();
1284
+
})
1285
+
function aiomaticLoading(btn){
1286
+
btn.attr('disabled','disabled');
1287
+
if(btn.find('.spinner').length === 0){
1288
+
btn.append('<span class="aiomatic-spinner spinner"></span>');
1289
+
}
1290
+
btn.find('.spinner').css('visibility','unset');
1291
+
}
1292
+
function aiomaticRmLoading(btn){
1293
+
btn.removeAttr('disabled');
1294
+
btn.find('.spinner').remove();
1295
+
}
1296
+
var aiomatic_get_other = $('.aiomatic_get_other');
1297
+
var aiomatic_get_finetune = $('.aiomatic_get_finetune');
1298
+
var aiomatic_cancel_finetune = $('.aiomatic_cancel_finetune');
1299
+
var aiomatic_delete_finetune = $('.aiomatic_delete_finetune');
1300
+
aiomatic_cancel_finetune.on('click', function (){
1301
+
var conf = confirm('Are you sure?');
1302
+
if(conf) {
1303
+
var btn = $(this);
1304
+
var id = btn.attr('data-id');
1305
+
if (!aiomaticAjaxRunning) {
1306
+
aiomaticAjaxRunning = true;
1307
+
$.ajax({
1308
+
url: aiomatic_ajax_url,
1309
+
data: {action: 'aiomatic_cancel_finetune', id: id, nonce: aiomatic_object.nonce},
1310
+
dataType: 'JSON',
1311
+
type: 'POST',
1312
+
beforeSend: function () {
1313
+
aiomaticLoading(btn);
1314
+
},
1315
+
success: function (res) {
1316
+
aiomaticRmLoading(btn);
1317
+
aiomaticAjaxRunning = false;
1318
+
if (res.status === 'success') {
1319
+
window.location.reload();
1320
+
} else {
1321
+
alert(res.msg);
1322
+
}
1323
+
},
1324
+
error: function (r, s, error) {
1325
+
aiomaticRmLoading(btn);
1326
+
aiomaticAjaxRunning = false;
1327
+
alert('Error in processing finetune cancelling: ' + error);
1328
+
}
1329
+
});
1330
+
}
1331
+
}
1332
+
});
1333
+
aiomatic_delete_finetune.on('click', function (){
1334
+
var conf = confirm('Are you sure?');
1335
+
if(conf) {
1336
+
var btn = $(this);
1337
+
var id = btn.attr('data-id');
1338
+
if (!aiomaticAjaxRunning) {
1339
+
aiomaticAjaxRunning = true;
1340
+
$.ajax({
1341
+
url: aiomatic_ajax_url,
1342
+
data: {action: 'aiomatic_delete_finetune', id: id, nonce: aiomatic_object.nonce},
1343
+
dataType: 'JSON',
1344
+
type: 'POST',
1345
+
beforeSend: function () {
1346
+
aiomaticLoading(btn);
1347
+
},
1348
+
success: function (res) {
1349
+
aiomaticRmLoading(btn);
1350
+
aiomaticAjaxRunning = false;
1351
+
if (res.status === 'success') {
1352
+
window.location.reload();
1353
+
} else {
1354
+
alert(res.msg);
1355
+
}
1356
+
},
1357
+
error: function (r, s, error) {
1358
+
aiomaticRmLoading(btn);
1359
+
aiomaticAjaxRunning = false;
1360
+
alert('Error in processing finetune deletion: ' + error);
1361
+
}
1362
+
});
1363
+
}
1364
+
}
1365
+
});
1366
+
aiomatic_get_other.on('click', function (){
1367
+
var btn = $(this);
1368
+
var id = btn.attr('data-id');
1369
+
var type = btn.attr('data-type');
1370
+
var aiomaticTitle = btn.text().trim();
1371
+
if(!aiomaticAjaxRunning){
1372
+
aiomaticAjaxRunning = true;
1373
+
$.ajax({
1374
+
url: aiomatic_ajax_url,
1375
+
data: {action: 'aiomatic_other_finetune', id: id, type: type, nonce: aiomatic_object.nonce},
1376
+
dataType: 'JSON',
1377
+
type: 'POST',
1378
+
beforeSend: function (){
1379
+
aiomaticLoading(btn);
1380
+
},
1381
+
success: function (res){
1382
+
aiomaticRmLoading(btn);
1383
+
aiomaticAjaxRunning = false;
1384
+
if(res.status === 'success'){
1385
+
$('.aiomatic_modal_title').html(aiomaticTitle);
1386
+
$('.aiomatic_modal_content').html(res.html);
1387
+
$('.aiomatic-overlay').show();
1388
+
$('.aiomatic_modal').show();
1389
+
}
1390
+
else{
1391
+
alert(res.msg);
1392
+
}
1393
+
},
1394
+
error: function (r, s, error){
1395
+
aiomaticRmLoading(btn);
1396
+
aiomaticAjaxRunning = false;
1397
+
alert('Error in processing finetune switching: ' + error);
1398
+
}
1399
+
});
1400
+
}
1401
+
});
1402
+
$('.aiomatic_sync_finetunes').on('click', function (){
1403
+
var btn = $(this);
1404
+
$.ajax({
1405
+
url: aiomatic_ajax_url,
1406
+
data: {action: 'aiomatic_fetch_finetunes', nonce: aiomatic_object.nonce},
1407
+
dataType: 'JSON',
1408
+
type: 'POST',
1409
+
beforeSend: function (){
1410
+
aiomaticLoading(btn);
1411
+
},
1412
+
success: function (res){
1413
+
aiomaticRmLoading(btn);
1414
+
if(res.status === 'success'){
1415
+
window.location.reload();
1416
+
}
1417
+
else{
1418
+
alert(res.msg);
1419
+
}
1420
+
},
1421
+
error: function (r, s, error){
1422
+
aiomaticRmLoading(btn);
1423
+
alert('Error in processing finetune fetching: ' + error);
1424
+
}
1425
+
});
1426
+
})
1427
+
});