mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Initial commit
This commit is contained in:
326
src/bad-words.js
Normal file
326
src/bad-words.js
Normal file
@@ -0,0 +1,326 @@
|
||||
const badWordIds = [
|
||||
[60],
|
||||
[62],
|
||||
[544],
|
||||
[683],
|
||||
[696],
|
||||
[880],
|
||||
[905],
|
||||
[1008],
|
||||
[1019],
|
||||
[1084],
|
||||
[1092],
|
||||
[1181],
|
||||
[1184],
|
||||
[1254],
|
||||
[1447],
|
||||
[1570],
|
||||
[1656],
|
||||
[2194],
|
||||
[2470],
|
||||
[2479],
|
||||
[2498],
|
||||
[2947],
|
||||
[3138],
|
||||
[3291],
|
||||
[3455],
|
||||
[3725],
|
||||
[3851],
|
||||
[3891],
|
||||
[3921],
|
||||
[3951],
|
||||
[4207],
|
||||
[4299],
|
||||
[4622],
|
||||
[4681],
|
||||
[5013],
|
||||
[5032],
|
||||
[5180],
|
||||
[5218],
|
||||
[5290],
|
||||
[5413],
|
||||
[5456],
|
||||
[5709],
|
||||
[5749],
|
||||
[5774],
|
||||
[6038],
|
||||
[6257],
|
||||
[6334],
|
||||
[6660],
|
||||
[6904],
|
||||
[7082],
|
||||
[7086],
|
||||
[7254],
|
||||
[7444],
|
||||
[7748],
|
||||
[8001],
|
||||
[8088],
|
||||
[8168],
|
||||
[8562],
|
||||
[8605],
|
||||
[8795],
|
||||
[8850],
|
||||
[9014],
|
||||
[9102],
|
||||
[9259],
|
||||
[9318],
|
||||
[9336],
|
||||
[9502],
|
||||
[9686],
|
||||
[9793],
|
||||
[9855],
|
||||
[9899],
|
||||
[9955],
|
||||
[10148],
|
||||
[10174],
|
||||
[10943],
|
||||
[11326],
|
||||
[11337],
|
||||
[11661],
|
||||
[12004],
|
||||
[12084],
|
||||
[12159],
|
||||
[12520],
|
||||
[12977],
|
||||
[13380],
|
||||
[13488],
|
||||
[13663],
|
||||
[13811],
|
||||
[13976],
|
||||
[14412],
|
||||
[14598],
|
||||
[14767],
|
||||
[15640],
|
||||
[15707],
|
||||
[15775],
|
||||
[15830],
|
||||
[16079],
|
||||
[16354],
|
||||
[16369],
|
||||
[16445],
|
||||
[16595],
|
||||
[16614],
|
||||
[16731],
|
||||
[16943],
|
||||
[17278],
|
||||
[17281],
|
||||
[17548],
|
||||
[17555],
|
||||
[17981],
|
||||
[18022],
|
||||
[18095],
|
||||
[18297],
|
||||
[18413],
|
||||
[18736],
|
||||
[18772],
|
||||
[18990],
|
||||
[19181],
|
||||
[20095],
|
||||
[20197],
|
||||
[20481],
|
||||
[20629],
|
||||
[20871],
|
||||
[20879],
|
||||
[20924],
|
||||
[20977],
|
||||
[21375],
|
||||
[21382],
|
||||
[21391],
|
||||
[21687],
|
||||
[21810],
|
||||
[21828],
|
||||
[21938],
|
||||
[22367],
|
||||
[22372],
|
||||
[22734],
|
||||
[23405],
|
||||
[23505],
|
||||
[23734],
|
||||
[23741],
|
||||
[23781],
|
||||
[24237],
|
||||
[24254],
|
||||
[24345],
|
||||
[24430],
|
||||
[25416],
|
||||
[25896],
|
||||
[26119],
|
||||
[26635],
|
||||
[26842],
|
||||
[26991],
|
||||
[26997],
|
||||
[27075],
|
||||
[27114],
|
||||
[27468],
|
||||
[27501],
|
||||
[27618],
|
||||
[27655],
|
||||
[27720],
|
||||
[27829],
|
||||
[28052],
|
||||
[28118],
|
||||
[28231],
|
||||
[28532],
|
||||
[28571],
|
||||
[28591],
|
||||
[28653],
|
||||
[29013],
|
||||
[29547],
|
||||
[29650],
|
||||
[29925],
|
||||
[30522],
|
||||
[30537],
|
||||
[30996],
|
||||
[31011],
|
||||
[31053],
|
||||
[31096],
|
||||
[31148],
|
||||
[31258],
|
||||
[31350],
|
||||
[31379],
|
||||
[31422],
|
||||
[31789],
|
||||
[31830],
|
||||
[32214],
|
||||
[32666],
|
||||
[32871],
|
||||
[33094],
|
||||
[33376],
|
||||
[33440],
|
||||
[33805],
|
||||
[34368],
|
||||
[34398],
|
||||
[34417],
|
||||
[34418],
|
||||
[34419],
|
||||
[34476],
|
||||
[34494],
|
||||
[34607],
|
||||
[34758],
|
||||
[34761],
|
||||
[34904],
|
||||
[34993],
|
||||
[35117],
|
||||
[35138],
|
||||
[35237],
|
||||
[35487],
|
||||
[35830],
|
||||
[35869],
|
||||
[36033],
|
||||
[36134],
|
||||
[36320],
|
||||
[36399],
|
||||
[36487],
|
||||
[36586],
|
||||
[36676],
|
||||
[36692],
|
||||
[36786],
|
||||
[37077],
|
||||
[37594],
|
||||
[37596],
|
||||
[37786],
|
||||
[37982],
|
||||
[38475],
|
||||
[38791],
|
||||
[39083],
|
||||
[39258],
|
||||
[39487],
|
||||
[39822],
|
||||
[40116],
|
||||
[40125],
|
||||
[41000],
|
||||
[41018],
|
||||
[41256],
|
||||
[41305],
|
||||
[41361],
|
||||
[41447],
|
||||
[41449],
|
||||
[41512],
|
||||
[41604],
|
||||
[42041],
|
||||
[42274],
|
||||
[42368],
|
||||
[42696],
|
||||
[42767],
|
||||
[42804],
|
||||
[42854],
|
||||
[42944],
|
||||
[42989],
|
||||
[43134],
|
||||
[43144],
|
||||
[43189],
|
||||
[43521],
|
||||
[43782],
|
||||
[44082],
|
||||
[44162],
|
||||
[44270],
|
||||
[44308],
|
||||
[44479],
|
||||
[44524],
|
||||
[44965],
|
||||
[45114],
|
||||
[45301],
|
||||
[45382],
|
||||
[45443],
|
||||
[45472],
|
||||
[45488],
|
||||
[45507],
|
||||
[45564],
|
||||
[45662],
|
||||
[46265],
|
||||
[46267],
|
||||
[46275],
|
||||
[46295],
|
||||
[46462],
|
||||
[46468],
|
||||
[46576],
|
||||
[46694],
|
||||
[47093],
|
||||
[47384],
|
||||
[47389],
|
||||
[47446],
|
||||
[47552],
|
||||
[47686],
|
||||
[47744],
|
||||
[47916],
|
||||
[48064],
|
||||
[48167],
|
||||
[48392],
|
||||
[48471],
|
||||
[48664],
|
||||
[48701],
|
||||
[49021],
|
||||
[49193],
|
||||
[49236],
|
||||
[49550],
|
||||
[49694],
|
||||
[49806],
|
||||
[49824],
|
||||
[50001],
|
||||
[50256],
|
||||
[0],
|
||||
[1],
|
||||
]
|
||||
|
||||
const clioBadWordsId = [
|
||||
[3],
|
||||
[49356],
|
||||
[1431],
|
||||
[31715],
|
||||
[34387],
|
||||
[20765],
|
||||
[30702],
|
||||
[10691],
|
||||
[49333],
|
||||
[1266],
|
||||
[19438],
|
||||
[43145],
|
||||
[26523],
|
||||
[41471],
|
||||
[2936],
|
||||
]
|
||||
|
||||
module.exports = {
|
||||
badWordIds,
|
||||
clioBadWordsId,
|
||||
};
|
72
src/character-card-parser.js
Normal file
72
src/character-card-parser.js
Normal file
@@ -0,0 +1,72 @@
|
||||
const fs = require('fs');
|
||||
const json5 = require('json5');
|
||||
const ExifReader = require('exifreader');
|
||||
|
||||
const extract = require('png-chunks-extract');
|
||||
const PNGtext = require('png-chunk-text');
|
||||
|
||||
const utf8Decode = new TextDecoder('utf-8', { ignoreBOM: true });
|
||||
|
||||
const parse = async (cardUrl, format) => {
|
||||
let fileFormat;
|
||||
if (format === undefined) {
|
||||
if (cardUrl.indexOf('.webp') !== -1)
|
||||
fileFormat = 'webp';
|
||||
else
|
||||
fileFormat = 'png';
|
||||
}
|
||||
else
|
||||
fileFormat = format;
|
||||
|
||||
switch (fileFormat) {
|
||||
case 'webp':
|
||||
try {
|
||||
const exif_data = await ExifReader.load(fs.readFileSync(cardUrl));
|
||||
let char_data;
|
||||
|
||||
if (exif_data['UserComment']['description']) {
|
||||
let description = exif_data['UserComment']['description'];
|
||||
if (description === 'Undefined' && exif_data['UserComment'].value && exif_data['UserComment'].value.length === 1) {
|
||||
description = exif_data['UserComment'].value[0];
|
||||
}
|
||||
|
||||
try {
|
||||
json5.parse(description);
|
||||
char_data = description;
|
||||
} catch {
|
||||
const byteArr = description.split(",").map(Number);
|
||||
const uint8Array = new Uint8Array(byteArr);
|
||||
const char_data_string = utf8Decode.decode(uint8Array);
|
||||
char_data = char_data_string;
|
||||
}
|
||||
}
|
||||
else {
|
||||
console.log('No description found in EXIF data.');
|
||||
return false;
|
||||
}
|
||||
|
||||
return char_data;
|
||||
}
|
||||
catch (err) {
|
||||
console.log(err);
|
||||
return false;
|
||||
}
|
||||
case 'png':
|
||||
const buffer = fs.readFileSync(cardUrl);
|
||||
const chunks = extract(buffer);
|
||||
|
||||
const textChunks = chunks.filter(function (chunk) {
|
||||
return chunk.name === 'tEXt';
|
||||
}).map(function (chunk) {
|
||||
return PNGtext.decode(chunk.data);
|
||||
});
|
||||
|
||||
return Buffer.from(textChunks[0].text, 'base64').toString('utf8');
|
||||
default:
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
parse: parse
|
||||
};
|
1
src/claude.json
Normal file
1
src/claude.json
Normal file
File diff suppressed because one or more lines are too long
21
src/horde/LICENSE.md
Normal file
21
src/horde/LICENSE.md
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2022 ZeldaFan0225
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
2190
src/horde/index.d.ts
vendored
Normal file
2190
src/horde/index.d.ts
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1
src/horde/index.js
Normal file
1
src/horde/index.js
Normal file
File diff suppressed because one or more lines are too long
3
src/horde/index.mjs
Normal file
3
src/horde/index.mjs
Normal file
@@ -0,0 +1,3 @@
|
||||
import AIHorde from './index.js'
|
||||
export default AIHorde
|
||||
export { AIHorde }
|
41
src/middleware/basicAuthMiddleware.js
Normal file
41
src/middleware/basicAuthMiddleware.js
Normal file
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* When applied, this middleware will ensure the request contains the required header for basic authentication and only
|
||||
* allow access to the endpoint after successful authentication.
|
||||
*/
|
||||
|
||||
//const {dirname} = require('path');
|
||||
//const appDir = dirname(require.main.filename);
|
||||
//const config = require(appDir + '/config.conf');
|
||||
const path = require('path');
|
||||
const config = require(path.join(process.cwd(), './config.conf'));
|
||||
|
||||
const unauthorizedResponse = (res) => {
|
||||
res.set('WWW-Authenticate', 'Basic realm="SillyTavern", charset="UTF-8"');
|
||||
return res.status(401).send('Authentication required');
|
||||
};
|
||||
|
||||
const basicAuthMiddleware = function (request, response, callback) {
|
||||
const authHeader = request.headers.authorization;
|
||||
|
||||
if (!authHeader) {
|
||||
return unauthorizedResponse(response);
|
||||
}
|
||||
|
||||
const [scheme, credentials] = authHeader.split(' ');
|
||||
|
||||
if (scheme !== 'Basic' || !credentials) {
|
||||
return unauthorizedResponse(response);
|
||||
}
|
||||
|
||||
const [username, password] = Buffer.from(credentials, 'base64')
|
||||
.toString('utf8')
|
||||
.split(':');
|
||||
|
||||
if (username === config.basicAuthUser.username && password === config.basicAuthUser.password) {
|
||||
return callback();
|
||||
} else {
|
||||
return unauthorizedResponse(response);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = basicAuthMiddleware;
|
BIN
src/sentencepiece/nerdstash.model
Normal file
BIN
src/sentencepiece/nerdstash.model
Normal file
Binary file not shown.
BIN
src/sentencepiece/nerdstash_v2.model
Normal file
BIN
src/sentencepiece/nerdstash_v2.model
Normal file
Binary file not shown.
BIN
src/sentencepiece/tokenizer.model
Normal file
BIN
src/sentencepiece/tokenizer.model
Normal file
Binary file not shown.
Reference in New Issue
Block a user