mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
View Horde kudos
This commit is contained in:
@ -1023,6 +1023,9 @@
|
|||||||
<h5>Get it here: <a target="_blank" href="https://horde.koboldai.net/register">Register</a><br>
|
<h5>Get it here: <a target="_blank" href="https://horde.koboldai.net/register">Register</a><br>
|
||||||
Enter <span class="monospace">0000000000</span> to use anonymous mode.
|
Enter <span class="monospace">0000000000</span> to use anonymous mode.
|
||||||
</h5>
|
</h5>
|
||||||
|
<div>
|
||||||
|
<a id="horde_kudos" href="javascript:void(0);">View my Kudos</a>
|
||||||
|
</div>
|
||||||
<div class="flex-container">
|
<div class="flex-container">
|
||||||
<input id="horde_api_key" name="horde_api_key" class="text_pole flex1" maxlength="500" type="text" placeholder="0000000000" autocomplete="off">
|
<input id="horde_api_key" name="horde_api_key" class="text_pole flex1" maxlength="500" type="text" placeholder="0000000000" autocomplete="off">
|
||||||
<div title="Clear your API key" class="menu_button fa-solid fa-circle-xmark clear-api-key" data-key="api_key_horde"></div>
|
<div title="Clear your API key" class="menu_button fa-solid fa-circle-xmark clear-api-key" data-key="api_key_horde"></div>
|
||||||
@ -2644,7 +2647,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
// Configure toast library:
|
// Configure toast library:
|
||||||
toastr.options.escapeHtml = true; // Prevent raw HTML inserts
|
toastr.options.escapeHtml = false; // Prevent raw HTML inserts
|
||||||
toastr.options.timeOut = 4000; // How long the toast will display without user interaction
|
toastr.options.timeOut = 4000; // How long the toast will display without user interaction
|
||||||
toastr.options.extendedTimeOut = 10000; // How long the toast will display after a user hovers over it
|
toastr.options.extendedTimeOut = 10000; // How long the toast will display after a user hovers over it
|
||||||
toastr.options.progressBar = true; // Visually indicate how long before a toast expires.
|
toastr.options.progressBar = true; // Visually indicate how long before a toast expires.
|
||||||
|
@ -185,6 +185,28 @@ function loadHordeSettings(settings) {
|
|||||||
$('#horde_auto_adjust_context_length').prop("checked", horde_settings.auto_adjust_context_length);
|
$('#horde_auto_adjust_context_length').prop("checked", horde_settings.auto_adjust_context_length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function showKudos() {
|
||||||
|
const response = await fetch('/horde_userinfo', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: getRequestHeaders(),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
toastr.warning('Could not load user info from Horde. Please try again later.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await response.json();
|
||||||
|
|
||||||
|
if (data.anonymous) {
|
||||||
|
toastr.info('You are in anonymous mode. Set your personal Horde API key to see kudos.')
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('Horde user data', data);
|
||||||
|
toastr.info(`${data.username}<br>Kudos: ${data.kudos}`);
|
||||||
|
}
|
||||||
|
|
||||||
jQuery(function () {
|
jQuery(function () {
|
||||||
$("#use_horde").on("input", async function () {
|
$("#use_horde").on("input", async function () {
|
||||||
horde_settings.use_horde = !!$(this).prop("checked");
|
horde_settings.use_horde = !!$(this).prop("checked");
|
||||||
@ -225,4 +247,5 @@ jQuery(function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
$("#horde_refresh").on("click", getHordeModels);
|
$("#horde_refresh").on("click", getHordeModels);
|
||||||
|
$("#horde_kudos").on("click", showKudos);
|
||||||
})
|
})
|
22
server.js
22
server.js
@ -2921,11 +2921,29 @@ app.post('/horde_models', jsonParser, async (_, response) => {
|
|||||||
response.send(models);
|
response.send(models);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.post('/horde_userinfo', jsonParser, async (_, response) => {
|
||||||
|
const api_key_horde = readSecret(SECRET_KEYS.HORDE);
|
||||||
|
|
||||||
|
if (!api_key_horde) {
|
||||||
|
return response.send({ anonymous: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const user = await ai_horde.findUser({ token: api_key_horde });
|
||||||
|
return response.send(user);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
return response.sendStatus(500);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
app.post('/horde_generateimage', jsonParser, async (request, response) => {
|
app.post('/horde_generateimage', jsonParser, async (request, response) => {
|
||||||
const MAX_ATTEMPTS = 100;
|
const MAX_ATTEMPTS = 100;
|
||||||
const CHECK_INTERVAL = 3000;
|
const CHECK_INTERVAL = 3000;
|
||||||
const api_key_horde = readSecret(SECRET_KEYS.HORDE) || ANONYMOUS_KEY;
|
const api_key_horde = readSecret(SECRET_KEYS.HORDE) || ANONYMOUS_KEY;
|
||||||
console.log('Stable Horde request:', request.body);
|
console.log('Stable Horde request:', request.body);
|
||||||
|
|
||||||
|
try {
|
||||||
const generation = await ai_horde.postAsyncImageGenerate(
|
const generation = await ai_horde.postAsyncImageGenerate(
|
||||||
{
|
{
|
||||||
prompt: `${request.body.prompt_prefix} ${request.body.prompt} ### ${request.body.negative_prompt}`,
|
prompt: `${request.body.prompt_prefix} ${request.body.prompt} ### ${request.body.negative_prompt}`,
|
||||||
@ -2969,6 +2987,10 @@ app.post('/horde_generateimage', jsonParser, async (request, response) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return response.sendStatus(504);
|
return response.sendStatus(504);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
return response.sendStatus(500);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function writeSecret(key, value) {
|
function writeSecret(key, value) {
|
||||||
|
Reference in New Issue
Block a user