Refactor API keys handling. Remove ST hosting from colab

This commit is contained in:
SillyLossy
2023-05-11 21:08:22 +03:00
parent 9b80c861f0
commit e374703798
15 changed files with 365 additions and 514 deletions

View File

@@ -1,4 +1,4 @@
import { saveSettingsDebounced, changeMainAPI, callPopup, setGenerationProgress, CLIENT_VERSION } from "../script.js";
import { saveSettingsDebounced, changeMainAPI, callPopup, setGenerationProgress, CLIENT_VERSION, getRequestHeaders } from "../script.js";
import { delay } from "./utils.js";
export {
@@ -14,7 +14,6 @@ export {
let models = [];
let horde_settings = {
api_key: '0000000000',
models: [],
use_horde: false,
auto_adjust_response_length: true,
@@ -30,14 +29,6 @@ const getRequestArgs = () => ({
"Client-Agent": CLIENT_VERSION,
}
});
const postRequestArgs = () => ({
method: "POST",
headers: {
"Content-Type": "application/json",
"apikey": horde_settings.api_key,
"Client-Agent": CLIENT_VERSION,
}
});
async function getWorkers() {
const response = await fetch('https://horde.koboldai.net/api/v2/workers?type=text', getRequestArgs());
@@ -107,8 +98,12 @@ async function generateHorde(prompt, params) {
"models": horde_settings.models,
};
const response = await fetch("https://horde.koboldai.net/api/v2/generate/text/async", {
...postRequestArgs(),
const response = await fetch("/generate_horde", {
method: 'POST',
headers: {
...getRequestHeaders(),
"Client-Agent": CLIENT_VERSION,
},
body: JSON.stringify(payload)
});
@@ -176,12 +171,6 @@ async function getHordeModels() {
if (horde_settings.models.length && models.filter(m => horde_settings.models.includes(m.name)).length === 0) {
horde_settings.models = [];
}
// if no models preselected - select a first one in dropdown
/*if (Array.isArray(horde_settings.models) || horde_settings.models.length == 0) {
$('#horde_model').first()
horde_settings.models = [.find(":selected").val()];
}*/
}
function loadHordeSettings(settings) {
@@ -190,7 +179,6 @@ function loadHordeSettings(settings) {
}
$('#use_horde').prop("checked", horde_settings.use_horde).trigger('input');
$('#horde_api_key').val(horde_settings.api_key);
$('#horde_auto_adjust_response_length').prop("checked", horde_settings.auto_adjust_response_length);
$('#horde_auto_adjust_context_length').prop("checked", horde_settings.auto_adjust_context_length);
}
@@ -219,11 +207,6 @@ jQuery(function () {
saveSettingsDebounced();
});
$("#horde_api_key").on("input", function () {
horde_settings.api_key = $(this).val();
saveSettingsDebounced();
});
$("#horde_auto_adjust_response_length").on("input", function () {
horde_settings.auto_adjust_response_length = !!$(this).prop("checked");
saveSettingsDebounced();