mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Horde should actually work now
This commit is contained in:
@@ -88,7 +88,8 @@
|
|||||||
<form action="javascript:void(null);" method="post" enctype="multipart/form-data">
|
<form action="javascript:void(null);" method="post" enctype="multipart/form-data">
|
||||||
<label for="use_horde" class="checkbox_label">
|
<label for="use_horde" class="checkbox_label">
|
||||||
<input id="use_horde" type="checkbox" />
|
<input id="use_horde" type="checkbox" />
|
||||||
Use Horde. <a target="_blank" href="https://stablehorde.net/">Learn more</a>
|
Use Horde.
|
||||||
|
<a target="_blank" href="https://horde.koboldai.net/">Learn more</a>
|
||||||
</label>
|
</label>
|
||||||
<div id="kobold_api_block">
|
<div id="kobold_api_block">
|
||||||
<h4>API url</h4>
|
<h4>API url</h4>
|
||||||
@@ -104,10 +105,17 @@
|
|||||||
Adjust generation to worker capabilities
|
Adjust generation to worker capabilities
|
||||||
</label>
|
</label>
|
||||||
<h4>API key</h4>
|
<h4>API key</h4>
|
||||||
<h5>Get it here: <a target="_blank" href="https://stablehorde.net/register">Register</a></h5>
|
<h5>Get it here: <a target="_blank" href="https://horde.koboldai.net/register">Register</a></h5>
|
||||||
<input id="horde_api_key" name="horde_api_key" class="text_pole" maxlength="500" value="0000000000" autocomplete="off">
|
<input id="horde_api_key" name="horde_api_key" class="text_pole" maxlength="500" value="0000000000" autocomplete="off">
|
||||||
<h4>Model</h4>
|
<h4 class="horde_model_title">
|
||||||
<select id="horde_model"></select>
|
Model
|
||||||
|
<div id="horde_refresh" title="Refresh models" class="right_menu_button">
|
||||||
|
<img class="svg_icon" src="img/repeat-solid.svg" />
|
||||||
|
</div>
|
||||||
|
</h4>
|
||||||
|
<select id="horde_model">
|
||||||
|
<option>-- Not connected to Horde --</option>
|
||||||
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div id="online_status2">
|
<div id="online_status2">
|
||||||
<div id="online_status_indicator2"></div>
|
<div id="online_status_indicator2"></div>
|
||||||
|
@@ -115,6 +115,7 @@ export {
|
|||||||
showSwipeButtons,
|
showSwipeButtons,
|
||||||
hideSwipeButtons,
|
hideSwipeButtons,
|
||||||
changeMainAPI,
|
changeMainAPI,
|
||||||
|
setGenerationProgress,
|
||||||
chat,
|
chat,
|
||||||
this_chid,
|
this_chid,
|
||||||
settings,
|
settings,
|
||||||
@@ -1085,6 +1086,7 @@ function appendToStoryString(value, prefix) {
|
|||||||
|
|
||||||
async function Generate(type, automatic_trigger, force_name2) {
|
async function Generate(type, automatic_trigger, force_name2) {
|
||||||
console.log('Generate entered');
|
console.log('Generate entered');
|
||||||
|
setGenerationProgress(0);
|
||||||
tokens_already_generated = 0;
|
tokens_already_generated = 0;
|
||||||
message_already_generated = name2 + ': ';
|
message_already_generated = name2 + ': ';
|
||||||
|
|
||||||
@@ -1708,9 +1710,13 @@ async function Generate(type, automatic_trigger, force_name2) {
|
|||||||
if (!data.error) {
|
if (!data.error) {
|
||||||
//const getData = await response.json();
|
//const getData = await response.json();
|
||||||
var getMessage = "";
|
var getMessage = "";
|
||||||
if (main_api == 'kobold') {
|
if (main_api == 'kobold' && !horde_settings.use_horde) {
|
||||||
getMessage = data.results[0].text;
|
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];
|
getMessage = data.data[0];
|
||||||
if (getMessage == null || data.error) {
|
if (getMessage == null || data.error) {
|
||||||
activateSendButtons();
|
activateSendButtons();
|
||||||
@@ -1718,7 +1724,8 @@ async function Generate(type, automatic_trigger, force_name2) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
getMessage = getMessage.substring(finalPromt.length);
|
getMessage = getMessage.substring(finalPromt.length);
|
||||||
} else if (main_api == 'novel') {
|
}
|
||||||
|
else if (main_api == 'novel') {
|
||||||
getMessage = data.output;
|
getMessage = data.output;
|
||||||
}
|
}
|
||||||
if (main_api == 'openai') {
|
if (main_api == 'openai') {
|
||||||
@@ -1795,6 +1802,7 @@ async function Generate(type, automatic_trigger, force_name2) {
|
|||||||
|
|
||||||
activateSendButtons();
|
activateSendButtons();
|
||||||
showSwipeButtons();
|
showSwipeButtons();
|
||||||
|
setGenerationProgress(0);
|
||||||
$('.mes_edit:last').show();
|
$('.mes_edit:last').show();
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1802,6 +1810,7 @@ async function Generate(type, automatic_trigger, force_name2) {
|
|||||||
$("#send_textarea").removeAttr('disabled');
|
$("#send_textarea").removeAttr('disabled');
|
||||||
is_send_press = false;
|
is_send_press = false;
|
||||||
activateSendButtons();
|
activateSendButtons();
|
||||||
|
setGenerationProgress(0);
|
||||||
console.log(exception);
|
console.log(exception);
|
||||||
console.log(jqXHR);
|
console.log(jqXHR);
|
||||||
};
|
};
|
||||||
@@ -2966,6 +2975,18 @@ function setGenerationFunction(func) {
|
|||||||
extension_generation_function = 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 () {
|
window["TavernAI"].getContext = function () {
|
||||||
return {
|
return {
|
||||||
chat: chat,
|
chat: chat,
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { saveSettingsDebounced, changeMainAPI, callPopup } from "../script.js";
|
import { saveSettingsDebounced, changeMainAPI, callPopup, setGenerationProgress } from "../script.js";
|
||||||
import { delay } from "./utils.js";
|
import { delay } from "./utils.js";
|
||||||
|
|
||||||
export {
|
export {
|
||||||
@@ -19,7 +19,7 @@ let horde_settings = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const MAX_RETRIES = 100;
|
const MAX_RETRIES = 100;
|
||||||
const CHECK_INTERVAL = 1000;
|
const CHECK_INTERVAL = 3000;
|
||||||
|
|
||||||
async function getWorkers() {
|
async function getWorkers() {
|
||||||
const response = await fetch('https://horde.koboldai.net/api/v2/workers?type=text');
|
const response = await fetch('https://horde.koboldai.net/api/v2/workers?type=text');
|
||||||
@@ -27,12 +27,23 @@ async function getWorkers() {
|
|||||||
return data;
|
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) {
|
async function adjustHordeGenerationParams(max_context_length, max_length) {
|
||||||
const workers = await getWorkers();
|
const workers = await getWorkers();
|
||||||
let maxContextLength = max_context_length;
|
let maxContextLength = max_context_length;
|
||||||
let maxLength = max_length;
|
let maxLength = max_length;
|
||||||
let availableWorkers = [];
|
let availableWorkers = [];
|
||||||
let selectedModel = models.find(m => m.name == horde_settings.model);
|
let selectedModel = validateHordeModel();
|
||||||
|
|
||||||
if (!selectedModel) {
|
if (!selectedModel) {
|
||||||
return { maxContextLength, maxLength };
|
return { maxContextLength, maxLength };
|
||||||
@@ -54,13 +65,21 @@ async function adjustHordeGenerationParams(max_context_length, max_length) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function generateHorde(prompt, params) {
|
async function generateHorde(prompt, params) {
|
||||||
|
validateHordeModel();
|
||||||
delete params.prompt;
|
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 = {
|
const payload = {
|
||||||
"prompt": prompt,
|
"prompt": prompt,
|
||||||
"params": params,
|
"params": params,
|
||||||
"trusted_workers": false,
|
//"trusted_workers": false,
|
||||||
"slow_workers": false,
|
//"slow_workers": false,
|
||||||
"models": [horde_settings.model],
|
"models": [horde_settings.model],
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -81,11 +100,10 @@ async function generateHorde(prompt, params) {
|
|||||||
|
|
||||||
const responseJson = await response.json();
|
const responseJson = await response.json();
|
||||||
const task_id = responseJson.id;
|
const task_id = responseJson.id;
|
||||||
|
let queue_position_first = null;
|
||||||
console.log(`Horde task id = ${task_id}`);
|
console.log(`Horde task id = ${task_id}`);
|
||||||
|
|
||||||
for (let retryNumber = 0; retryNumber < MAX_RETRIES; retryNumber++) {
|
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}`, {
|
const statusCheckResponse = await fetch(`https://horde.koboldai.net/api/v2/generate/text/status/${task_id}`, {
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -96,12 +114,27 @@ async function generateHorde(prompt, params) {
|
|||||||
const statusCheckJson = await statusCheckResponse.json();
|
const statusCheckJson = await statusCheckResponse.json();
|
||||||
console.log(statusCheckJson);
|
console.log(statusCheckJson);
|
||||||
|
|
||||||
if (statusCheckJson.done) {
|
if (statusCheckJson.done && Array.isArray(statusCheckJson.generations) && statusCheckJson.generations.length) {
|
||||||
const generatedText = statusCheckJson.generations[0];
|
setGenerationProgress(100);
|
||||||
|
const generatedText = statusCheckJson.generations[0].text;
|
||||||
console.log(generatedText);
|
console.log(generatedText);
|
||||||
return 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() {
|
async function checkHordeStatus() {
|
||||||
@@ -169,4 +202,6 @@ $(document).ready(function () {
|
|||||||
horde_settings.auto_adjust = !!$(this).prop("checked");
|
horde_settings.auto_adjust = !!$(this).prop("checked");
|
||||||
saveSettingsDebounced();
|
saveSettingsDebounced();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$("#horde_refresh").on("click", getHordeModels);
|
||||||
})
|
})
|
@@ -1272,6 +1272,17 @@ input[type=search]:focus::-webkit-search-cancel-button {
|
|||||||
display: inline-block;
|
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 {
|
#softprompt {
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user