Skip to content

Commit

Permalink
Fix horde for GUI preset mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Cohee1207 committed Apr 9, 2023
1 parent 64b1485 commit 66f7d55
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 41 deletions.
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ <h4 class="horde_model_title">
</div>
</h4>
<select id="horde_model">
<option>-- Not connected to Horde --</option>
<option>-- Horde models not loaded --</option>
</select>
</div>
<div id="online_status2">
Expand Down
97 changes: 60 additions & 37 deletions public/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ import {
loadHordeSettings,
generateHorde,
checkHordeStatus,
getHordeModels,
adjustHordeGenerationParams,
} from "./scripts/horde.js";

Expand Down Expand Up @@ -1115,6 +1116,11 @@ async function Generate(type, automatic_trigger, force_name2) {
return;
}

if (isHordeGenerationNotAllowed()) {
is_send_press = false;
return;
}

if (selected_group && !is_group_generating) {
generateGroupWrapper(false, type = type);
return;
Expand Down Expand Up @@ -2194,6 +2200,7 @@ function changeMainAPI() {
if (main_api == "kobold" && horde_settings.use_horde) {
is_get_status = true;
getStatus();
getHordeModels();
}
}

Expand Down Expand Up @@ -2278,35 +2285,14 @@ async function getSettings(type) {
changeMainAPI();
}

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);
});
let 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 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);
});

arr_holder = {};
let arr_holder = {};

$("#settings_perset").empty(); //RossAscends: uncommented this to prevent settings selector from doubling preset list on refresh
$("#settings_perset").append(
Expand All @@ -2322,6 +2308,39 @@ async function getSettings(type) {
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 (temp, context length, anchors, and anchor order)

amount_gen = settings.amount_gen;
Expand Down Expand Up @@ -2378,21 +2397,6 @@ async function getSettings(type) {

//Enable GUI deference settings if GUI is selected for Kobold
if (main_api === "kobold") {
if (preset_settings == "gui") {
$("#settings_perset option[value=gui]")
.attr("selected", "true")
.trigger("change");
} 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";
$("#settings_perset option[value=gui]")
.attr("selected", "true")
.trigger("change");
}
}
}

//Load User's Name and Avatar
Expand Down Expand Up @@ -2450,6 +2454,12 @@ async function getSettings(type) {
});
}

function selectKoboldGuiPreset() {
$("#settings_perset option[value=gui]")
.attr("selected", "true")
.trigger("change");
}

async function saveSettings(type) {
//console.log('Entering settings with name1 = '+name1);
jQuery.ajax({
Expand Down Expand Up @@ -3062,6 +3072,15 @@ function sortCharactersList(field, order) {
}
}

function isHordeGenerationNotAllowed() {
if (main_api == "kobold" && horde_settings.use_horde && preset_settings == "gui") {
callPopup('GUI Settings preset is not supported for Horde. Please select another preset.', 'text');
return true;
}

return false;
}

window["TavernAI"].getContext = function () {
return {
chat: chat,
Expand Down Expand Up @@ -3111,6 +3130,10 @@ $(document).ready(function () {
closeMessageEditor();
}

if (isHordeGenerationNotAllowed()) {
return;
}

const swipe_duration = 120;
const swipe_range = 700;
//console.log(swipe_range);
Expand Down
14 changes: 11 additions & 3 deletions public/scripts/horde.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export {
checkHordeStatus,
loadHordeSettings,
adjustHordeGenerationParams,
getHordeModels,
}

let models = [];
Expand Down Expand Up @@ -154,6 +155,16 @@ async function getHordeModels() {
option.selected = horde_settings.model === model.name;
$('#horde_model').append(option);
}

// if previously selected is no longer available
if (horde_settings.model && !models.find(m => m.name == horde_settings.model)) {
horde_settings.model = null;
}

// if no models preselected - select a first one in dropdown
if (!horde_settings.model) {
horde_settings.model = $('#horde_model').find(":selected").val();
}
}

function loadHordeSettings(settings) {
Expand Down Expand Up @@ -182,9 +193,6 @@ $(document).ready(function () {
// Trigger status check
changeMainAPI();
saveSettingsDebounced();
if (main_api === 'kobold' && horde_settings.use_horde) {
await getHordeModels();
}
});

$("#horde_model").on("change", function () {
Expand Down

0 comments on commit 66f7d55

Please sign in to comment.