From 2d07cce1dd0f9c1d02be100966f96810fda39382 Mon Sep 17 00:00:00 2001 From: 50h100a Date: Thu, 3 Aug 2023 16:28:02 -0400 Subject: [PATCH 1/6] make KAI url-fixing as flexible as webUI's --- public/scripts/kai-settings.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/public/scripts/kai-settings.js b/public/scripts/kai-settings.js index 8365487ae..c84344374 100644 --- a/public/scripts/kai-settings.js +++ b/public/scripts/kai-settings.js @@ -35,12 +35,11 @@ const MIN_STREAMING_KCPPVERSION = '1.30'; function formatKoboldUrl(value) { try { const url = new URL(value); - url.pathname = '/api'; - return url.toString(); - } - catch { - return null; - } + if (url.pathname.endsWith('/api')) { + return url.toString(); + } + } catch { } // Try and Catch both fall through to the same return. + return null; } function loadKoboldSettings(preset) { From 6b2455da2bbfb0ea18afb42b544ff56162a1d486 Mon Sep 17 00:00:00 2001 From: 50h100a Date: Fri, 4 Aug 2023 16:49:55 -0400 Subject: [PATCH 2/6] setting for relaxed api urls --- public/index.html | 3 +++ public/scripts/kai-settings.js | 11 ++++++++++- public/scripts/power-user.js | 8 ++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/public/index.html b/public/index.html index 74c7be0d1..082975e78 100644 --- a/public/index.html +++ b/public/index.html @@ -2542,6 +2542,9 @@ +
diff --git a/public/scripts/kai-settings.js b/public/scripts/kai-settings.js index c84344374..978a47b3c 100644 --- a/public/scripts/kai-settings.js +++ b/public/scripts/kai-settings.js @@ -4,6 +4,10 @@ import { getStoppingStrings, } from "../script.js"; +import { + power_user, +} from "./power-user.js"; + export { kai_settings, loadKoboldSettings, @@ -35,7 +39,12 @@ const MIN_STREAMING_KCPPVERSION = '1.30'; function formatKoboldUrl(value) { try { const url = new URL(value); - if (url.pathname.endsWith('/api')) { + if (power_user.settings.relaxed_api_urls) { + if (url.pathname.endsWith('/api')) { + return url.toString(); + } + } else { + url.pathname = '/api'; return url.toString(); } } catch { } // Try and Catch both fall through to the same return. diff --git a/public/scripts/power-user.js b/public/scripts/power-user.js index d28119a61..2532ca183 100644 --- a/public/scripts/power-user.js +++ b/public/scripts/power-user.js @@ -163,6 +163,7 @@ let power_user = { prefer_character_jailbreak: true, continue_on_send: false, trim_spaces: true, + relaxed_api_urls: false, instruct: { enabled: false, @@ -671,6 +672,7 @@ function loadPowerUserSettings(settings, data) { power_user.chat_width = 50; } + $('#relaxed_api_urls').prop("checked", power_user.relaxed_api_urls); $('#trim_spaces').prop("checked", power_user.trim_spaces); $('#continue_on_send').prop("checked", power_user.continue_on_send); $('#auto_swipe').prop("checked", power_user.auto_swipe); @@ -1979,6 +1981,12 @@ $(document).ready(() => { saveSettingsDebounced(); }); + $("#relaxed_api_urls").on("input", function () { + const value = !!$(this).prop('checked'); + power_user.relaxed_api_urls = value; + saveSettingsDebounced(); + }); + $('#spoiler_free_mode').on('input', function () { power_user.spoiler_free_mode = !!$(this).prop('checked'); switchSpoilerMode(); From 4ae3e9db0a992fb6cbd70fc2dd048cb53e04b1e2 Mon Sep 17 00:00:00 2001 From: 50h100a Date: Fri, 4 Aug 2023 17:01:09 -0400 Subject: [PATCH 3/6] fix settings access --- public/scripts/kai-settings.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/scripts/kai-settings.js b/public/scripts/kai-settings.js index 978a47b3c..49cdbeb33 100644 --- a/public/scripts/kai-settings.js +++ b/public/scripts/kai-settings.js @@ -39,7 +39,7 @@ const MIN_STREAMING_KCPPVERSION = '1.30'; function formatKoboldUrl(value) { try { const url = new URL(value); - if (power_user.settings.relaxed_api_urls) { + if (power_user.relaxed_api_urls) { if (url.pathname.endsWith('/api')) { return url.toString(); } From 75bb0d641f883dc7d2b40ba7b87910d64cf772cf Mon Sep 17 00:00:00 2001 From: 50h100a Date: Mon, 7 Aug 2023 16:46:12 -0400 Subject: [PATCH 4/6] Make 'relaxed api url' even more relaxed. --- public/scripts/kai-settings.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/public/scripts/kai-settings.js b/public/scripts/kai-settings.js index 49cdbeb33..5ca4f5a5b 100644 --- a/public/scripts/kai-settings.js +++ b/public/scripts/kai-settings.js @@ -39,14 +39,10 @@ const MIN_STREAMING_KCPPVERSION = '1.30'; function formatKoboldUrl(value) { try { const url = new URL(value); - if (power_user.relaxed_api_urls) { - if (url.pathname.endsWith('/api')) { - return url.toString(); - } - } else { + if (!power_user.relaxed_api_urls) { url.pathname = '/api'; - return url.toString(); } + return url.toString(); } catch { } // Try and Catch both fall through to the same return. return null; } From 128945aaaa32bf1bebd3ffe3e3bf75df81167490 Mon Sep 17 00:00:00 2001 From: 50h100a Date: Mon, 7 Aug 2023 16:46:32 -0400 Subject: [PATCH 5/6] Copy 'relaxed api url' functionality over to webui --- public/scripts/textgen-settings.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/public/scripts/textgen-settings.js b/public/scripts/textgen-settings.js index cc984e361..cbc92ae8d 100644 --- a/public/scripts/textgen-settings.js +++ b/public/scripts/textgen-settings.js @@ -6,6 +6,10 @@ import { setGenerationParamsFromPreset, } from "../script.js"; +import { + power_user, +} from "./power-user.js"; + export { textgenerationwebui_settings, loadTextGenSettings, @@ -98,9 +102,10 @@ function selectPreset(name) { function formatTextGenURL(value) { try { const url = new URL(value); - if (url.pathname.endsWith('/api')) { - return url.toString(); + if (!power_user.relaxed_api_urls) { + url.pathname = '/api'; } + return url.toString(); } catch { } // Try and Catch both fall through to the same return. return null; } From c1ab0212e5350b154e5be9e7b0568c0e1066d70a Mon Sep 17 00:00:00 2001 From: 50h100a Date: Mon, 7 Aug 2023 17:10:05 -0400 Subject: [PATCH 6/6] update comments --- public/scripts/kai-settings.js | 2 +- public/scripts/textgen-settings.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/public/scripts/kai-settings.js b/public/scripts/kai-settings.js index 5ca4f5a5b..07bb1b0d1 100644 --- a/public/scripts/kai-settings.js +++ b/public/scripts/kai-settings.js @@ -43,7 +43,7 @@ function formatKoboldUrl(value) { url.pathname = '/api'; } return url.toString(); - } catch { } // Try and Catch both fall through to the same return. + } catch { } // Just using URL as a validation check return null; } diff --git a/public/scripts/textgen-settings.js b/public/scripts/textgen-settings.js index cbc92ae8d..bb8ebdc48 100644 --- a/public/scripts/textgen-settings.js +++ b/public/scripts/textgen-settings.js @@ -106,7 +106,7 @@ function formatTextGenURL(value) { url.pathname = '/api'; } return url.toString(); - } catch { } // Try and Catch both fall through to the same return. + } catch { } // Just using URL as a validation check return null; }