Use Express router for horde endpoint
This commit is contained in:
parent
414c9bd5fb
commit
2e990bf336
|
@ -3609,7 +3609,7 @@ require('./src/endpoints/content-manager').registerEndpoints(app, jsonParser);
|
|||
require('./src/endpoints/stable-diffusion').registerEndpoints(app, jsonParser);
|
||||
|
||||
// LLM and SD Horde generation
|
||||
require('./src/endpoints/horde').registerEndpoints(app, jsonParser);
|
||||
app.use('/api/horde', require('./src/endpoints/horde').router);
|
||||
|
||||
// Vector storage DB
|
||||
require('./src/endpoints/vectors').registerEndpoints(app, jsonParser);
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
const fetch = require('node-fetch').default;
|
||||
const express = require('express');
|
||||
const AIHorde = require('../ai_horde');
|
||||
const { getVersion, delay } = require('../util');
|
||||
const { readSecret, SECRET_KEYS } = require('./secrets');
|
||||
const { jsonParser } = require('../express-common');
|
||||
|
||||
const ANONYMOUS_KEY = '0000000000';
|
||||
|
||||
|
@ -52,13 +54,9 @@ function sanitizeHordeImagePrompt(prompt) {
|
|||
return prompt;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {import("express").Express} app
|
||||
* @param {any} jsonParser
|
||||
*/
|
||||
function registerEndpoints(app, jsonParser) {
|
||||
app.post('/api/horde/generate-text', jsonParser, async (request, response) => {
|
||||
const router = express.Router();
|
||||
|
||||
router.post('/generate-text', jsonParser, async (request, response) => {
|
||||
const api_key_horde = readSecret(SECRET_KEYS.HORDE) || ANONYMOUS_KEY;
|
||||
const url = 'https://horde.koboldai.net/api/v2/generate/text/async';
|
||||
|
||||
|
@ -88,7 +86,7 @@ function registerEndpoints(app, jsonParser) {
|
|||
}
|
||||
});
|
||||
|
||||
app.post('/api/horde/sd-samplers', jsonParser, async (_, response) => {
|
||||
router.post('/sd-samplers', jsonParser, async (_, response) => {
|
||||
try {
|
||||
const ai_horde = await getHordeClient();
|
||||
const samplers = Object.values(ai_horde.ModelGenerationInputStableSamplers);
|
||||
|
@ -99,7 +97,7 @@ function registerEndpoints(app, jsonParser) {
|
|||
}
|
||||
});
|
||||
|
||||
app.post('/api/horde/sd-models', jsonParser, async (_, response) => {
|
||||
router.post('/sd-models', jsonParser, async (_, response) => {
|
||||
try {
|
||||
const ai_horde = await getHordeClient();
|
||||
const models = await ai_horde.getModels();
|
||||
|
@ -110,7 +108,7 @@ function registerEndpoints(app, jsonParser) {
|
|||
}
|
||||
});
|
||||
|
||||
app.post('/api/horde/caption-image', jsonParser, async (request, response) => {
|
||||
router.post('/caption-image', jsonParser, async (request, response) => {
|
||||
try {
|
||||
const api_key_horde = readSecret(SECRET_KEYS.HORDE) || ANONYMOUS_KEY;
|
||||
const ai_horde = await getHordeClient();
|
||||
|
@ -162,7 +160,7 @@ function registerEndpoints(app, jsonParser) {
|
|||
}
|
||||
});
|
||||
|
||||
app.post('/api/horde/user-info', jsonParser, async (_, response) => {
|
||||
router.post('/user-info', jsonParser, async (_, response) => {
|
||||
const api_key_horde = readSecret(SECRET_KEYS.HORDE);
|
||||
|
||||
if (!api_key_horde) {
|
||||
|
@ -179,7 +177,7 @@ function registerEndpoints(app, jsonParser) {
|
|||
}
|
||||
});
|
||||
|
||||
app.post('/api/horde/generate-image', jsonParser, async (request, response) => {
|
||||
router.post('/generate-image', jsonParser, async (request, response) => {
|
||||
if (!request.body.prompt) {
|
||||
return response.sendStatus(400);
|
||||
}
|
||||
|
@ -265,8 +263,5 @@ function registerEndpoints(app, jsonParser) {
|
|||
return response.sendStatus(500);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
registerEndpoints,
|
||||
};
|
||||
module.exports = { router };
|
||||
|
|
Loading…
Reference in New Issue