mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
New toggle features: Auto-Connect & Auto-Load-Chat
1. new function - Auto-connect to API 2. new function - Auto-load last character/chat Both of these have toggles in the right menu at the bottom in a "Power user options" section. Both only load if settings.json has a pre-defined setting for them. (won't fire on first load after install)
This commit is contained in:
Binary file not shown.
Before Width: | Height: | Size: 2.9 KiB |
@ -81,6 +81,7 @@
|
|||||||
var generatedPromtCache = '';
|
var generatedPromtCache = '';
|
||||||
var characters = [];
|
var characters = [];
|
||||||
var this_chid;
|
var this_chid;
|
||||||
|
var active_character;
|
||||||
var backgrounds = [];
|
var backgrounds = [];
|
||||||
var default_avatar = 'img/fluffy.png';
|
var default_avatar = 'img/fluffy.png';
|
||||||
var is_colab = false;
|
var is_colab = false;
|
||||||
@ -150,6 +151,8 @@
|
|||||||
var anchor_order = 0;
|
var anchor_order = 0;
|
||||||
var style_anchor = true;
|
var style_anchor = true;
|
||||||
var character_anchor = true;
|
var character_anchor = true;
|
||||||
|
var auto_connect = false;
|
||||||
|
var auto_load_chat = false;
|
||||||
|
|
||||||
var main_api = 'kobold';
|
var main_api = 'kobold';
|
||||||
//novel settings
|
//novel settings
|
||||||
@ -201,18 +204,20 @@
|
|||||||
$.get("/csrf-token")
|
$.get("/csrf-token")
|
||||||
.then(data => {
|
.then(data => {
|
||||||
token = data.token;
|
token = data.token;
|
||||||
|
getCharacters();
|
||||||
getSettings("def");
|
getSettings("def");
|
||||||
getLastVersion();
|
getLastVersion();
|
||||||
getCharacters();
|
//getCharacters();
|
||||||
|
|
||||||
printMessages();
|
printMessages();
|
||||||
getBackgrounds();
|
getBackgrounds();
|
||||||
getUserAvatars();
|
getUserAvatars();
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
$('#characloud_url').click(function(){
|
$('#characloud_url').click(function(){
|
||||||
window.open('https://boosty.to/tavernai', '_blank');
|
window.open('https://boosty.to/tavernai', '_blank');
|
||||||
});
|
});
|
||||||
function checkOnlineStatus(){
|
function checkOnlineStatus(){
|
||||||
//console.log(online_status);
|
//console.log(online_status);
|
||||||
if(online_status == 'no_connection'){
|
if(online_status == 'no_connection'){
|
||||||
@ -341,7 +346,7 @@
|
|||||||
this_avatar = "characters/"+item.avatar+"#"+Date.now();
|
this_avatar = "characters/"+item.avatar+"#"+Date.now();
|
||||||
|
|
||||||
}
|
}
|
||||||
$("#rm_print_characters_block").prepend('<div class=character_select chid='+i+'><div class=avatar><img src="'+this_avatar+'"></div><div class=ch_name>'+item.name+'</div></div>');
|
$("#rm_print_characters_block").prepend('<div class=character_select chid='+i+' id="CharID'+i+'"><div class=avatar><img src="'+this_avatar+'"></div><div class=ch_name>'+item.name+'</div></div>');
|
||||||
//console.log(item.name);
|
//console.log(item.name);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -1099,7 +1104,7 @@
|
|||||||
addOneMessage(chat[chat.length-1]);
|
addOneMessage(chat[chat.length-1]);
|
||||||
$( "#send_but" ).css("display", "inline");
|
$( "#send_but" ).css("display", "inline");
|
||||||
$( "#loading_mes" ).css("display", "none");
|
$( "#loading_mes" ).css("display", "none");
|
||||||
console.log('/savechat called by /Generate');
|
//console.log('/savechat called by /Generate');
|
||||||
saveChat();
|
saveChat();
|
||||||
}else{
|
}else{
|
||||||
//console.log('run force_name2 protocol');
|
//console.log('run force_name2 protocol');
|
||||||
@ -1161,7 +1166,7 @@ console.log('/savechat called by /Generate');
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
async function getChat() {
|
async function getChat() {
|
||||||
console.log('/getChat entered');
|
//console.log('/getChat entered');
|
||||||
//console.log(characters[this_chid].chat);
|
//console.log(characters[this_chid].chat);
|
||||||
jQuery.ajax({
|
jQuery.ajax({
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
@ -1182,16 +1187,16 @@ console.log('/getChat entered');
|
|||||||
}
|
}
|
||||||
//chat = data;
|
//chat = data;
|
||||||
chat_create_date = chat[0]['create_date'];
|
chat_create_date = chat[0]['create_date'];
|
||||||
console.log('/getchat saw chat_create_date: '+chat_create_date);
|
//console.log('/getchat saw chat_create_date: '+chat_create_date);
|
||||||
chat.shift();
|
chat.shift();
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
chat_create_date = humanizedISO8601DateTime();
|
chat_create_date = humanizedISO8601DateTime();
|
||||||
}
|
}
|
||||||
//console.log(chat);
|
//console.log(chat);
|
||||||
console.log('getChatResults called by /getchat');
|
//console.log('getChatResults called by /getchat');
|
||||||
getChatResult();
|
getChatResult();
|
||||||
console.log('savechat called by /getchat');
|
//console.log('savechat called by /getchat');
|
||||||
saveChat();
|
saveChat();
|
||||||
},
|
},
|
||||||
error: function (jqXHR, exception) {
|
error: function (jqXHR, exception) {
|
||||||
@ -1388,12 +1393,13 @@ console.log('savechat called by /getchat');
|
|||||||
}
|
}
|
||||||
|
|
||||||
function select_selected_character(chid){ //character select
|
function select_selected_character(chid){ //character select
|
||||||
|
//console.log('select_selected_character() -- starting with input of -- '+chid+' (name:'+characters[chid].name+')');
|
||||||
select_rm_create();
|
select_rm_create();
|
||||||
menu_type = 'character_edit';
|
menu_type = 'character_edit';
|
||||||
$( "#delete_button_div" ).css("display", "block");
|
$( "#delete_button_div" ).css("display", "block");
|
||||||
$( "#rm_button_selected_ch" ).css("class","selected-right-tab");
|
$( "#rm_button_selected_ch" ).css("class","selected-right-tab");
|
||||||
var display_name = characters[chid].name;
|
var display_name = characters[chid].name;
|
||||||
|
|
||||||
|
|
||||||
$( "#rm_button_selected_ch" ).children("h2").text(display_name);
|
$( "#rm_button_selected_ch" ).children("h2").text(display_name);
|
||||||
|
|
||||||
@ -1432,6 +1438,10 @@ console.log('savechat called by /getchat');
|
|||||||
$("#name_div").css("display", "none");
|
$("#name_div").css("display", "none");
|
||||||
|
|
||||||
$("#form_create").attr("actiontype", "editcharacter");
|
$("#form_create").attr("actiontype", "editcharacter");
|
||||||
|
active_character = chid;
|
||||||
|
//console.log('select_selected_character() -- active_character -- '+chid+'(ChID of '+display_name+')');
|
||||||
|
saveSettings();
|
||||||
|
//console.log('select_selected_character() -- called saveSettings() to save -- active_character -- '+active_character+'(ChID of '+display_name+')');
|
||||||
}
|
}
|
||||||
$(document).on('click', '.character_select', function(){
|
$(document).on('click', '.character_select', function(){
|
||||||
if(this_chid !== $(this).attr("chid")){
|
if(this_chid !== $(this).attr("chid")){
|
||||||
@ -1441,8 +1451,7 @@ console.log('savechat called by /getchat');
|
|||||||
this_chid = $(this).attr("chid");
|
this_chid = $(this).attr("chid");
|
||||||
clearChat();
|
clearChat();
|
||||||
chat.length = 0;
|
chat.length = 0;
|
||||||
getChat();
|
getChat();
|
||||||
|
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
selected_button = 'character_edit';
|
selected_button = 'character_edit';
|
||||||
@ -1728,8 +1737,7 @@ console.log('savechat called by /getchat');
|
|||||||
if($("#form_create").attr("actiontype") == "createcharacter"){
|
if($("#form_create").attr("actiontype") == "createcharacter"){
|
||||||
|
|
||||||
if($("#character_name_pole").val().length > 0){
|
if($("#character_name_pole").val().length > 0){
|
||||||
console.log('/createcharacter entered');
|
//console.log('/createcharacter entered');
|
||||||
console.log('CharCreate formData: '+formData);
|
|
||||||
jQuery.ajax({
|
jQuery.ajax({
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
url: '/createcharacter',
|
url: '/createcharacter',
|
||||||
@ -1772,7 +1780,7 @@ console.log('CharCreate formData: '+formData);
|
|||||||
select_rm_info("Character created");
|
select_rm_info("Character created");
|
||||||
|
|
||||||
$('#rm_info_block').transition({ opacity: 1.0 ,duration: 2000});
|
$('#rm_info_block').transition({ opacity: 1.0 ,duration: 2000});
|
||||||
console.log('/getcharacters called after /createchracter');
|
//console.log('/getcharacters called after /createchracter');
|
||||||
getCharacters();
|
getCharacters();
|
||||||
}else{
|
}else{
|
||||||
$('#result_info').html(html);
|
$('#result_info').html(html);
|
||||||
@ -1786,7 +1794,7 @@ console.log('/getcharacters called after /createchracter');
|
|||||||
$('#result_info').html("Name not entered");
|
$('#result_info').html("Name not entered");
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
console.log('Avatar Button Value:'+$("#add_avatar_button").val());
|
//console.log('Avatar Button Value:'+$("#add_avatar_button").val());
|
||||||
|
|
||||||
jQuery.ajax({
|
jQuery.ajax({
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
@ -2191,6 +2199,16 @@ console.log('Avatar Button Value:'+$("#add_avatar_button").val());
|
|||||||
character_anchor = !!$('#character_anchor').prop('checked');
|
character_anchor = !!$('#character_anchor').prop('checked');
|
||||||
saveSettings();
|
saveSettings();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('#auto-connect-checkbox').change(function() {
|
||||||
|
auto_connect = !!$('#auto-connect-checkbox').prop('checked');
|
||||||
|
saveSettings();
|
||||||
|
});
|
||||||
|
$('#auto-load-chat-checkbox').change(function() {
|
||||||
|
auto_load_chat = !!$('#auto-load-chat-checkbox').prop('checked');
|
||||||
|
saveSettings();
|
||||||
|
});
|
||||||
|
|
||||||
$(document).on('input', '#rep_pen', function() {
|
$(document).on('input', '#rep_pen', function() {
|
||||||
rep_pen = $(this).val();
|
rep_pen = $(this).val();
|
||||||
if(isInt(rep_pen)){
|
if(isInt(rep_pen)){
|
||||||
@ -2235,7 +2253,7 @@ console.log('Avatar Button Value:'+$("#add_avatar_button").val());
|
|||||||
///////////////////////////////////////////
|
///////////////////////////////////////////
|
||||||
async function getSettings(type){//timer
|
async function getSettings(type){//timer
|
||||||
|
|
||||||
|
//console.log('getSettings() pinging server for settings request');
|
||||||
jQuery.ajax({
|
jQuery.ajax({
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
url: '/getsettings',
|
url: '/getsettings',
|
||||||
@ -2249,33 +2267,36 @@ console.log('Avatar Button Value:'+$("#add_avatar_button").val());
|
|||||||
contentType: "application/json",
|
contentType: "application/json",
|
||||||
//processData: false,
|
//processData: false,
|
||||||
success: function(data){
|
success: function(data){
|
||||||
|
// console.log('processing loaded settings');
|
||||||
if(data.result != 'file not find'){
|
if(data.result != 'file not find'){
|
||||||
|
// console.log('getSettings() -- settings file found');
|
||||||
settings = JSON.parse(data.settings);
|
settings = JSON.parse(data.settings);
|
||||||
if(settings.username !== undefined){
|
if(settings.username !== undefined){
|
||||||
|
// console.log('getSettings() -- Username -- '+settings.username);
|
||||||
if(settings.username !== ''){
|
if(settings.username !== ''){
|
||||||
name1 = settings.username;
|
name1 = settings.username;
|
||||||
$('#your_name').val(name1);
|
$('#your_name').val(name1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Load which API we are using
|
||||||
//Novel
|
|
||||||
if(settings.main_api != undefined){
|
if(settings.main_api != undefined){
|
||||||
main_api = settings.main_api;
|
main_api = settings.main_api;
|
||||||
$("#main_api option[value="+main_api+"]").attr('selected', 'true');
|
$("#main_api option[value="+main_api+"]").attr('selected', 'true');
|
||||||
changeMainAPI();
|
changeMainAPI();
|
||||||
}
|
}
|
||||||
|
//load Novel API KEY is exists
|
||||||
if(settings.api_key_novel != undefined){
|
if(settings.api_key_novel != undefined){
|
||||||
api_key_novel = settings.api_key_novel;
|
api_key_novel = settings.api_key_novel;
|
||||||
$("#api_key_novel").val(api_key_novel);
|
$("#api_key_novel").val(api_key_novel);
|
||||||
}
|
}
|
||||||
|
//load the rest of the Novel settings without any checks
|
||||||
model_novel = settings.model_novel;
|
model_novel = settings.model_novel;
|
||||||
$("#model_novel_select option[value="+model_novel+"]").attr('selected', 'true');
|
$("#model_novel_select option[value="+model_novel+"]").attr('selected', 'true');
|
||||||
|
|
||||||
novelai_setting_names = data.novelai_setting_names;
|
novelai_setting_names = data.novelai_setting_names;
|
||||||
novelai_settings = data.novelai_settings;
|
novelai_settings = data.novelai_settings;
|
||||||
novelai_settings.forEach(function(item, i, arr) {
|
novelai_settings.forEach(function(item, i, arr) {
|
||||||
|
|
||||||
novelai_settings[i] = JSON.parse(item);
|
novelai_settings[i] = JSON.parse(item);
|
||||||
});
|
});
|
||||||
var arr_holder = {};
|
var arr_holder = {};
|
||||||
@ -2290,7 +2311,8 @@ console.log('Avatar Button Value:'+$("#add_avatar_button").val());
|
|||||||
|
|
||||||
preset_settings_novel = settings.preset_settings_novel;
|
preset_settings_novel = settings.preset_settings_novel;
|
||||||
$("#settings_perset_novel option[value="+novelai_setting_names[preset_settings_novel]+"]").attr('selected', 'true');
|
$("#settings_perset_novel option[value="+novelai_setting_names[preset_settings_novel]+"]").attr('selected', 'true');
|
||||||
//Kobold
|
|
||||||
|
//Load KoboldAI settings
|
||||||
koboldai_setting_names = data.koboldai_setting_names;
|
koboldai_setting_names = data.koboldai_setting_names;
|
||||||
koboldai_settings = data.koboldai_settings;
|
koboldai_settings = data.koboldai_settings;
|
||||||
koboldai_settings.forEach(function(item, i, arr) {
|
koboldai_settings.forEach(function(item, i, arr) {
|
||||||
@ -2307,13 +2329,19 @@ console.log('Avatar Button Value:'+$("#add_avatar_button").val());
|
|||||||
koboldai_setting_names = arr_holder;
|
koboldai_setting_names = arr_holder;
|
||||||
|
|
||||||
preset_settings = settings.preset_settings;
|
preset_settings = settings.preset_settings;
|
||||||
|
|
||||||
|
//Load AI model config settings (temp, context length, anchors, and anchor order)
|
||||||
temp = settings.temp;
|
temp = settings.temp;
|
||||||
amount_gen = settings.amount_gen;
|
amount_gen = settings.amount_gen;
|
||||||
if(settings.max_context !== undefined) max_context = parseInt(settings.max_context);
|
if(settings.max_context !== undefined) max_context = parseInt(settings.max_context);
|
||||||
if(settings.anchor_order !== undefined) anchor_order = parseInt(settings.anchor_order);
|
if(settings.anchor_order !== undefined) anchor_order = parseInt(settings.anchor_order);
|
||||||
if(settings.style_anchor !== undefined) style_anchor = !!settings.style_anchor;
|
if(settings.style_anchor !== undefined) style_anchor = !!settings.style_anchor;
|
||||||
if(settings.character_anchor !== undefined) character_anchor = !!settings.character_anchor;
|
if(settings.character_anchor !== undefined) character_anchor = !!settings.character_anchor;
|
||||||
|
|
||||||
|
//load poweruser options
|
||||||
|
if(settings.auto_connect !== undefined) auto_connect = !!settings.auto_connect;
|
||||||
|
if(settings.auto_load_chat !== undefined) auto_load_chat = !!settings.auto_load_chat;
|
||||||
|
|
||||||
rep_pen = settings.rep_pen;
|
rep_pen = settings.rep_pen;
|
||||||
rep_pen_size = settings.rep_pen_size;
|
rep_pen_size = settings.rep_pen_size;
|
||||||
|
|
||||||
@ -2327,6 +2355,9 @@ console.log('Avatar Button Value:'+$("#add_avatar_button").val());
|
|||||||
$('#character_anchor').prop('checked', character_anchor);
|
$('#character_anchor').prop('checked', character_anchor);
|
||||||
$("#anchor_order option[value="+anchor_order+"]").attr('selected', 'true');
|
$("#anchor_order option[value="+anchor_order+"]").attr('selected', 'true');
|
||||||
|
|
||||||
|
$('#auto-connect-checkbox').prop('checked', auto_connect);
|
||||||
|
$('#auto-load-chat-checkbox').prop('checked', auto_load_chat);
|
||||||
|
|
||||||
$('#max_context').val(max_context);
|
$('#max_context').val(max_context);
|
||||||
$('#max_context_counter').html(max_context+' Tokens');
|
$('#max_context_counter').html(max_context+' Tokens');
|
||||||
|
|
||||||
@ -2360,7 +2391,7 @@ console.log('Avatar Button Value:'+$("#add_avatar_button").val());
|
|||||||
$('#rep_pen_size_novel').val(rep_pen_size_novel);
|
$('#rep_pen_size_novel').val(rep_pen_size_novel);
|
||||||
$('#rep_pen_size_counter_novel').html(rep_pen_size_novel+" Tokens");
|
$('#rep_pen_size_counter_novel').html(rep_pen_size_novel+" Tokens");
|
||||||
|
|
||||||
//////////////////////
|
//Enable GUI deference settings if GUI is selected for Kobold
|
||||||
if(preset_settings == 'gui'){
|
if(preset_settings == 'gui'){
|
||||||
$("#settings_perset option[value=gui]").attr('selected', 'true');
|
$("#settings_perset option[value=gui]").attr('selected', 'true');
|
||||||
$("#range_block").children().prop("disabled", true);
|
$("#range_block").children().prop("disabled", true);
|
||||||
@ -2384,17 +2415,36 @@ console.log('Avatar Button Value:'+$("#add_avatar_button").val());
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//User
|
//Load User's Name and Avatar
|
||||||
user_avatar = settings.user_avatar;
|
user_avatar = settings.user_avatar;
|
||||||
$('.mes').each(function(){
|
$('.mes').each(function(){
|
||||||
if($(this).attr('ch_name') == name1){
|
if($(this).attr('ch_name') == name1){
|
||||||
$(this).children('.avatar').children('img').attr('src', 'User Avatars/'+user_avatar);
|
$(this).children('.avatar').children('img').attr('src', 'User Avatars/'+user_avatar);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//Load the API server URL from settings
|
||||||
api_server = settings.api_server;
|
api_server = settings.api_server;
|
||||||
$('#api_url_text').val(api_server);
|
$('#api_url_text').val(api_server);
|
||||||
|
|
||||||
|
//RossAscends: auto-connect to last API function (fires when API URL exists in settings and auto_connect is true)
|
||||||
|
if(api_server !== ''&& auto_connect == true){
|
||||||
|
$('#api_button').click();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//RossAscends: auto-load last character function (fires when active_character is defined and auto_load_chat is true)
|
||||||
|
if(settings.active_character !== undefined){
|
||||||
|
//console.log('getSettings() -- active_character -- '+settings.active_character);
|
||||||
|
if(settings.active_character !== ''){
|
||||||
|
active_character = settings.active_character;
|
||||||
|
//console.log('getSettings() -- auto_load_chat -- '+auto_load_chat);
|
||||||
|
if (auto_load_chat == true){
|
||||||
|
//console.log('getSettings() - trying to click .character_select div with ID #CharID'+active_character);
|
||||||
|
$('#CharID'+active_character).click(); //will auto-select and load chat of last selected character is auto_load_chat is true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if(!is_checked_colab) isColab();
|
if(!is_checked_colab) isColab();
|
||||||
|
|
||||||
},
|
},
|
||||||
@ -2408,7 +2458,7 @@ console.log('Avatar Button Value:'+$("#add_avatar_button").val());
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function saveSettings(type){
|
async function saveSettings(type){
|
||||||
|
//console.log('saveSettings() -- pinging server to save settings.');
|
||||||
jQuery.ajax({
|
jQuery.ajax({
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
url: '/savesettings',
|
url: '/savesettings',
|
||||||
@ -2424,6 +2474,8 @@ console.log('Avatar Button Value:'+$("#add_avatar_button").val());
|
|||||||
anchor_order: anchor_order,
|
anchor_order: anchor_order,
|
||||||
style_anchor: style_anchor,
|
style_anchor: style_anchor,
|
||||||
character_anchor: character_anchor,
|
character_anchor: character_anchor,
|
||||||
|
auto_connect: auto_connect,
|
||||||
|
auto_load_chat: auto_load_chat,
|
||||||
main_api: main_api,
|
main_api: main_api,
|
||||||
api_key_novel: api_key_novel,
|
api_key_novel: api_key_novel,
|
||||||
rep_pen: rep_pen,
|
rep_pen: rep_pen,
|
||||||
@ -2431,10 +2483,11 @@ console.log('Avatar Button Value:'+$("#add_avatar_button").val());
|
|||||||
model_novel: model_novel,
|
model_novel: model_novel,
|
||||||
temp_novel: temp_novel,
|
temp_novel: temp_novel,
|
||||||
rep_pen_novel: rep_pen_novel,
|
rep_pen_novel: rep_pen_novel,
|
||||||
rep_pen_size_novel: rep_pen_size_novel
|
rep_pen_size_novel: rep_pen_size_novel,
|
||||||
|
active_character: active_character
|
||||||
}),
|
}),
|
||||||
beforeSend: function(){
|
beforeSend: function(){
|
||||||
|
//console.log('saveSettings() -- active_character -- '+active_character);
|
||||||
|
|
||||||
},
|
},
|
||||||
cache: false,
|
cache: false,
|
||||||
@ -2578,14 +2631,14 @@ console.log('Avatar Button Value:'+$("#add_avatar_button").val());
|
|||||||
if(!is_send_press){
|
if(!is_send_press){
|
||||||
name1 = $("#your_name").val();
|
name1 = $("#your_name").val();
|
||||||
if(name1 === undefined || name1 == '') name1 = default_user_name;
|
if(name1 === undefined || name1 == '') name1 = default_user_name;
|
||||||
console.log(name1);
|
//console.log(name1);
|
||||||
saveSettings('change_name');
|
saveSettings('change_name');
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
//Select chat
|
//Select chat
|
||||||
async function getAllCharaChats() {
|
async function getAllCharaChats() {
|
||||||
console.log('entered getAllCharaChats');
|
//console.log('getAllCharaChats() pinging server for character chat history.');
|
||||||
$('#select_chat_div').html('');
|
$('#select_chat_div').html('');
|
||||||
//console.log(characters[this_chid].chat);
|
//console.log(characters[this_chid].chat);
|
||||||
jQuery.ajax({
|
jQuery.ajax({
|
||||||
@ -2601,12 +2654,11 @@ console.log('Avatar Button Value:'+$("#add_avatar_button").val());
|
|||||||
success: function(data){
|
success: function(data){
|
||||||
$('#load_select_chat_div').css('display', 'none');
|
$('#load_select_chat_div').css('display', 'none');
|
||||||
let dataArr = Object.values(data);
|
let dataArr = Object.values(data);
|
||||||
console.log('dataArr = '+ Object.values(data));
|
|
||||||
data = dataArr.sort((a, b) => a['file_name'].localeCompare(b['file_name']));
|
data = dataArr.sort((a, b) => a['file_name'].localeCompare(b['file_name']));
|
||||||
data = data.reverse();
|
data = data.reverse();
|
||||||
|
|
||||||
for (const key in data) {
|
for (const key in data) {
|
||||||
let strlen = 40;
|
let strlen = 300;
|
||||||
let mes = data[key]['mes'];
|
let mes = data[key]['mes'];
|
||||||
if(mes !== undefined){
|
if(mes !== undefined){
|
||||||
if(mes.length > strlen){
|
if(mes.length > strlen){
|
||||||
@ -2628,11 +2680,11 @@ console.log('Avatar Button Value:'+$("#add_avatar_button").val());
|
|||||||
//chat = data;
|
//chat = data;
|
||||||
//getChatResult();
|
//getChatResult();
|
||||||
//saveChat();
|
//saveChat();
|
||||||
console.log('Finished getAllCharaChats successfully');
|
//console.log('getAllCharaChats() -- Finished successfully');
|
||||||
},
|
},
|
||||||
error: function (jqXHR, exception) {
|
error: function (jqXHR, exception) {
|
||||||
//getChatResult();
|
//getChatResult();
|
||||||
console.log('Failed to Finished getAllCharaChats');
|
//console.log('getAllCharaChats() -- Failed');
|
||||||
console.log(exception);
|
console.log(exception);
|
||||||
console.log(jqXHR);
|
console.log(jqXHR);
|
||||||
|
|
||||||
@ -2833,7 +2885,7 @@ console.log('Avatar Button Value:'+$("#add_avatar_button").val());
|
|||||||
$("#chat_import_file_type").val(format);
|
$("#chat_import_file_type").val(format);
|
||||||
//console.log(format);
|
//console.log(format);
|
||||||
var formData = new FormData($("#form_import_chat").get(0));
|
var formData = new FormData($("#form_import_chat").get(0));
|
||||||
console.log('/importchat entered with: '+formData);
|
//console.log('/importchat entered with: '+formData);
|
||||||
jQuery.ajax({
|
jQuery.ajax({
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
url: '/importchat',
|
url: '/importchat',
|
||||||
@ -3132,7 +3184,7 @@ console.log('/importchat entered with: '+formData);
|
|||||||
<input type="range" id="rep_pen_size_novel" name="volume" min="0" max="2048" step="1">
|
<input type="range" id="rep_pen_size_novel" name="volume" min="0" max="2048" step="1">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<hr style="margin-bottom: 5px;">
|
<hr>
|
||||||
|
|
||||||
<h4>Your Avatar</h4><h5></h5>
|
<h4>Your Avatar</h4><h5></h5>
|
||||||
<div id="user_avatar_block"></div>
|
<div id="user_avatar_block"></div>
|
||||||
@ -3143,17 +3195,23 @@ console.log('/importchat entered with: '+formData);
|
|||||||
<input id="your_name_button" type="submit" title="Click to set a new User Name (reloads page)" value="Change Name">
|
<input id="your_name_button" type="submit" title="Click to set a new User Name (reloads page)" value="Change Name">
|
||||||
</form>
|
</form>
|
||||||
<hr>
|
<hr>
|
||||||
<div style="opacity:0.80">
|
|
||||||
<h3 style='margin-bottom: 10px;'>Pro Settings</h3>
|
<div id="pro-settings-block">
|
||||||
|
<h3>Pro Settings</h3>
|
||||||
|
|
||||||
<div id="amount_gen_block">
|
<div id="amount_gen_block">
|
||||||
<h4>Amount generation </h4><h5 id="amount_gen_counter">select</h5>
|
<h4>Amount generation </h4>
|
||||||
<input type="range" id="amount_gen" name="volume" min="16" max="512" step="1">
|
<h5 id="amount_gen_counter">select</h5>
|
||||||
|
<input type="range" id="amount_gen" name="volume" min="16" max="512" step="1">
|
||||||
</div>
|
</div>
|
||||||
<div id="max_context_block">
|
<div id="max_context_block">
|
||||||
<h4>Context Size</h4><h5 id="max_context_counter">select</h5>
|
<h4>Context Size</h4>
|
||||||
|
<h5 id="max_context_counter">select</h5>
|
||||||
<input type="range" id="max_context" name="volume" min="512" max="2048" step="1">
|
<input type="range" id="max_context" name="volume" min="512" max="2048" step="1">
|
||||||
</div>
|
</div>
|
||||||
<h4>Anchors Order</h4><h5>Helps to increase the length of messages (<a href="/notes/9" target="_blank">?</a>)</h5>
|
|
||||||
|
<h4>Anchors Order</h4>
|
||||||
|
<h5>Helps to increase the length of messages (<a href="/notes/9" target="_blank">?</a>)</h5>
|
||||||
<select id="anchor_order">
|
<select id="anchor_order">
|
||||||
<option value="0">Character Anchor - Style Anchor</option>
|
<option value="0">Character Anchor - Style Anchor</option>
|
||||||
<option value="1">Style Anchor - Character Anchor</option>
|
<option value="1">Style Anchor - Character Anchor</option>
|
||||||
@ -3162,8 +3220,19 @@ console.log('/importchat entered with: '+formData);
|
|||||||
<input id="character_anchor" type="checkbox"/><h4>Character Anchor</h4>
|
<input id="character_anchor" type="checkbox"/><h4>Character Anchor</h4>
|
||||||
<input id="style_anchor" type="checkbox"/><h4>Style Anchor</h4>
|
<input id="style_anchor" type="checkbox"/><h4>Style Anchor</h4>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
<hr>
|
||||||
|
|
||||||
|
<div ="power-user-options-block">
|
||||||
|
<h3>Power User Options</h3>
|
||||||
|
<div id="power-user-option-checkboxes">
|
||||||
|
<input id="auto-connect-checkbox" type="checkbox"/><h4>Auto-connects Last Server</h4>
|
||||||
|
<input id="auto-load-chat-checkbox" type="checkbox"/><h4>Auto-load Last Chat</h4>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="rm_character_import" class="right_menu" style="display: none;">
|
<div id="rm_character_import" class="right_menu" style="display: none;">
|
||||||
<form id="form_import" action="javascript:void(null);" method="post" enctype="multipart/form-data">
|
<form id="form_import" action="javascript:void(null);" method="post" enctype="multipart/form-data">
|
||||||
<input type="file" id="character_import_file" accept=".json, image/png" name="avatar">
|
<input type="file" id="character_import_file" accept=".json, image/png" name="avatar">
|
||||||
|
@ -452,6 +452,7 @@ width: 100%;
|
|||||||
margin:0;
|
margin:0;
|
||||||
padding:0;
|
padding:0;
|
||||||
margin-left: 10px;
|
margin-left: 10px;
|
||||||
|
margin-bottom: 10px;
|
||||||
}
|
}
|
||||||
.right_menu h4 {
|
.right_menu h4 {
|
||||||
margin:0;
|
margin:0;
|
||||||
@ -1311,9 +1312,6 @@ input[type="range"] {
|
|||||||
background-size: 70% 100%;
|
background-size: 70% 100%;
|
||||||
background-repeat: no-repeat;
|
background-repeat: no-repeat;
|
||||||
}
|
}
|
||||||
#rm_api_block h4{
|
|
||||||
opacity: 0.85;
|
|
||||||
}
|
|
||||||
|
|
||||||
#right-nav-panel h5 a{
|
#right-nav-panel h5 a{
|
||||||
color: #936f4a;
|
color: #936f4a;
|
||||||
@ -1461,12 +1459,21 @@ label.checkbox :checked + span:after {
|
|||||||
background-color: rgba(0,0,0,0.5);
|
background-color: rgba(0,0,0,0.5);
|
||||||
}
|
}
|
||||||
#anchor_checkbox{
|
#anchor_checkbox{
|
||||||
margin-left: 10px;
|
margin-left: 10px;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
float: left;
|
text-align: left;
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-rows: 30px auto;
|
grid-template-rows: 30px auto;
|
||||||
grid-template-columns: auto auto;
|
grid-template-columns: 30px auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
#power-user-option-checkboxes {
|
||||||
|
margin-left: 10px;
|
||||||
|
align-items: center;
|
||||||
|
text-align: left;
|
||||||
|
display: grid;
|
||||||
|
grid-template-rows: 30px auto;
|
||||||
|
grid-template-columns: 30px auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
#shadow_character_popup{
|
#shadow_character_popup{
|
||||||
@ -1602,6 +1609,7 @@ label.checkbox :checked + span:after {
|
|||||||
box-shadow: 0 0 10px rgb(0 0 0 / 50%);
|
box-shadow: 0 0 10px rgb(0 0 0 / 50%);
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
/* padding-top: 50px; */
|
/* padding-top: 50px; */
|
||||||
|
|
||||||
background-color: rgba(0,0,0,0.7);
|
background-color: rgba(0,0,0,0.7);
|
||||||
border-radius: 20px;
|
border-radius: 20px;
|
||||||
overflow-y: scroll;
|
overflow-y: scroll;
|
||||||
|
26
server.js
26
server.js
@ -285,7 +285,7 @@ app.post("/generate", jsonParser, function(request, response_generate = response
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
app.post("/savechat", jsonParser, function(request, response){
|
app.post("/savechat", jsonParser, function(request, response){
|
||||||
console.log(humanizedISO8601DateTime()+':/savechat/ entered');
|
//console.log(humanizedISO8601DateTime()+':/savechat/ entered');
|
||||||
//console.log(request.data);
|
//console.log(request.data);
|
||||||
//console.log(request.body.bg);
|
//console.log(request.body.bg);
|
||||||
//const data = request.body;
|
//const data = request.body;
|
||||||
@ -293,10 +293,10 @@ console.log(humanizedISO8601DateTime()+':/savechat/ entered');
|
|||||||
//console.log(request.body.chat);
|
//console.log(request.body.chat);
|
||||||
//var bg = "body {background-image: linear-gradient(rgba(19,21,44,0.75), rgba(19,21,44,0.75)), url(../backgrounds/"+request.body.bg+");}";
|
//var bg = "body {background-image: linear-gradient(rgba(19,21,44,0.75), rgba(19,21,44,0.75)), url(../backgrounds/"+request.body.bg+");}";
|
||||||
var dir_name = String(request.body.avatar_url).replace('.png','');
|
var dir_name = String(request.body.avatar_url).replace('.png','');
|
||||||
console.log(humanizedISO8601DateTime()+':/savechat sees '+dir_name+' as the character name (derived from avatar PNG filename)');
|
//console.log(humanizedISO8601DateTime()+':/savechat sees '+dir_name+' as the character name (derived from avatar PNG filename)');
|
||||||
let chat_data = request.body.chat;
|
let chat_data = request.body.chat;
|
||||||
let jsonlData = chat_data.map(JSON.stringify).join('\n');
|
let jsonlData = chat_data.map(JSON.stringify).join('\n');
|
||||||
console.log(humanizedISO8601DateTime()+':/savechat saving a chat named '+request.body.file_name+'.jsonl');
|
//console.log(humanizedISO8601DateTime()+':/savechat saving a chat named '+request.body.file_name+'.jsonl');
|
||||||
fs.writeFile(chatsPath+dir_name+"/"+request.body.file_name+'.jsonl', jsonlData, 'utf8', function(err) {
|
fs.writeFile(chatsPath+dir_name+"/"+request.body.file_name+'.jsonl', jsonlData, 'utf8', function(err) {
|
||||||
if(err) {
|
if(err) {
|
||||||
response.send(err);
|
response.send(err);
|
||||||
@ -316,7 +316,7 @@ app.post("/getchat", jsonParser, function(request, response){
|
|||||||
//console.log(request);
|
//console.log(request);
|
||||||
//console.log(request.body.chat);
|
//console.log(request.body.chat);
|
||||||
//var bg = "body {background-image: linear-gradient(rgba(19,21,44,0.75), rgba(19,21,44,0.75)), url(../backgrounds/"+request.body.bg+");}";
|
//var bg = "body {background-image: linear-gradient(rgba(19,21,44,0.75), rgba(19,21,44,0.75)), url(../backgrounds/"+request.body.bg+");}";
|
||||||
console.log(humanizedISO8601DateTime()+':/getchat entered');
|
//console.log(humanizedISO8601DateTime()+':/getchat entered');
|
||||||
var dir_name = String(request.body.avatar_url).replace('.png','');
|
var dir_name = String(request.body.avatar_url).replace('.png','');
|
||||||
|
|
||||||
fs.stat(chatsPath+dir_name, function(err, stat) {
|
fs.stat(chatsPath+dir_name, function(err, stat) {
|
||||||
@ -333,7 +333,7 @@ console.log(humanizedISO8601DateTime()+':/getchat entered');
|
|||||||
fs.stat(chatsPath+dir_name+"/"+request.body.file_name+".jsonl", function(err, stat) {
|
fs.stat(chatsPath+dir_name+"/"+request.body.file_name+".jsonl", function(err, stat) {
|
||||||
|
|
||||||
if (err === null) { //if no error (the file exists), read the file
|
if (err === null) { //if no error (the file exists), read the file
|
||||||
console.log(humanizedISO8601DateTime()+':/getchat tries to access: '+chatsPath+dir_name+'/'+request.body.file_name+'.jsonl');
|
//console.log(humanizedISO8601DateTime()+':/getchat tries to access: '+chatsPath+dir_name+'/'+request.body.file_name+'.jsonl');
|
||||||
if(stat !== undefined){
|
if(stat !== undefined){
|
||||||
fs.readFile(chatsPath+dir_name+"/"+request.body.file_name+".jsonl", 'utf8', (err, data) => {
|
fs.readFile(chatsPath+dir_name+"/"+request.body.file_name+".jsonl", 'utf8', (err, data) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
@ -930,7 +930,7 @@ app.post("/getallchatsofcharacter", jsonParser, function(request, response){
|
|||||||
var chatData = {};
|
var chatData = {};
|
||||||
let ii = jsonFiles.length; //this is the number of files belonging to the character
|
let ii = jsonFiles.length; //this is the number of files belonging to the character
|
||||||
if (ii !== 0) {
|
if (ii !== 0) {
|
||||||
console.log('found '+ii+' chat logs to load');
|
//console.log('found '+ii+' chat logs to load');
|
||||||
for(let i = jsonFiles.length-1; i >= 0; i--){
|
for(let i = jsonFiles.length-1; i >= 0; i--){
|
||||||
const file = jsonFiles[i];
|
const file = jsonFiles[i];
|
||||||
const fileStream = fs.createReadStream(chatsPath+char_dir+'/'+file);
|
const fileStream = fs.createReadStream(chatsPath+char_dir+'/'+file);
|
||||||
@ -965,7 +965,7 @@ app.post("/getallchatsofcharacter", jsonParser, function(request, response){
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
}else{
|
}else{
|
||||||
console.log('Found No Chats. Exiting Load Routine.');
|
//console.log('Found No Chats. Exiting Load Routine.');
|
||||||
response.send({error: true});
|
response.send({error: true});
|
||||||
};
|
};
|
||||||
})});
|
})});
|
||||||
@ -1051,7 +1051,7 @@ app.post("/importcharacter", urlencodedParser, function(request, response){
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.post("/importchat", urlencodedParser, function(request, response){
|
app.post("/importchat", urlencodedParser, function(request, response){
|
||||||
console.log(humanizedISO8601DateTime()+':/importchat begun');
|
//console.log(humanizedISO8601DateTime()+':/importchat begun');
|
||||||
if(!request.body) return response.sendStatus(400);
|
if(!request.body) return response.sendStatus(400);
|
||||||
|
|
||||||
var format = request.body.file_type;
|
var format = request.body.file_type;
|
||||||
@ -1075,7 +1075,7 @@ console.log(humanizedISO8601DateTime()+':/importchat begun');
|
|||||||
const jsonData = JSON.parse(data);
|
const jsonData = JSON.parse(data);
|
||||||
var new_chat = [];
|
var new_chat = [];
|
||||||
if(jsonData.histories !== undefined){
|
if(jsonData.histories !== undefined){
|
||||||
console.log('/importchat confirms JSON histories are defined');
|
//console.log('/importchat confirms JSON histories are defined');
|
||||||
let i = 0;
|
let i = 0;
|
||||||
new_chat[i] = {};
|
new_chat[i] = {};
|
||||||
new_chat[0]['user_name'] = 'You';
|
new_chat[0]['user_name'] = 'You';
|
||||||
@ -1096,7 +1096,7 @@ console.log('/importchat confirms JSON histories are defined');
|
|||||||
i++;
|
i++;
|
||||||
});
|
});
|
||||||
const chatJsonlData = new_chat.map(JSON.stringify).join('\n');
|
const chatJsonlData = new_chat.map(JSON.stringify).join('\n');
|
||||||
console.log('/importchat saving a file: '+ch_name+' - '+humanizedISO8601DateTime()+' imported.jsonl');
|
//console.log('/importchat saving a file: '+ch_name+' - '+humanizedISO8601DateTime()+' imported.jsonl');
|
||||||
fs.writeFile(chatsPath+avatar_url+'/'+ch_name+' - '+humanizedISO8601DateTime()+' imported.jsonl', chatJsonlData, 'utf8', function(err) { //added ch_name and replaced Date.now() with humanizedISO8601DateTime
|
fs.writeFile(chatsPath+avatar_url+'/'+ch_name+' - '+humanizedISO8601DateTime()+' imported.jsonl', chatJsonlData, 'utf8', function(err) { //added ch_name and replaced Date.now() with humanizedISO8601DateTime
|
||||||
|
|
||||||
if(err) {
|
if(err) {
|
||||||
@ -1117,7 +1117,7 @@ console.log('/importchat saving a file: '+ch_name+' - '+humanizedISO8601DateTime
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
if(format === 'jsonl'){
|
if(format === 'jsonl'){
|
||||||
console.log(humanizedISO8601DateTime()+':imported chat format is JSONL');
|
//console.log(humanizedISO8601DateTime()+':imported chat format is JSONL');
|
||||||
const fileStream = fs.createReadStream('./uploads/'+filedata.filename);
|
const fileStream = fs.createReadStream('./uploads/'+filedata.filename);
|
||||||
const rl = readline.createInterface({
|
const rl = readline.createInterface({
|
||||||
input: fileStream,
|
input: fileStream,
|
||||||
@ -1128,7 +1128,7 @@ console.log(humanizedISO8601DateTime()+':imported chat format is JSONL');
|
|||||||
let jsonData = JSON.parse(line);
|
let jsonData = JSON.parse(line);
|
||||||
|
|
||||||
if(jsonData.user_name !== undefined){
|
if(jsonData.user_name !== undefined){
|
||||||
console.log(humanizedISO8601DateTime()+':/importchat copying chat as '+ch_name+' - '+humanizedISO8601DateTime()+'.jsonl');
|
//console.log(humanizedISO8601DateTime()+':/importchat copying chat as '+ch_name+' - '+humanizedISO8601DateTime()+'.jsonl');
|
||||||
fs.copyFile('./uploads/'+filedata.filename, chatsPath+avatar_url+'/'+ch_name+' - '+humanizedISO8601DateTime()+'.jsonl', (err) => { //added character name and replaced Date.now() with humanizedISO8601DateTime
|
fs.copyFile('./uploads/'+filedata.filename, chatsPath+avatar_url+'/'+ch_name+' - '+humanizedISO8601DateTime()+'.jsonl', (err) => { //added character name and replaced Date.now() with humanizedISO8601DateTime
|
||||||
if(err) {
|
if(err) {
|
||||||
response.send({error:true});
|
response.send({error:true});
|
||||||
@ -1273,7 +1273,7 @@ function convertStage2(){
|
|||||||
});
|
});
|
||||||
const jsonlData = new_chat_data.map(JSON.stringify).join('\n');
|
const jsonlData = new_chat_data.map(JSON.stringify).join('\n');
|
||||||
// Write the contents to the destination folder
|
// Write the contents to the destination folder
|
||||||
console.log('convertstage2 writing a file: '+chatsPath+char.name+'/' + file+'l');
|
//console.log('convertstage2 writing a file: '+chatsPath+char.name+'/' + file+'l');
|
||||||
fs.writeFileSync(chatsPath+char.name+'/' + file+'l', jsonlData);
|
fs.writeFileSync(chatsPath+char.name+'/' + file+'l', jsonlData);
|
||||||
});
|
});
|
||||||
//fs.rmSync('public/characters/'+directoriesB[key],{ recursive: true });
|
//fs.rmSync('public/characters/'+directoriesB[key],{ recursive: true });
|
||||||
|
Reference in New Issue
Block a user