mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
#252 Added client version to Horde headers
This commit is contained in:
@@ -222,6 +222,7 @@ let this_chid;
|
|||||||
let backgrounds = [];
|
let backgrounds = [];
|
||||||
const default_avatar = "img/ai4.png";
|
const default_avatar = "img/ai4.png";
|
||||||
const system_avatar = "img/five.png";
|
const system_avatar = "img/five.png";
|
||||||
|
export let CLIENT_VERSION = 'SillyTavern:UNKNOWN:Cohee#1207'; // For Horde header
|
||||||
let is_colab = false;
|
let is_colab = false;
|
||||||
let is_checked_colab = false;
|
let is_checked_colab = false;
|
||||||
let is_mes_reload_avatar = false;
|
let is_mes_reload_avatar = false;
|
||||||
@@ -368,6 +369,15 @@ $(document).ajaxError(function myErrorHandler(_, xhr) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
async function getClientVersion() {
|
||||||
|
try {
|
||||||
|
const response = await fetch('/version');
|
||||||
|
CLIENT_VERSION = await response.text();
|
||||||
|
} catch (err) {
|
||||||
|
console.log("Couldn't get client version", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function getTokenCount(str, padding = 0) {
|
function getTokenCount(str, padding = 0) {
|
||||||
let tokenizerType = power_user.tokenizer;
|
let tokenizerType = power_user.tokenizer;
|
||||||
|
|
||||||
@@ -552,6 +562,7 @@ $.ajaxPrefilter((options, originalOptions, xhr) => {
|
|||||||
///// initialization protocol ////////
|
///// initialization protocol ////////
|
||||||
$.get("/csrf-token").then((data) => {
|
$.get("/csrf-token").then((data) => {
|
||||||
token = data.token;
|
token = data.token;
|
||||||
|
getClientVersion();
|
||||||
getCharacters();
|
getCharacters();
|
||||||
getSettings("def");
|
getSettings("def");
|
||||||
sendSystemMessage(system_message_types.WELCOME);
|
sendSystemMessage(system_message_types.WELCOME);
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { saveSettingsDebounced, changeMainAPI, callPopup, setGenerationProgress } from "../script.js";
|
import { saveSettingsDebounced, changeMainAPI, callPopup, setGenerationProgress, CLIENT_VERSION } from "../script.js";
|
||||||
import { delay } from "./utils.js";
|
import { delay } from "./utils.js";
|
||||||
|
|
||||||
export {
|
export {
|
||||||
@@ -23,9 +23,23 @@ let horde_settings = {
|
|||||||
const MAX_RETRIES = 100;
|
const MAX_RETRIES = 100;
|
||||||
const CHECK_INTERVAL = 3000;
|
const CHECK_INTERVAL = 3000;
|
||||||
const MIN_AMOUNT_GEN = 16;
|
const MIN_AMOUNT_GEN = 16;
|
||||||
|
const getRequestArgs = () => ({
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
"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() {
|
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', getRequestArgs());
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
@@ -89,11 +103,7 @@ async function generateHorde(prompt, params) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const response = await fetch("https://horde.koboldai.net/api/v2/generate/text/async", {
|
const response = await fetch("https://horde.koboldai.net/api/v2/generate/text/async", {
|
||||||
method: "POST",
|
...postRequestArgs(),
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
"apikey": horde_settings.api_key,
|
|
||||||
},
|
|
||||||
body: JSON.stringify(payload)
|
body: JSON.stringify(payload)
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -109,12 +119,7 @@ async function generateHorde(prompt, params) {
|
|||||||
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++) {
|
||||||
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}`, getRequestArgs());
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
"apikey": horde_settings.api_key,
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const statusCheckJson = await statusCheckResponse.json();
|
const statusCheckJson = await statusCheckResponse.json();
|
||||||
console.log(statusCheckJson);
|
console.log(statusCheckJson);
|
||||||
@@ -145,13 +150,13 @@ async function generateHorde(prompt, params) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function checkHordeStatus() {
|
async function checkHordeStatus() {
|
||||||
const response = await fetch('https://horde.koboldai.net/api/v2/status/heartbeat');
|
const response = await fetch('https://horde.koboldai.net/api/v2/status/heartbeat', getRequestArgs());
|
||||||
return response.ok;
|
return response.ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getHordeModels() {
|
async function getHordeModels() {
|
||||||
$('#horde_model').empty();
|
$('#horde_model').empty();
|
||||||
const response = await fetch('https://horde.koboldai.net/api/v2/status/models?type=text');
|
const response = await fetch('https://horde.koboldai.net/api/v2/status/models?type=text', getRequestArgs());
|
||||||
models = await response.json();
|
models = await response.json();
|
||||||
|
|
||||||
for (const model of models) {
|
for (const model of models) {
|
||||||
|
13
server.js
13
server.js
@@ -305,6 +305,19 @@ app.get('/deviceinfo', function (request, response) {
|
|||||||
const deviceInfo = deviceDetector.parse(userAgent);
|
const deviceInfo = deviceDetector.parse(userAgent);
|
||||||
return response.send(deviceInfo);
|
return response.send(deviceInfo);
|
||||||
});
|
});
|
||||||
|
app.get('/version', function (_, response) {
|
||||||
|
let pkgVersion, gitRevision;
|
||||||
|
try {
|
||||||
|
const pkgJson = require('./package.json');
|
||||||
|
pkgVersion = pkgJson.version;
|
||||||
|
gitRevision = require('child_process')
|
||||||
|
.execSync('git rev-parse --short HEAD', { cwd: __dirname })
|
||||||
|
.toString().trim();
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
response.send(`SillyTavern:${gitRevision || pkgVersion}:Cohee#1207`)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
//**************Kobold api
|
//**************Kobold api
|
||||||
app.post("/generate", jsonParser, async function (request, response_generate = response) {
|
app.post("/generate", jsonParser, async function (request, response_generate = response) {
|
||||||
|
Reference in New Issue
Block a user