#895 Move AI Horde connection to related endpoints

This commit is contained in:
Cohee 2023-08-07 19:34:10 +03:00
parent 7384cb07a4
commit 5f97a52d58
1 changed files with 13 additions and 4 deletions

View File

@ -123,10 +123,15 @@ const allowKeysExposure = config.allowKeysExposure;
const axios = require('axios'); const axios = require('axios');
const tiktoken = require('@dqbd/tiktoken'); const tiktoken = require('@dqbd/tiktoken');
const WebSocket = require('ws'); const WebSocket = require('ws');
const AIHorde = require("./src/horde");
const ai_horde = new AIHorde({ function getHordeClient() {
const AIHorde = require("./src/horde");
const ai_horde = new AIHorde({
client_agent: getVersion()?.agent || 'SillyTavern:UNKNOWN:Cohee#1207', client_agent: getVersion()?.agent || 'SillyTavern:UNKNOWN:Cohee#1207',
}); });
return ai_horde;
}
const ipMatching = require('ip-matching'); const ipMatching = require('ip-matching');
const yauzl = require('yauzl'); const yauzl = require('yauzl');
@ -3838,6 +3843,7 @@ app.post('/viewsecrets', jsonParser, async (_, response) => {
app.post('/horde_samplers', jsonParser, async (_, response) => { app.post('/horde_samplers', jsonParser, async (_, response) => {
try { try {
const ai_horde = getHordeClient();
const samplers = Object.values(ai_horde.ModelGenerationInputStableSamplers); const samplers = Object.values(ai_horde.ModelGenerationInputStableSamplers);
response.send(samplers); response.send(samplers);
} catch (error) { } catch (error) {
@ -3848,6 +3854,7 @@ app.post('/horde_samplers', jsonParser, async (_, response) => {
app.post('/horde_models', jsonParser, async (_, response) => { app.post('/horde_models', jsonParser, async (_, response) => {
try { try {
const ai_horde = getHordeClient();
const models = await ai_horde.getModels(); const models = await ai_horde.getModels();
response.send(models); response.send(models);
} catch (error) { } catch (error) {
@ -3864,6 +3871,7 @@ app.post('/horde_userinfo', jsonParser, async (_, response) => {
} }
try { try {
const ai_horde = getHordeClient();
const user = await ai_horde.findUser({ token: api_key_horde }); const user = await ai_horde.findUser({ token: api_key_horde });
return response.send(user); return response.send(user);
} catch (error) { } catch (error) {
@ -3879,6 +3887,7 @@ app.post('/horde_generateimage', jsonParser, async (request, response) => {
console.log('Stable Horde request:', request.body); console.log('Stable Horde request:', request.body);
try { try {
const ai_horde = getHordeClient();
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}`,