From 81ed4d84311e32e98218b3ea7211b9c7465f3617 Mon Sep 17 00:00:00 2001
From: Cohee <18619528+Cohee1207@users.noreply.github.com>
Date: Wed, 16 Aug 2023 20:34:47 +0300
Subject: [PATCH] Reorderable samplers for Novel
---
default/settings.json | 3 +-
public/index.html | 53 ++++++++++++++++++++++++++++++-
public/scripts/nai-settings.js | 57 +++++++++++++++++++++++++++++++++-
public/style.css | 30 +++++++++++++++---
4 files changed, 136 insertions(+), 7 deletions(-)
diff --git a/default/settings.json b/default/settings.json
index 64d4807e9..c086c6604 100644
--- a/default/settings.json
+++ b/default/settings.json
@@ -348,7 +348,8 @@
"min_length": 1,
"model_novel": "clio-v1",
"preset_settings_novel": "Talker-Chat-Clio",
- "streaming_novel": false
+ "streaming_novel": true,
+ "order": [1, 5, 0, 2, 3, 4]
},
"kai_settings": {
"temp": 1,
diff --git a/public/index.html b/public/index.html
index 73a5bb4c5..5c4bfc5d2 100644
--- a/public/index.html
+++ b/public/index.html
@@ -832,7 +832,7 @@
Samplers will be applied in a top-down order.
Use with caution.
-
diff --git a/public/scripts/nai-settings.js b/public/scripts/nai-settings.js
index 79a319257..47aa56670 100644
--- a/public/scripts/nai-settings.js
+++ b/public/scripts/nai-settings.js
@@ -17,6 +17,7 @@ export {
};
const default_preamble = "[ Style: chat, complex, sensory, visceral ]";
+const default_order = [1, 5, 0, 2, 3, 4];
const maximum_output_length = 150;
const default_presets = {
"euterpe-v2": "Classic-Euterpe",
@@ -45,6 +46,7 @@ const nai_settings = {
prefix: '',
cfg_uc: '',
banned_tokens: '',
+ order: default_order,
};
const nai_tiers = {
@@ -108,6 +110,7 @@ function loadNovelPreset(preset) {
nai_settings.prefix = preset.prefix;
nai_settings.cfg_uc = preset.cfg_uc || '';
nai_settings.banned_tokens = preset.banned_tokens || '';
+ nai_settings.order = preset.order || default_order;
loadNovelSettingsUi(nai_settings);
}
@@ -140,6 +143,7 @@ function loadNovelSettings(settings) {
nai_settings.prefix = settings.prefix;
nai_settings.cfg_uc = settings.cfg_uc || '';
nai_settings.banned_tokens = settings.banned_tokens || '';
+ nai_settings.order = settings.order || default_order;
loadNovelSettingsUi(nai_settings);
}
@@ -181,6 +185,7 @@ function loadNovelSettingsUi(ui_settings) {
$('#nai_banned_tokens').val(ui_settings.banned_tokens || "");
$("#streaming_novel").prop('checked', ui_settings.streaming_novel);
+ sortItemsByOrder(ui_settings.order);
}
const sliders = [
@@ -419,7 +424,7 @@ export function getNovelGenerationData(finalPrompt, this_settings, this_amount_g
"use_string": true,
"return_full_text": false,
"prefix": prefix,
- "order": this_settings.order,
+ "order": nai_settings.order || this_settings.order || default_order,
"streaming": nai_settings.streaming_novel,
};
}
@@ -441,6 +446,44 @@ function selectPrefix(selected_prefix, finalPromt) {
return "vanilla";
}
+// Sort the samplers by the order array
+function sortItemsByOrder(orderArray) {
+ console.debug('Preset samplers order: ' + orderArray);
+ const $draggableItems = $("#novel_order");
+
+ // Sort the items by the order array
+ for (let i = 0; i < orderArray.length; i++) {
+ const index = orderArray[i];
+ const $item = $draggableItems.find(`[data-id="${index}"]`).detach();
+ $draggableItems.append($item);
+ }
+
+ // Update the disabled class for each sampler
+ $draggableItems.children().each(function () {
+ const isEnabled = orderArray.includes(parseInt($(this).data('id')));
+ $(this).toggleClass('disabled', !isEnabled);
+
+ // If the sampler is disabled, move it to the bottom of the list
+ if (!isEnabled) {
+ const item = $(this).detach();
+ $draggableItems.append(item);
+ }
+ });
+}
+
+function saveSamplingOrder() {
+ const order = [];
+ $('#novel_order').children().each(function () {
+ const isEnabled = !$(this).hasClass('disabled');
+ if (isEnabled) {
+ order.push($(this).data('id'));
+ }
+ });
+ nai_settings.order = order;
+ console.log('Samplers reordered:', nai_settings.order);
+ saveSettingsDebounced();
+}
+
export async function generateNovelWithStreaming(generate_data, signal) {
const response = await fetch('/generate_novelai', {
headers: getRequestHeaders(),
@@ -532,4 +575,16 @@ $(document).ready(function () {
nai_settings.phrase_rep_pen = $("#phrase_rep_pen_novel").find(":selected").val();
saveSettingsDebounced();
});
+
+ $('#novel_order').sortable({
+ stop: saveSamplingOrder,
+ });
+
+ $('#novel_order .toggle_button').on('click', function () {
+ const $item = $(this).closest('[data-id]');
+ const isEnabled = !$item.hasClass('disabled');
+ $item.toggleClass('disabled', isEnabled);
+ console.log('Sampler toggled:', $item.data('id'), !isEnabled);
+ saveSamplingOrder();
+ });
});
diff --git a/public/style.css b/public/style.css
index 9cce622b1..9764133c9 100644
--- a/public/style.css
+++ b/public/style.css
@@ -2216,7 +2216,7 @@ grammarly-extension {
background-color: red;
}
-#kobold_order {
+.prompt_order {
display: flex;
flex-direction: column;
align-items: center;
@@ -2226,7 +2226,7 @@ grammarly-extension {
padding: 5px;
}
-#kobold_order>div {
+.prompt_order>div {
padding: 5px;
padding-left: 30px;
width: 100%;
@@ -2241,18 +2241,40 @@ grammarly-extension {
display: flex;
align-items: center;
justify-content: space-between;
+ column-gap: 10px;
}
-#kobold_order>div:hover {
+.prompt_order>div>span:first-child {
+ flex-grow: 1;
+}
+
+.prompt_order>div:hover {
background-color: var(--grey30a);
}
-#kobold_order>div::after {
+.prompt_order>div::after {
content: "☰";
left: 8px;
position: absolute;
}
+.prompt_order .disabled {
+ opacity: 0.5;
+ filter: grayscale(0.5);
+}
+
+.prompt_order .toggle_button {
+ padding-right: 0;
+}
+
+.prompt_order .toggle_button::after {
+ content: '☑';
+}
+
+.prompt_order .disabled .toggle_button::after {
+ content: '☐';
+}
+
/* ------ online status indicators and texts. 2 = kobold AI, 3 = Novel AI ----------*/
#online_status2,
#online_status_horde,