mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Unconditional load of extensions. Fixes for translations
This commit is contained in:
355
public/script.js
355
public/script.js
@ -3575,29 +3575,21 @@ async function getChat() {
|
||||
} else {
|
||||
chat_create_date = humanizedDateTime();
|
||||
}
|
||||
getChatResult();
|
||||
saveChat();
|
||||
await getChatResult();
|
||||
await saveChat();
|
||||
setTimeout(function () {
|
||||
$('#send_textarea').click();
|
||||
$('#send_textarea').focus();
|
||||
}, 200);
|
||||
} catch (error) {
|
||||
getChatResult();
|
||||
await getChatResult();
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
|
||||
function getChatResult() {
|
||||
async function getChatResult() {
|
||||
name2 = characters[this_chid].name;
|
||||
if (chat.length > 1) {
|
||||
for (let i = 0; i < chat.length; i++) {
|
||||
const item = chat[i];
|
||||
if (item["is_user"]) {
|
||||
//item['mes'] = item['mes'].replace(default_user_name + ':', name1 + ':');
|
||||
//item['name'] = name1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (chat.length === 0) {
|
||||
const firstMes = characters[this_chid].first_mes || default_ch_mes;
|
||||
chat[0] = {
|
||||
name: name2,
|
||||
@ -3609,6 +3601,10 @@ function getChatResult() {
|
||||
}
|
||||
printMessages();
|
||||
select_selected_character(this_chid);
|
||||
|
||||
if (chat.length === 1) {
|
||||
await eventSource.emit(event_types.MESSAGE_RECEIVED, (chat.length - 1));
|
||||
}
|
||||
}
|
||||
|
||||
async function openCharacterChat(file_name) {
|
||||
@ -3806,178 +3802,166 @@ function reloadUserAvatar() {
|
||||
//***************SETTINGS****************//
|
||||
///////////////////////////////////////////
|
||||
async function getSettings(type) {
|
||||
//timer
|
||||
|
||||
//console.log('getSettings() pinging server for settings request');
|
||||
jQuery.ajax({
|
||||
type: "POST",
|
||||
url: "/getsettings",
|
||||
data: JSON.stringify({}),
|
||||
beforeSend: function () { },
|
||||
cache: false,
|
||||
dataType: "json",
|
||||
contentType: "application/json",
|
||||
//processData: false,
|
||||
success: function (data) {
|
||||
if (data.result != "file not find" && data.settings) {
|
||||
settings = JSON.parse(data.settings);
|
||||
if (settings.username !== undefined) {
|
||||
if (settings.username !== "") {
|
||||
name1 = settings.username;
|
||||
$("#your_name").val(name1);
|
||||
}
|
||||
}
|
||||
|
||||
//Load KoboldAI settings
|
||||
koboldai_setting_names = data.koboldai_setting_names;
|
||||
koboldai_settings = data.koboldai_settings;
|
||||
koboldai_settings.forEach(function (item, i, arr) {
|
||||
koboldai_settings[i] = JSON.parse(item);
|
||||
});
|
||||
|
||||
let arr_holder = {};
|
||||
|
||||
$("#settings_perset").empty(); //RossAscends: uncommented this to prevent settings selector from doubling preset list on refresh
|
||||
$("#settings_perset").append(
|
||||
'<option value="gui">GUI KoboldAI Settings</option>'
|
||||
); //adding in the GUI settings, since it is not loaded dynamically
|
||||
|
||||
koboldai_setting_names.forEach(function (item, i, arr) {
|
||||
arr_holder[item] = i;
|
||||
$("#settings_perset").append(`<option value=${i}>${item}</option>`);
|
||||
//console.log('loading preset #'+i+' -- '+item);
|
||||
});
|
||||
koboldai_setting_names = {};
|
||||
koboldai_setting_names = arr_holder;
|
||||
preset_settings = settings.preset_settings;
|
||||
|
||||
if (preset_settings == "gui") {
|
||||
selectKoboldGuiPreset();
|
||||
} else {
|
||||
if (typeof koboldai_setting_names[preset_settings] !== "undefined") {
|
||||
$(`#settings_perset option[value=${koboldai_setting_names[preset_settings]}]`)
|
||||
.attr("selected", "true");
|
||||
} else {
|
||||
preset_settings = "gui";
|
||||
selectKoboldGuiPreset();
|
||||
}
|
||||
}
|
||||
|
||||
novelai_setting_names = data.novelai_setting_names;
|
||||
novelai_settings = data.novelai_settings;
|
||||
novelai_settings.forEach(function (item, i, arr) {
|
||||
novelai_settings[i] = JSON.parse(item);
|
||||
});
|
||||
arr_holder = {};
|
||||
|
||||
$("#settings_perset_novel").empty();
|
||||
|
||||
novelai_setting_names.forEach(function (item, i, arr) {
|
||||
arr_holder[item] = i;
|
||||
$("#settings_perset_novel").append(`<option value=${i}>${item}</option>`);
|
||||
});
|
||||
novelai_setting_names = {};
|
||||
novelai_setting_names = arr_holder;
|
||||
|
||||
nai_settings.preset_settings_novel = settings.preset_settings_novel;
|
||||
$(
|
||||
`#settings_perset_novel option[value=${novelai_setting_names[nai_settings.preset_settings_novel]}]`
|
||||
).attr("selected", "true");
|
||||
|
||||
//Load AI model config settings
|
||||
|
||||
amount_gen = settings.amount_gen;
|
||||
if (settings.max_context !== undefined)
|
||||
max_context = parseInt(settings.max_context);
|
||||
|
||||
swipes = settings.swipes !== undefined ? !!settings.swipes : true; // enable swipes by default
|
||||
$('#swipes-checkbox').prop('checked', swipes); /// swipecode
|
||||
hideSwipeButtons();
|
||||
showSwipeButtons();
|
||||
|
||||
// Kobold
|
||||
loadKoboldSettings(settings);
|
||||
|
||||
// Novel
|
||||
loadNovelSettings(settings);
|
||||
|
||||
// TextGen
|
||||
loadTextGenSettings(data, settings);
|
||||
|
||||
// OpenAI
|
||||
loadOpenAISettings(data, settings);
|
||||
|
||||
// Horde
|
||||
loadHordeSettings(settings);
|
||||
|
||||
// Poe
|
||||
loadPoeSettings(settings);
|
||||
|
||||
// Load power user settings
|
||||
loadPowerUserSettings(settings, data);
|
||||
|
||||
// Load character tags
|
||||
loadTagsSettings(settings);
|
||||
|
||||
// Load context templates
|
||||
loadContextTemplatesFromSettings(data, settings);
|
||||
|
||||
// Set context size after loading power user (may override the max value)
|
||||
$("#max_context").val(max_context);
|
||||
$("#max_context_counter").text(`${max_context}`);
|
||||
|
||||
$("#amount_gen").val(amount_gen);
|
||||
$("#amount_gen_counter").text(`${amount_gen}`);
|
||||
|
||||
//Load which API we are using
|
||||
if (settings.main_api != undefined) {
|
||||
main_api = settings.main_api;
|
||||
$("#main_api option[value=" + main_api + "]").attr(
|
||||
"selected",
|
||||
"true"
|
||||
);
|
||||
changeMainAPI();
|
||||
}
|
||||
|
||||
//Load User's Name and Avatar
|
||||
|
||||
user_avatar = settings.user_avatar;
|
||||
reloadUserAvatar();
|
||||
highlightSelectedAvatar();
|
||||
|
||||
//Load the API server URL from settings
|
||||
api_server = settings.api_server;
|
||||
$("#api_url_text").val(api_server);
|
||||
|
||||
setWorldInfoSettings(settings, data);
|
||||
|
||||
if (data.enable_extensions) {
|
||||
const src = "scripts/extensions.js";
|
||||
if ($(`script[src="${src}"]`).length === 0) {
|
||||
const script = document.createElement("script");
|
||||
script.type = "module";
|
||||
script.src = src;
|
||||
$("body").append(script);
|
||||
}
|
||||
loadExtensionSettings(settings);
|
||||
}
|
||||
|
||||
api_server_textgenerationwebui =
|
||||
settings.api_server_textgenerationwebui;
|
||||
$("#textgenerationwebui_api_url_text").val(
|
||||
api_server_textgenerationwebui
|
||||
);
|
||||
|
||||
selected_button = settings.selected_button;
|
||||
}
|
||||
|
||||
if (!is_checked_colab) isColab();
|
||||
},
|
||||
error: function (jqXHR, exception) {
|
||||
console.log(exception);
|
||||
console.log(jqXHR);
|
||||
},
|
||||
const response = await fetch("/getsettings", {
|
||||
method: "POST",
|
||||
headers: getRequestHeaders(),
|
||||
body: JSON.stringify({}),
|
||||
cache: "no-cache",
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
toastr.error('Settings could not be loaded. Try reloading the page.');
|
||||
throw new Error('Error getting settings');
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (data.result != "file not find" && data.settings) {
|
||||
settings = JSON.parse(data.settings);
|
||||
if (settings.username !== undefined) {
|
||||
if (settings.username !== "") {
|
||||
name1 = settings.username;
|
||||
$("#your_name").val(name1);
|
||||
}
|
||||
}
|
||||
|
||||
//Load KoboldAI settings
|
||||
koboldai_setting_names = data.koboldai_setting_names;
|
||||
koboldai_settings = data.koboldai_settings;
|
||||
koboldai_settings.forEach(function (item, i, arr) {
|
||||
koboldai_settings[i] = JSON.parse(item);
|
||||
});
|
||||
|
||||
let arr_holder = {};
|
||||
|
||||
$("#settings_perset").empty(); //RossAscends: uncommented this to prevent settings selector from doubling preset list on refresh
|
||||
$("#settings_perset").append(
|
||||
'<option value="gui">GUI KoboldAI Settings</option>'
|
||||
); //adding in the GUI settings, since it is not loaded dynamically
|
||||
|
||||
koboldai_setting_names.forEach(function (item, i, arr) {
|
||||
arr_holder[item] = i;
|
||||
$("#settings_perset").append(`<option value=${i}>${item}</option>`);
|
||||
//console.log('loading preset #'+i+' -- '+item);
|
||||
});
|
||||
koboldai_setting_names = {};
|
||||
koboldai_setting_names = arr_holder;
|
||||
preset_settings = settings.preset_settings;
|
||||
|
||||
if (preset_settings == "gui") {
|
||||
selectKoboldGuiPreset();
|
||||
} else {
|
||||
if (typeof koboldai_setting_names[preset_settings] !== "undefined") {
|
||||
$(`#settings_perset option[value=${koboldai_setting_names[preset_settings]}]`)
|
||||
.attr("selected", "true");
|
||||
} else {
|
||||
preset_settings = "gui";
|
||||
selectKoboldGuiPreset();
|
||||
}
|
||||
}
|
||||
|
||||
novelai_setting_names = data.novelai_setting_names;
|
||||
novelai_settings = data.novelai_settings;
|
||||
novelai_settings.forEach(function (item, i, arr) {
|
||||
novelai_settings[i] = JSON.parse(item);
|
||||
});
|
||||
arr_holder = {};
|
||||
|
||||
$("#settings_perset_novel").empty();
|
||||
|
||||
novelai_setting_names.forEach(function (item, i, arr) {
|
||||
arr_holder[item] = i;
|
||||
$("#settings_perset_novel").append(`<option value=${i}>${item}</option>`);
|
||||
});
|
||||
novelai_setting_names = {};
|
||||
novelai_setting_names = arr_holder;
|
||||
|
||||
nai_settings.preset_settings_novel = settings.preset_settings_novel;
|
||||
$(
|
||||
`#settings_perset_novel option[value=${novelai_setting_names[nai_settings.preset_settings_novel]}]`
|
||||
).attr("selected", "true");
|
||||
|
||||
//Load AI model config settings
|
||||
|
||||
amount_gen = settings.amount_gen;
|
||||
if (settings.max_context !== undefined)
|
||||
max_context = parseInt(settings.max_context);
|
||||
|
||||
swipes = settings.swipes !== undefined ? !!settings.swipes : true; // enable swipes by default
|
||||
$('#swipes-checkbox').prop('checked', swipes); /// swipecode
|
||||
hideSwipeButtons();
|
||||
showSwipeButtons();
|
||||
|
||||
// Kobold
|
||||
loadKoboldSettings(settings);
|
||||
|
||||
// Novel
|
||||
loadNovelSettings(settings);
|
||||
|
||||
// TextGen
|
||||
loadTextGenSettings(data, settings);
|
||||
|
||||
// OpenAI
|
||||
loadOpenAISettings(data, settings);
|
||||
|
||||
// Horde
|
||||
loadHordeSettings(settings);
|
||||
|
||||
// Poe
|
||||
loadPoeSettings(settings);
|
||||
|
||||
// Load power user settings
|
||||
loadPowerUserSettings(settings, data);
|
||||
|
||||
// Load character tags
|
||||
loadTagsSettings(settings);
|
||||
|
||||
// Load context templates
|
||||
loadContextTemplatesFromSettings(data, settings);
|
||||
|
||||
// Set context size after loading power user (may override the max value)
|
||||
$("#max_context").val(max_context);
|
||||
$("#max_context_counter").text(`${max_context}`);
|
||||
|
||||
$("#amount_gen").val(amount_gen);
|
||||
$("#amount_gen_counter").text(`${amount_gen}`);
|
||||
|
||||
//Load which API we are using
|
||||
if (settings.main_api != undefined) {
|
||||
main_api = settings.main_api;
|
||||
$("#main_api option[value=" + main_api + "]").attr(
|
||||
"selected",
|
||||
"true"
|
||||
);
|
||||
changeMainAPI();
|
||||
}
|
||||
|
||||
//Load User's Name and Avatar
|
||||
|
||||
user_avatar = settings.user_avatar;
|
||||
reloadUserAvatar();
|
||||
highlightSelectedAvatar();
|
||||
|
||||
//Load the API server URL from settings
|
||||
api_server = settings.api_server;
|
||||
$("#api_url_text").val(api_server);
|
||||
|
||||
setWorldInfoSettings(settings, data);
|
||||
|
||||
api_server_textgenerationwebui =
|
||||
settings.api_server_textgenerationwebui;
|
||||
$("#textgenerationwebui_api_url_text").val(
|
||||
api_server_textgenerationwebui
|
||||
);
|
||||
|
||||
selected_button = settings.selected_button;
|
||||
|
||||
if (data.enable_extensions) {
|
||||
await loadExtensionSettings(settings);
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_checked_colab) isColab();
|
||||
}
|
||||
|
||||
function selectKoboldGuiPreset() {
|
||||
@ -4926,7 +4910,7 @@ const swipe_right = () => {
|
||||
chat[chat.length - 1]['swipe_id']++; //make new slot in array
|
||||
if (chat[chat.length - 1].extra) {
|
||||
// if message has memory attached - remove it to allow regen
|
||||
if ( chat[chat.length - 1].extra.memory) {
|
||||
if (chat[chat.length - 1].extra.memory) {
|
||||
delete chat[chat.length - 1].extra.memory;
|
||||
}
|
||||
// ditto for display text
|
||||
@ -5694,6 +5678,7 @@ $(document).ready(function () {
|
||||
add_mes_without_animation = true;
|
||||
//console.log('form create submission calling addOneMessage');
|
||||
addOneMessage(chat[0]);
|
||||
await eventSource.emit(event_types.MESSAGE_RECEIVED, (chat.length - 1));
|
||||
}
|
||||
}
|
||||
$("#create_button").removeAttr("disabled");
|
||||
|
Reference in New Issue
Block a user