Move endpoints into their own folder

This commit is contained in:
valadaptive 2023-12-03 08:52:43 -05:00
parent 604e62298c
commit 4919a2e9a2
20 changed files with 48 additions and 48 deletions

View File

@ -51,12 +51,12 @@ util.inspect.defaultOptions.maxStringLength = null;
// local library imports
const basicAuthMiddleware = require('./src/middleware/basicAuthMiddleware');
const characterCardParser = require('./src/character-card-parser.js');
const contentManager = require('./src/content-manager');
const contentManager = require('./src/endpoints/content-manager');
const statsHelpers = require('./statsHelpers.js');
const { readSecret, migrateSecrets, SECRET_KEYS } = require('./src/secrets');
const { readSecret, migrateSecrets, SECRET_KEYS } = require('./src/endpoints/secrets');
const { delay, getVersion, deepMerge, getConfigValue, color, uuidv4 } = require('./src/util');
const { invalidateThumbnail, ensureThumbnailCache } = require('./src/thumbnails');
const { getTokenizerModel, getTiktokenTokenizer, loadTokenizers, TEXT_COMPLETION_MODELS, getSentencepiceTokenizer, sentencepieceTokenizers } = require('./src/tokenizers');
const { invalidateThumbnail, ensureThumbnailCache } = require('./src/endpoints/thumbnails');
const { getTokenizerModel, getTiktokenTokenizer, loadTokenizers, TEXT_COMPLETION_MODELS, getSentencepiceTokenizer, sentencepieceTokenizers } = require('./src/endpoints/tokenizers');
const { convertClaudePrompt } = require('./src/chat-completion');
// Work around a node v20.0.0, v20.1.0, and v20.2.0 bug. The issue was fixed in v20.3.0.
@ -2002,7 +2002,7 @@ app.post('/importcharacter', urlencodedParser, async function (request, response
let uploadPath = path.join(UPLOADS_PATH, filedata.filename);
var format = request.body.file_type;
const defaultAvatarPath = './public/img/ai4.png';
const { importRisuSprites } = require('./src/sprites');
const { importRisuSprites } = require('./src/endpoints/sprites');
//console.log(format);
if (filedata) {
if (format == 'json') {
@ -3576,55 +3576,55 @@ async function fetchJSON(url, args = {}) {
// ** END **
// OpenAI API
require('./src/openai').registerEndpoints(app, jsonParser, urlencodedParser);
require('./src/endpoints/openai').registerEndpoints(app, jsonParser, urlencodedParser);
// Tokenizers
require('./src/tokenizers').registerEndpoints(app, jsonParser);
require('./src/endpoints/tokenizers').registerEndpoints(app, jsonParser);
// Preset management
require('./src/presets').registerEndpoints(app, jsonParser);
require('./src/endpoints/presets').registerEndpoints(app, jsonParser);
// Secrets managemenet
require('./src/secrets').registerEndpoints(app, jsonParser);
require('./src/endpoints/secrets').registerEndpoints(app, jsonParser);
// Thumbnail generation
require('./src/thumbnails').registerEndpoints(app, jsonParser);
require('./src/endpoints/thumbnails').registerEndpoints(app, jsonParser);
// NovelAI generation
require('./src/novelai').registerEndpoints(app, jsonParser);
require('./src/endpoints/novelai').registerEndpoints(app, jsonParser);
// Third-party extensions
require('./src/extensions').registerEndpoints(app, jsonParser);
require('./src/endpoints/extensions').registerEndpoints(app, jsonParser);
// Asset management
require('./src/assets').registerEndpoints(app, jsonParser);
require('./src/endpoints/assets').registerEndpoints(app, jsonParser);
// Character sprite management
require('./src/sprites').registerEndpoints(app, jsonParser, urlencodedParser);
require('./src/endpoints/sprites').registerEndpoints(app, jsonParser, urlencodedParser);
// Custom content management
require('./src/content-manager').registerEndpoints(app, jsonParser);
require('./src/endpoints/content-manager').registerEndpoints(app, jsonParser);
// Stable Diffusion generation
require('./src/stable-diffusion').registerEndpoints(app, jsonParser);
require('./src/endpoints/stable-diffusion').registerEndpoints(app, jsonParser);
// LLM and SD Horde generation
require('./src/horde').registerEndpoints(app, jsonParser);
require('./src/endpoints/horde').registerEndpoints(app, jsonParser);
// Vector storage DB
require('./src/vectors').registerEndpoints(app, jsonParser);
require('./src/endpoints/vectors').registerEndpoints(app, jsonParser);
// Chat translation
require('./src/translate').registerEndpoints(app, jsonParser);
require('./src/endpoints/translate').registerEndpoints(app, jsonParser);
// Emotion classification
require('./src/classify').registerEndpoints(app, jsonParser);
require('./src/endpoints/classify').registerEndpoints(app, jsonParser);
// Image captioning
require('./src/caption').registerEndpoints(app, jsonParser);
require('./src/endpoints/caption').registerEndpoints(app, jsonParser);
// Web search extension
require('./src/serpapi').registerEndpoints(app, jsonParser);
require('./src/endpoints/serpapi').registerEndpoints(app, jsonParser);
const tavernUrl = new URL(
(cliArguments.ssl ? 'https://' : 'http://') +

View File

@ -4,7 +4,7 @@ const sanitize = require('sanitize-filename');
const fetch = require('node-fetch').default;
const { finished } = require('stream/promises');
const writeFileSyncAtomic = require('write-file-atomic').sync;
const { DIRECTORIES, UNSAFE_EXTENSIONS } = require('./constants');
const { DIRECTORIES, UNSAFE_EXTENSIONS } = require('../constants');
const VALID_CATEGORIES = ['bgm', 'ambient', 'blip', 'live2d'];

View File

@ -9,7 +9,7 @@ function registerEndpoints(app, jsonParser) {
try {
const { image } = req.body;
const module = await import('./transformers.mjs');
const module = await import('../transformers.mjs');
const rawImage = await module.default.getRawImage(image);
if (!rawImage) {

View File

@ -9,7 +9,7 @@ function registerEndpoints(app, jsonParser) {
app.post('/api/extra/classify/labels', jsonParser, async (req, res) => {
try {
const module = await import('./transformers.mjs');
const module = await import('../transformers.mjs');
const pipe = await module.default.getPipeline(TASK);
const result = Object.keys(pipe.model.config.label2id);
return res.json({ labels: result });
@ -27,7 +27,7 @@ function registerEndpoints(app, jsonParser) {
if (Object.hasOwn(cacheObject, text)) {
return cacheObject[text];
} else {
const module = await import('./transformers.mjs');
const module = await import('../transformers.mjs');
const pipe = await module.default.getPipeline(TASK);
const result = await pipe(text, { topk: 5 });
result.sort((a, b) => b.score - a.score);

View File

@ -2,11 +2,11 @@ const fs = require('fs');
const path = require('path');
const fetch = require('node-fetch').default;
const sanitize = require('sanitize-filename');
const { getConfigValue } = require('./util');
const { getConfigValue } = require('../util');
const contentDirectory = path.join(process.cwd(), 'default/content');
const contentLogPath = path.join(contentDirectory, 'content.log');
const contentIndexPath = path.join(contentDirectory, 'index.json');
const { DIRECTORIES } = require('./constants');
const { DIRECTORIES } = require('../constants');
const presetFolders = [DIRECTORIES.koboldAI_Settings, DIRECTORIES.openAI_Settings, DIRECTORIES.novelAI_Settings, DIRECTORIES.textGen_Settings];
/**

View File

@ -2,7 +2,7 @@ const path = require('path');
const fs = require('fs');
const { default: simpleGit } = require('simple-git');
const sanitize = require('sanitize-filename');
const { DIRECTORIES } = require('./constants');
const { DIRECTORIES } = require('../constants');
/**
* This function extracts the extension information from the manifest file.

View File

@ -1,6 +1,6 @@
const fetch = require('node-fetch').default;
const AIHorde = require('./ai_horde');
const { getVersion, delay } = require('./util');
const AIHorde = require('../ai_horde');
const { getVersion, delay } = require('../util');
const { readSecret, SECRET_KEYS } = require('./secrets');
const ANONYMOUS_KEY = '0000000000';

View File

@ -2,7 +2,7 @@ const fetch = require('node-fetch').default;
const util = require('util');
const { Readable } = require('stream');
const { readSecret, SECRET_KEYS } = require('./secrets');
const { readAllChunks, extractFileFromZipBuffer } = require('./util');
const { readAllChunks, extractFileFromZipBuffer } = require('../util');
const API_NOVELAI = 'https://api.novelai.net';

View File

@ -2,7 +2,7 @@ const fs = require('fs');
const path = require('path');
const sanitize = require('sanitize-filename');
const writeFileAtomicSync = require('write-file-atomic').sync;
const { DIRECTORIES } = require('./constants');
const { DIRECTORIES } = require('../constants');
const { getDefaultPresetFile, getDefaultPresets } = require('./content-manager');
/**

View File

@ -1,6 +1,6 @@
const fs = require('fs');
const path = require('path');
const { getConfigValue } = require('./util');
const { getConfigValue } = require('../util');
const writeFileAtomicSync = require('write-file-atomic').sync;
const SECRETS_FILE = path.join(process.cwd(), './secrets.json');

View File

@ -4,8 +4,8 @@ const path = require('path');
const mime = require('mime-types');
const sanitize = require('sanitize-filename');
const writeFileAtomicSync = require('write-file-atomic').sync;
const { DIRECTORIES, UPLOADS_PATH } = require('./constants');
const { getImageBuffers } = require('./util');
const { DIRECTORIES, UPLOADS_PATH } = require('../constants');
const { getImageBuffers } = require('../util');
/**
* Gets the path to the sprites folder for the provided character name

View File

@ -1,8 +1,8 @@
const fetch = require('node-fetch').default;
const sanitize = require('sanitize-filename');
const { getBasicAuthHeader, delay } = require('./util');
const { getBasicAuthHeader, delay } = require('../util.js');
const fs = require('fs');
const { DIRECTORIES } = require('./constants.js');
const { DIRECTORIES } = require('../constants.js');
const writeFileAtomicSync = require('write-file-atomic').sync;
/**
@ -341,7 +341,7 @@ function registerEndpoints(app, jsonParser) {
try {
const task = 'text-generation';
const module = await import('./transformers.mjs');
const module = await import('../transformers.mjs');
const pipe = await module.default.getPipeline(task);
const result = await pipe(prompt, { num_beams: 1, max_new_tokens: 256, do_sample: true });

View File

@ -3,8 +3,8 @@ const path = require('path');
const sanitize = require('sanitize-filename');
const jimp = require('jimp');
const writeFileAtomicSync = require('write-file-atomic').sync;
const { DIRECTORIES } = require('./constants');
const { getConfigValue } = require('./util');
const { DIRECTORIES } = require('../constants');
const { getConfigValue } = require('../util');
/**
* Gets a path to thumbnail folder based on the type.

View File

@ -3,7 +3,7 @@ const path = require('path');
const { SentencePieceProcessor } = require('@agnai/sentencepiece-js');
const tiktoken = require('@dqbd/tiktoken');
const { Tokenizer } = require('@agnai/web-tokenizers');
const { convertClaudePrompt } = require('./chat-completion');
const { convertClaudePrompt } = require('../chat-completion');
const { readSecret, SECRET_KEYS } = require('./secrets');
/**

View File

@ -1,7 +1,7 @@
const fetch = require('node-fetch').default;
const https = require('https');
const { readSecret, SECRET_KEYS } = require('./secrets');
const { getConfigValue } = require('./util');
const { getConfigValue } = require('../util');
const DEEPLX_URL_DEFAULT = 'http://127.0.0.1:1188/translate';
const ONERING_URL_DEFAULT = 'http://127.0.0.1:4990/translate';

View File

@ -11,11 +11,11 @@ const sanitize = require('sanitize-filename');
async function getVector(source, text) {
switch (source) {
case 'openai':
return require('./openai-vectors').getOpenAIVector(text);
return require('../openai-vectors').getOpenAIVector(text);
case 'transformers':
return require('./embedding').getTransformersVector(text);
return require('../embedding').getTransformersVector(text);
case 'palm':
return require('./palm-vectors').getPaLMVector(text);
return require('../palm-vectors').getPaLMVector(text);
}
throw new Error(`Unknown vector source ${source}`);

View File

@ -1,5 +1,5 @@
const fetch = require('node-fetch').default;
const { SECRET_KEYS, readSecret } = require('./secrets');
const { SECRET_KEYS, readSecret } = require('./endpoints/secrets');
/**
* Gets the vector for the given text from OpenAI ada model

View File

@ -1,5 +1,5 @@
const fetch = require('node-fetch').default;
const { SECRET_KEYS, readSecret } = require('./secrets');
const { SECRET_KEYS, readSecret } = require('./endpoints/secrets');
/**
* Gets the vector for the given text from PaLM gecko model