From 4988f22e94b5ac4506032213ef594245fb40de4b Mon Sep 17 00:00:00 2001 From: Karl-Johan Alm Date: Mon, 25 Nov 2024 23:08:11 +0900 Subject: [PATCH 01/13] feature: allow auto-use of max context size given by backend --- public/index.html | 4 ++++ public/script.js | 13 ++++++++++++- public/scripts/power-user.js | 12 ++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/public/index.html b/public/index.html index 2791dbd70..d5e4d9d8e 100644 --- a/public/index.html +++ b/public/index.html @@ -220,6 +220,10 @@ +
diff --git a/public/script.js b/public/script.js index 405319c55..1fdb92786 100644 --- a/public/script.js +++ b/public/script.js @@ -1238,8 +1238,9 @@ async function getStatusTextgen() { const wantsInstructDerivation = (power_user.instruct.enabled && power_user.instruct.derived); const wantsContextDerivation = power_user.context_derived; + const wantsContextSize = power_user.context_size_derived; const supportsChatTemplate = [textgen_types.KOBOLDCPP, textgen_types.LLAMACPP].includes(textgen_settings.type); - if (supportsChatTemplate && (wantsInstructDerivation || wantsContextDerivation)) { + if (supportsChatTemplate && (wantsInstructDerivation || wantsContextDerivation || wantsContextSize)) { const response = await fetch('/api/backends/text-completions/props', { method: 'POST', headers: getRequestHeaders(), @@ -1253,6 +1254,16 @@ async function getStatusTextgen() { const data = await response.json(); if (data) { const { chat_template, chat_template_hash } = data; + if (wantsContextSize && "default_generation_settings" in data) { + const backend_max_context = data["default_generation_settings"]["n_ctx"]; + if (max_context !== backend_max_context) { + console.log(`Auto-switching max context from ${max_context} to ${backend_max_context}`); + toastr.info(`Context Size Changed: ${max_context} ⇒ ${backend_max_context}`); + max_context = backend_max_context; + $('#max_context').val(max_context); + $('#max_context_counter').val(max_context); + } + } console.log(`We have chat template ${chat_template.split('\n')[0]}...`); const templates = await deriveTemplatesFromChatTemplate(chat_template, chat_template_hash); if (templates) { diff --git a/public/scripts/power-user.js b/public/scripts/power-user.js index c86d2de82..48eef067f 100644 --- a/public/scripts/power-user.js +++ b/public/scripts/power-user.js @@ -245,6 +245,7 @@ let power_user = { }, context_derived: false, + context_size_derived: false, sysprompt: { enabled: true, @@ -1481,6 +1482,7 @@ async function loadPowerUserSettings(settings, data) { $('#example_messages_behavior').val(getExampleMessagesBehavior()); $(`#example_messages_behavior option[value="${getExampleMessagesBehavior()}"]`).prop('selected', true); $('#context_derived').parent().find('i').toggleClass('toggleEnabled', !!power_user.context_derived); + $('#context_size_derived').parent().find('i').toggleClass('toggleEnabled', !!power_user.context_size_derived); $('#console_log_prompts').prop('checked', power_user.console_log_prompts); $('#request_token_probabilities').prop('checked', power_user.request_token_probabilities); @@ -3076,6 +3078,16 @@ $(document).ready(() => { $('#context_derived').parent().find('i').toggleClass('toggleEnabled', !!power_user.context_derived); }); + $('#context_size_derived').on('input', function () { + const value = !!$(this).prop('checked'); + power_user.context_size_derived = value; + saveSettingsDebounced(); + }); + + $('#context_size_derived').on('change', function () { + $('#context_size_derived').parent().find('i').toggleClass('toggleEnabled', !!power_user.context_size_derived); + }); + $('#always-force-name2-checkbox').change(function () { power_user.always_force_name2 = !!$(this).prop('checked'); saveSettingsDebounced(); From e02f57b7b0d17e0a39ce4bc1c79d4aa6e2370d48 Mon Sep 17 00:00:00 2001 From: Karl-Johan Alm Date: Tue, 26 Nov 2024 10:00:52 +0900 Subject: [PATCH 02/13] respect context unlocked flag when auto-setting context size --- public/script.js | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/public/script.js b/public/script.js index 1fdb92786..a3865a00d 100644 --- a/public/script.js +++ b/public/script.js @@ -1256,12 +1256,13 @@ async function getStatusTextgen() { const { chat_template, chat_template_hash } = data; if (wantsContextSize && "default_generation_settings" in data) { const backend_max_context = data["default_generation_settings"]["n_ctx"]; + const old_value = max_context; if (max_context !== backend_max_context) { - console.log(`Auto-switching max context from ${max_context} to ${backend_max_context}`); - toastr.info(`Context Size Changed: ${max_context} ⇒ ${backend_max_context}`); - max_context = backend_max_context; - $('#max_context').val(max_context); - $('#max_context_counter').val(max_context); + setGenerationParamsFromPreset({ max_length: backend_max_context }, true); + } + if (old_value !== max_context) { + console.log(`Auto-switched max context from ${old_value} to ${max_context}`); + toastr.info(`Context Size Changed: ${old_value} ⇒ ${max_context}`); } } console.log(`We have chat template ${chat_template.split('\n')[0]}...`); @@ -6832,9 +6833,19 @@ export async function saveSettings(type) { }); } -export function setGenerationParamsFromPreset(preset) { +export function setGenerationParamsFromPreset(preset, keep_context_lock) { const needsUnlock = (preset.max_length ?? max_context) > MAX_CONTEXT_DEFAULT || (preset.genamt ?? amount_gen) > MAX_RESPONSE_DEFAULT; - $('#max_context_unlocked').prop('checked', needsUnlock).trigger('change'); + if (!keep_context_lock || $('#max_context_unlocked').prop('checked')) { + $('#max_context_unlocked').prop('checked', needsUnlock).trigger('change'); + } else if (needsUnlock) { + // cap values + if ((preset.max_length ?? max_context) > MAX_CONTEXT_DEFAULT) { + preset.max_length = MAX_CONTEXT_DEFAULT; + } + if ((preset.genamt ?? amount_gen) > MAX_RESPONSE_DEFAULT) { + preset.genamt = MAX_RESPONSE_DEFAULT; + } + } if (preset.genamt !== undefined) { amount_gen = preset.genamt; From faf80d1b624c391109ed7377e3f6e5744c473445 Mon Sep 17 00:00:00 2001 From: Karl-Johan Alm Date: Tue, 26 Nov 2024 10:36:40 +0900 Subject: [PATCH 03/13] UI: move the derived context size flag into connection pane --- public/index.html | 10 ++++++---- public/scripts/power-user.js | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/public/index.html b/public/index.html index d5e4d9d8e..1f86807fb 100644 --- a/public/index.html +++ b/public/index.html @@ -220,10 +220,6 @@ -
@@ -3272,6 +3268,12 @@ View hidden API keys
+
+ +
diff --git a/public/scripts/power-user.js b/public/scripts/power-user.js index 48eef067f..dcba95ca7 100644 --- a/public/scripts/power-user.js +++ b/public/scripts/power-user.js @@ -1482,7 +1482,7 @@ async function loadPowerUserSettings(settings, data) { $('#example_messages_behavior').val(getExampleMessagesBehavior()); $(`#example_messages_behavior option[value="${getExampleMessagesBehavior()}"]`).prop('selected', true); $('#context_derived').parent().find('i').toggleClass('toggleEnabled', !!power_user.context_derived); - $('#context_size_derived').parent().find('i').toggleClass('toggleEnabled', !!power_user.context_size_derived); + $('#context_size_derived').prop('checked', !!power_user.context_size_derived); $('#console_log_prompts').prop('checked', power_user.console_log_prompts); $('#request_token_probabilities').prop('checked', power_user.request_token_probabilities); @@ -3085,7 +3085,7 @@ $(document).ready(() => { }); $('#context_size_derived').on('change', function () { - $('#context_size_derived').parent().find('i').toggleClass('toggleEnabled', !!power_user.context_size_derived); + $('#context_size_derived').prop('checked', !!power_user.context_size_derived); }); $('#always-force-name2-checkbox').change(function () { From 04b68d2cce27bb5fe9bf039fb34bbe2bbcb6f0f6 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sat, 30 Nov 2024 18:08:12 +0200 Subject: [PATCH 04/13] Move derive context size to TC settings --- public/index.html | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/public/index.html b/public/index.html index 1f86807fb..bbd104b0b 100644 --- a/public/index.html +++ b/public/index.html @@ -2573,15 +2573,21 @@
+
+ + +
-
@@ -3268,12 +3274,6 @@ View hidden API keys
-
- -
From 8e20ebb534189d9e17baa1475949761aa4a0e017 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sat, 30 Nov 2024 18:14:46 +0200 Subject: [PATCH 05/13] Run eslint --- public/script.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/script.js b/public/script.js index a3865a00d..cf8e79300 100644 --- a/public/script.js +++ b/public/script.js @@ -1254,8 +1254,8 @@ async function getStatusTextgen() { const data = await response.json(); if (data) { const { chat_template, chat_template_hash } = data; - if (wantsContextSize && "default_generation_settings" in data) { - const backend_max_context = data["default_generation_settings"]["n_ctx"]; + if (wantsContextSize && 'default_generation_settings' in data) { + const backend_max_context = data['default_generation_settings']['n_ctx']; const old_value = max_context; if (max_context !== backend_max_context) { setGenerationParamsFromPreset({ max_length: backend_max_context }, true); From 4a7a11dfd560c21ac99cf25bb9f4167cc75992e2 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sat, 30 Nov 2024 18:19:31 +0200 Subject: [PATCH 06/13] Add JSdoc for function --- public/script.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/public/script.js b/public/script.js index cf8e79300..f93880cea 100644 --- a/public/script.js +++ b/public/script.js @@ -6833,9 +6833,14 @@ export async function saveSettings(type) { }); } -export function setGenerationParamsFromPreset(preset, keep_context_lock) { +/** + * Sets the generation parameters from a preset object. + * @param {{ genamt?: number, max_length?: number }} preset Preset object + * @param {boolean?} keepContextLock If true, will not unlock context if it needs to be unlocked + */ +export function setGenerationParamsFromPreset(preset, keepContextLock = false) { const needsUnlock = (preset.max_length ?? max_context) > MAX_CONTEXT_DEFAULT || (preset.genamt ?? amount_gen) > MAX_RESPONSE_DEFAULT; - if (!keep_context_lock || $('#max_context_unlocked').prop('checked')) { + if (!keepContextLock || $('#max_context_unlocked').prop('checked')) { $('#max_context_unlocked').prop('checked', needsUnlock).trigger('change'); } else if (needsUnlock) { // cap values From 56c99000c4fcb32a15e7cc8706ebcad193a25249 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sat, 30 Nov 2024 18:21:15 +0200 Subject: [PATCH 07/13] Split auto-switch toast --- public/script.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/script.js b/public/script.js index f93880cea..9e212faa0 100644 --- a/public/script.js +++ b/public/script.js @@ -1262,7 +1262,7 @@ async function getStatusTextgen() { } if (old_value !== max_context) { console.log(`Auto-switched max context from ${old_value} to ${max_context}`); - toastr.info(`Context Size Changed: ${old_value} ⇒ ${max_context}`); + toastr.info(`${old_value} ⇒ ${max_context}`, 'Context Size Changed'); } } console.log(`We have chat template ${chat_template.split('\n')[0]}...`); From a86735d7436939df3473a3cf51b8f9314edd6345 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sat, 30 Nov 2024 19:30:14 +0200 Subject: [PATCH 08/13] Fix sendless statuses --- src/endpoints/backends/text-completions.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/endpoints/backends/text-completions.js b/src/endpoints/backends/text-completions.js index 34c215bce..80955696e 100644 --- a/src/endpoints/backends/text-completions.js +++ b/src/endpoints/backends/text-completions.js @@ -152,7 +152,7 @@ router.post('/status', jsonParser, async function (request, response) { if (!modelsReply.ok) { console.log('Models endpoint is offline.'); - return response.status(400); + return response.sendStatus(400); } /** @type {any} */ @@ -173,7 +173,7 @@ router.post('/status', jsonParser, async function (request, response) { if (!Array.isArray(data.data)) { console.log('Models response is not an array.'); - return response.status(400); + return response.sendStatus(400); } const modelIds = data.data.map(x => x.id); @@ -224,7 +224,7 @@ router.post('/status', jsonParser, async function (request, response) { return response.send({ result, data: data.data }); } catch (error) { console.error(error); - return response.status(500); + return response.sendStatus(500); } }); @@ -244,7 +244,7 @@ router.post('/props', jsonParser, async function (request, response) { const propsReply = await fetch(propsUrl, args); if (!propsReply.ok) { - return response.status(400); + return response.sendStatus(400); } /** @type {any} */ @@ -258,7 +258,7 @@ router.post('/props', jsonParser, async function (request, response) { return response.send(props); } catch (error) { console.error(error); - return response.status(500); + return response.sendStatus(500); } }); @@ -450,7 +450,7 @@ ollama.post('/download', jsonParser, async function (request, response) { return response.send({ ok: true }); } catch (error) { console.error(error); - return response.status(500); + return response.sendStatus(500); } }); @@ -493,7 +493,7 @@ ollama.post('/caption-image', jsonParser, async function (request, response) { return response.send({ caption }); } catch (error) { console.error(error); - return response.status(500); + return response.sendStatus(500); } }); @@ -540,7 +540,7 @@ llamacpp.post('/caption-image', jsonParser, async function (request, response) { } catch (error) { console.error(error); - return response.status(500); + return response.sendStatus(500); } }); @@ -569,7 +569,7 @@ llamacpp.post('/props', jsonParser, async function (request, response) { } catch (error) { console.error(error); - return response.status(500); + return response.sendStatus(500); } }); @@ -619,7 +619,7 @@ llamacpp.post('/slots', jsonParser, async function (request, response) { } catch (error) { console.error(error); - return response.status(500); + return response.sendStatus(500); } }); @@ -665,7 +665,7 @@ tabby.post('/download', jsonParser, async function (request, response) { return response.send({ ok: true }); } catch (error) { console.error(error); - return response.status(500); + return response.sendStatus(500); } }); From 89ec8fd23a24f464b935692e5dc7bda6cc015e58 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sun, 1 Dec 2024 14:38:17 +0200 Subject: [PATCH 09/13] Bump package version --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index bbac61b87..93902fcff 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "sillytavern", - "version": "1.12.7", + "version": "1.12.8", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "sillytavern", - "version": "1.12.7", + "version": "1.12.8", "hasInstallScript": true, "license": "AGPL-3.0", "dependencies": { diff --git a/package.json b/package.json index e2e15d376..56ddd3796 100644 --- a/package.json +++ b/package.json @@ -84,7 +84,7 @@ "type": "git", "url": "https://github.com/SillyTavern/SillyTavern.git" }, - "version": "1.12.7", + "version": "1.12.8", "scripts": { "start": "node server.js", "start:deno": "deno run --allow-run --allow-net --allow-read --allow-write --allow-sys --allow-env server.js", From 66a862f797d0a86291925f1238941dbf3b845bea Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sun, 1 Dec 2024 15:10:22 +0200 Subject: [PATCH 10/13] Lint the use of data-i18n attributes --- public/index.html | 111 ++++++++++++------ .../extensions/expressions/settings.html | 2 +- public/scripts/extensions/tts/settings.html | 4 +- 3 files changed, 75 insertions(+), 42 deletions(-) diff --git a/public/index.html b/public/index.html index c00ab84f7..b720f126d 100644 --- a/public/index.html +++ b/public/index.html @@ -820,8 +820,8 @@
-
- World Info format template +
+ World Info format template
@@ -1524,15 +1524,15 @@
-

Contrastive Search +

+ Contrastive Search

@@ -1566,9 +1566,8 @@

-

CFG +

+ CFG

@@ -1965,8 +1965,10 @@
Logit Bias
-
- Helps to ban or reinforce the usage of certain tokens. Confirm token parsing with Tokenizer. +
+ Helps to ban or reinforce the usage of certain tokens. + Confirm token parsing with + Tokenizer.
@@ -2629,8 +2632,9 @@
- This will show up as your saved preset.
+ This will show up as your saved preset.
+
@@ -2640,8 +2644,9 @@
- Alternative server URL (leave empty to use the default value).
+ Alternative server URL (leave empty to use the default value).
+
@@ -2654,8 +2659,9 @@
- Will be used as a password for the proxy instead of API key.
+ Will be used as a password for the proxy instead of API key.
+
@@ -3743,7 +3749,11 @@
- Active World(s) for all chats + + + Active World(s) for all chats + +
@@ -4240,7 +4253,7 @@ - @@ -4359,8 +4372,10 @@
-
- +
@@ -4559,7 +4578,9 @@
- +
@@ -4587,14 +4608,18 @@