diff --git a/public/index.html b/public/index.html index c5b43fae6..be2bb0255 100644 --- a/public/index.html +++ b/public/index.html @@ -88,7 +88,8 @@

API url

@@ -104,10 +105,17 @@ Adjust generation to worker capabilities

API key

-
Get it here: Register
+
Get it here: Register
-

Model

- +

+ Model +
+ +
+

+
diff --git a/public/script.js b/public/script.js index 20605001b..852db850c 100644 --- a/public/script.js +++ b/public/script.js @@ -115,6 +115,7 @@ export { showSwipeButtons, hideSwipeButtons, changeMainAPI, + setGenerationProgress, chat, this_chid, settings, @@ -1085,6 +1086,7 @@ function appendToStoryString(value, prefix) { async function Generate(type, automatic_trigger, force_name2) { console.log('Generate entered'); + setGenerationProgress(0); tokens_already_generated = 0; message_already_generated = name2 + ': '; @@ -1708,9 +1710,13 @@ async function Generate(type, automatic_trigger, force_name2) { if (!data.error) { //const getData = await response.json(); var getMessage = ""; - if (main_api == 'kobold') { + if (main_api == 'kobold' && !horde_settings.use_horde) { getMessage = data.results[0].text; - } else if (main_api == 'textgenerationwebui') { + } + else if (main_api == 'kobold' && horde_settings.use_horde) { + getMessage = data; + } + else if (main_api == 'textgenerationwebui') { getMessage = data.data[0]; if (getMessage == null || data.error) { activateSendButtons(); @@ -1718,7 +1724,8 @@ async function Generate(type, automatic_trigger, force_name2) { return; } getMessage = getMessage.substring(finalPromt.length); - } else if (main_api == 'novel') { + } + else if (main_api == 'novel') { getMessage = data.output; } if (main_api == 'openai') { @@ -1795,6 +1802,7 @@ async function Generate(type, automatic_trigger, force_name2) { activateSendButtons(); showSwipeButtons(); + setGenerationProgress(0); $('.mes_edit:last').show(); }; @@ -1802,6 +1810,7 @@ async function Generate(type, automatic_trigger, force_name2) { $("#send_textarea").removeAttr('disabled'); is_send_press = false; activateSendButtons(); + setGenerationProgress(0); console.log(exception); console.log(jqXHR); }; @@ -2966,6 +2975,18 @@ function setGenerationFunction(func) { extension_generation_function = func; } +function setGenerationProgress(progress) { + if (!progress) { + $('#send_textarea').css({'background': '', 'transition': ''}); + } + else { + $('#send_textarea').css({ + 'background': `linear-gradient(90deg, #008000d6 ${progress}%, transparent ${progress}%)`, + 'transition': '0.25s ease-in-out' + }); + } +} + window["TavernAI"].getContext = function () { return { chat: chat, diff --git a/public/scripts/horde.js b/public/scripts/horde.js index e4a1fa213..d6c9e054c 100644 --- a/public/scripts/horde.js +++ b/public/scripts/horde.js @@ -1,4 +1,4 @@ -import { saveSettingsDebounced, changeMainAPI, callPopup } from "../script.js"; +import { saveSettingsDebounced, changeMainAPI, callPopup, setGenerationProgress } from "../script.js"; import { delay } from "./utils.js"; export { @@ -19,7 +19,7 @@ let horde_settings = { }; const MAX_RETRIES = 100; -const CHECK_INTERVAL = 1000; +const CHECK_INTERVAL = 3000; async function getWorkers() { const response = await fetch('https://horde.koboldai.net/api/v2/workers?type=text'); @@ -27,12 +27,23 @@ async function getWorkers() { return data; } +function validateHordeModel() { + let selectedModel = models.find(m => m.name == horde_settings.model); + + if (!selectedModel) { + callPopup('No Horde model selected or the selected model is no longer available. Please choose another model'); + throw new Error('No Horde model available'); + } + + return selectedModel; +} + async function adjustHordeGenerationParams(max_context_length, max_length) { const workers = await getWorkers(); let maxContextLength = max_context_length; let maxLength = max_length; let availableWorkers = []; - let selectedModel = models.find(m => m.name == horde_settings.model); + let selectedModel = validateHordeModel(); if (!selectedModel) { return { maxContextLength, maxLength }; @@ -54,13 +65,21 @@ async function adjustHordeGenerationParams(max_context_length, max_length) { } async function generateHorde(prompt, params) { + validateHordeModel(); delete params.prompt; + // No idea what these do + params["n"] = 1; + params["frmtadsnsp"] = false; + params["frmtrmblln"] = false; + params["frmtrmspch"] = false; + params["frmttriminc"] = false; + const payload = { "prompt": prompt, "params": params, - "trusted_workers": false, - "slow_workers": false, + //"trusted_workers": false, + //"slow_workers": false, "models": [horde_settings.model], }; @@ -81,11 +100,10 @@ async function generateHorde(prompt, params) { const responseJson = await response.json(); const task_id = responseJson.id; + let queue_position_first = null; console.log(`Horde task id = ${task_id}`); for (let retryNumber = 0; retryNumber < MAX_RETRIES; retryNumber++) { - await delay(CHECK_INTERVAL); - const statusCheckResponse = await fetch(`https://horde.koboldai.net/api/v2/generate/text/status/${task_id}`, { headers: { "Content-Type": "application/json", @@ -96,12 +114,27 @@ async function generateHorde(prompt, params) { const statusCheckJson = await statusCheckResponse.json(); console.log(statusCheckJson); - if (statusCheckJson.done) { - const generatedText = statusCheckJson.generations[0]; + if (statusCheckJson.done && Array.isArray(statusCheckJson.generations) && statusCheckJson.generations.length) { + setGenerationProgress(100); + const generatedText = statusCheckJson.generations[0].text; console.log(generatedText); return generatedText; } + else if (!queue_position_first) { + queue_position_first = statusCheckJson.queue_position; + setGenerationProgress(0); + } + else if (statusCheckJson.queue_position >= 0) { + let queue_position = statusCheckJson.queue_position; + const progress = Math.round(100 - (queue_position / queue_position_first * 100)); + setGenerationProgress(progress); + } + + await delay(CHECK_INTERVAL); } + + callPopup('Horde request timed out. Try again', 'text'); + throw new Error('Horde timeout'); } async function checkHordeStatus() { @@ -169,4 +202,6 @@ $(document).ready(function () { horde_settings.auto_adjust = !!$(this).prop("checked"); saveSettingsDebounced(); }); + + $("#horde_refresh").on("click", getHordeModels); }) \ No newline at end of file diff --git a/public/style.css b/public/style.css index a5e0d6a5b..22e7ac977 100644 --- a/public/style.css +++ b/public/style.css @@ -1272,6 +1272,17 @@ input[type=search]:focus::-webkit-search-cancel-button { display: inline-block; } +.horde_model_title { + display: flex; + flex-direction: row; + align-items: center; + column-gap: 20px; +} + +.horde_model_title .right_menu_button img.svg_icon { + height: 20px; +} + #softprompt { margin-bottom: 10px; }