diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..2a13caebf --- /dev/null +++ b/.editorconfig @@ -0,0 +1,11 @@ +root = true + +[*] +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true + +[*.{js, conf, json}] +charset = utf-8 +indent_style = space +indent_size = 4 \ No newline at end of file diff --git a/colab/GPU.ipynb b/colab/GPU.ipynb index caf939c44..194ba8dea 100644 --- a/colab/GPU.ipynb +++ b/colab/GPU.ipynb @@ -98,7 +98,7 @@ "!git clone https://github.com/Cohee1207/tts_samples\n", "!npm install -g localtunnel\n", "!pip install -r requirements-complete.txt\n", - "!pip install tensorflow==2.11\n", + "!pip install tensorflow==2.12\n", "\n", "\n", "cmd = f\"python server.py {' '.join(params)}\"\n", diff --git a/config.conf b/config.conf index 452636cca..b6f7dcb62 100644 --- a/config.conf +++ b/config.conf @@ -10,6 +10,11 @@ const enableExtensions = true; //Enables support for TavernAI-extras project const listen = true; // If true, Can be access from other device or PC. otherwise can be access only from hosting machine. const allowKeysExposure = false; // If true, private API keys could be fetched to the frontend. + +// If true, Allows insecure settings for listen, whitelist, and authentication. +// Change this setting only on "trusted networks". Do not change this value unless you are aware of the issues that can arise from changing this setting and configuring a insecure setting. +const securityOverride = false; + module.exports = { port, whitelist, @@ -21,4 +26,5 @@ module.exports = { listen, disableThumbnails, allowKeysExposure, + securityOverride, }; diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 59b67738d..9b91526c4 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -1,12 +1,13 @@ version: "3" services: - tavernai: + sillytavern: build: .. - container_name: tavernai - hostname: tavernai - image: tavernai/tavernai:latest + container_name: sillytavern + hostname: sillytavern + image: cohee1207/sillytavern:latest ports: - "8000:8000" volumes: - "./config:/home/node/app/config" - restart: unless-stopped \ No newline at end of file + - "./config.conf:/home/node/app/config.conf" + restart: unless-stopped diff --git a/package-lock.json b/package-lock.json index fb027e06a..e1aa5c111 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "sillytavern", - "version": "1.5.4", + "version": "1.6.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "sillytavern", - "version": "1.5.4", + "version": "1.6.0", "license": "AGPL-3.0", "dependencies": { "@dqbd/tiktoken": "^1.0.2", diff --git a/package.json b/package.json index 49548b351..af3fcd5de 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "type": "git", "url": "https://github.com/Cohee1207/SillyTavern.git" }, - "version": "1.5.4", + "version": "1.6.0", "scripts": { "start": "node server.js", "pkg": "pkg --compress Gzip ." diff --git a/public/backgrounds/_black.jpg b/public/backgrounds/_black.jpg new file mode 100644 index 000000000..a451bc161 Binary files /dev/null and b/public/backgrounds/_black.jpg differ diff --git a/public/backgrounds/_white.jpg b/public/backgrounds/_white.jpg new file mode 100644 index 000000000..a7c12e675 Binary files /dev/null and b/public/backgrounds/_white.jpg differ diff --git a/public/index.html b/public/index.html index 856cac5f0..b60005cc7 100644 --- a/public/index.html +++ b/public/index.html @@ -370,15 +370,6 @@ -
|
| Author's Note | Built-in extension that allows you to append notes that will be added to the context and steer the story and character in a specific direction. Because it's sent after the character description, it has a lot of weight. Thanks Ali឵#2222 for pitching the idea! | None |  |
| Character Backgrounds | Built-in extension to assign unique backgrounds to specific chats or groups. | None |
|
+| Stable Diffusion | Use local of cloud-based Stable Diffusion webUI API to generate images. 5 presets included ('you', 'your face', 'me', 'the story', and 'the last message'. Free mode also supported via `/sd (anything_here_)` command in the chat input bar. Most common StableDiffusion generation settings are customizable within the SillyTavern UI. | None |
|
+| Text-to-Speech | AI-generated voice will read back character messages on demand, or automatically read new messages they arrive. Supports ElevenLabs, Silero, and your device's TTS service. | None |
|
## UI/CSS/Quality of Life tweaks by RossAscends
diff --git a/server.js b/server.js
index 03e80abcd..66c3291c2 100644
--- a/server.js
+++ b/server.js
@@ -63,7 +63,9 @@ const utf8Encode = new TextEncoder();
const utf8Decode = new TextDecoder('utf-8', { ignoreBOM: true });
const commandExistsSync = require('command-exists').sync;
+const characterCardParser = require('./src/character-card-parser.js');
const config = require(path.join(process.cwd(), './config.conf'));
+
const server_port = process.env.SILLY_TAVERN_PORT || config.port;
const whitelistPath = path.join(process.cwd(), "./whitelist.txt");
@@ -913,61 +915,7 @@ async function tryReadImage(img_url, crop) {
}
async function charaRead(img_url, input_format) {
- let format;
- if (input_format === undefined) {
- if (img_url.indexOf('.webp') !== -1) {
- format = 'webp';
- } else {
- format = 'png';
- }
- } else {
- format = input_format;
- }
-
- switch (format) {
- case 'webp':
- try {
- const exif_data = await ExifReader.load(fs.readFileSync(img_url));
- 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(img_url);
- const chunks = extract(buffer);
-
- const textChunks = chunks.filter(function (chunk) {
- return chunk.name === 'tEXt';
- }).map(function (chunk) {
- return PNGtext.decode(chunk.data);
- });
- var base64DecodedData = Buffer.from(textChunks[0].text, 'base64').toString('utf8');
- return base64DecodedData;//textChunks[0].text;
- default:
- break;
- }
+ return characterCardParser.parse(img_url, input_format);
}
app.post("/getcharacters", jsonParser, function (request, response) {
@@ -1754,6 +1702,17 @@ app.post("/exportcharacter", jsonParser, async function (request, response) {
return response.sendStatus(400);
});
+app.post("/importgroupchat", urlencodedParser, function (request, response) {
+ try {
+ const filedata = request.file;
+ const chatname = humanizedISO8601DateTime();
+ fs.copyFileSync(`./uploads/${filedata.filename}`, (`${directories.groupChats}/${chatname}.jsonl`));
+ return response.send({ res: chatname });
+ } catch (error) {
+ console.error(error);
+ return response.send({ error: true });
+ }
+});
app.post("/importchat", urlencodedParser, function (request, response) {
if (!request.body) return response.sendStatus(400);
@@ -1763,9 +1722,8 @@ app.post("/importchat", urlencodedParser, function (request, response) {
let avatar_url = (request.body.avatar_url).replace('.png', '');
let ch_name = request.body.character_name;
if (filedata) {
-
if (format === 'json') {
- fs.readFile('./uploads/' + filedata.filename, 'utf8', (err, data) => {
+ fs.readFile(`./uploads/${filedata.filename}`, 'utf8', (err, data) => {
if (err) {
console.log(err);
@@ -1782,7 +1740,6 @@ app.post("/importchat", urlencodedParser, function (request, response) {
user_name: 'You',
character_name: ch_name,
create_date: humanizedISO8601DateTime(),
-
},
...history.msgs.map(
(message) => ({
@@ -1803,7 +1760,7 @@ app.post("/importchat", urlencodedParser, function (request, response) {
const errors = [];
newChats.forEach(chat => fs.writeFile(
- chatsPath + avatar_url + '/' + ch_name + ' - ' + humanizedISO8601DateTime() + ' imported.jsonl',
+ `${chatsPath + avatar_url}/${ch_name} - ${humanizedISO8601DateTime()} imported.jsonl`,
chat.map(JSON.stringify).join('\n'),
'utf8',
(err) => err ?? errors.push(err)
@@ -1832,8 +1789,7 @@ app.post("/importchat", urlencodedParser, function (request, response) {
let jsonData = json5.parse(line);
if (jsonData.user_name !== undefined || jsonData.name !== undefined) {
- //console.log(humanizedISO8601DateTime()+':/importchat copying chat as '+ch_name+' - '+humanizedISO8601DateTime()+'.jsonl');
- fs.copyFile('./uploads/' + filedata.filename, chatsPath + avatar_url + '/' + ch_name + ' - ' + humanizedISO8601DateTime() + '.jsonl', (err) => { //added character name and replaced Date.now() with humanizedISO8601DateTime
+ fs.copyFile(`./uploads/${filedata.filename}`, (`${chatsPath + avatar_url}/${ch_name} - ${humanizedISO8601DateTime()}.jsonl`), (err) => {
if (err) {
response.send({ error: true });
return console.log(err);
@@ -1849,9 +1805,7 @@ app.post("/importchat", urlencodedParser, function (request, response) {
rl.close();
});
}
-
}
-
});
app.post('/importworldinfo', urlencodedParser, (request, response) => {
@@ -1919,7 +1873,7 @@ app.post('/uploaduseravatar', urlencodedParser, async (request, response) => {
const crop = tryParse(request.query.crop);
let rawImg = await jimp.read(pathToUpload);
- if (typeof crop == 'object') {
+ if (typeof crop == 'object' && [crop.x, crop.y, crop.width, crop.height].every(x => typeof x === 'number')) {
rawImg = rawImg.crop(crop.x, crop.y, crop.width, crop.height);
}
@@ -2746,8 +2700,12 @@ const setupTasks = async function () {
}
if (listen && !config.whitelistMode && !config.basicAuthMode) {
- console.error('Your SillyTavern is currently unsecurely open to the public. Enable whitelisting or basic authentication.');
- process.exit(1);
+ if (config.securityOverride)
+ console.warn("Security has been override. If it's not a trusted network, change the settings.");
+ else {
+ console.error('Your SillyTavern is currently unsecurely open to the public. Enable whitelisting or basic authentication.');
+ process.exit(1);
+ }
}
if (true === cliArguments.ssl)
diff --git a/src/character-card-parser.js b/src/character-card-parser.js
new file mode 100644
index 000000000..e97a66bf0
--- /dev/null
+++ b/src/character-card-parser.js
@@ -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
+};