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:
@@ -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);
|
||||
})
|
Reference in New Issue
Block a user