mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Merge branch 'TavernAI:main' into main
This commit is contained in:
@ -65,9 +65,9 @@
|
|||||||
"\n",
|
"\n",
|
||||||
"Model = \"Pygmalion 6B\" #@param [ \"Pygmalion 6B\", \"Pygmalion 6B Dev\"] {allow-input: true}\n",
|
"Model = \"Pygmalion 6B\" #@param [ \"Pygmalion 6B\", \"Pygmalion 6B Dev\"] {allow-input: true}\n",
|
||||||
"Version = \"Official\" \n",
|
"Version = \"Official\" \n",
|
||||||
"Provider = \"Cloudflare\" \n",
|
"KoboldAI_Provider = \"Localtunnel\" #@param [\"Localtunnel\", \"Cloudflare\"]\n",
|
||||||
"use_google_drive = True #@param {type:\"boolean\"}\n",
|
"use_google_drive = True #@param {type:\"boolean\"}\n",
|
||||||
"\n",
|
"Provider = KoboldAI_Provider\n",
|
||||||
"!nvidia-smi\n",
|
"!nvidia-smi\n",
|
||||||
"import subprocess\n",
|
"import subprocess\n",
|
||||||
"import time\n",
|
"import time\n",
|
||||||
@ -133,7 +133,11 @@
|
|||||||
"#Henk's KoboldAI script\n",
|
"#Henk's KoboldAI script\n",
|
||||||
"!wget https://koboldai.org/ckds && chmod +x ckds\n",
|
"!wget https://koboldai.org/ckds && chmod +x ckds\n",
|
||||||
"!./ckds --init only\n",
|
"!./ckds --init only\n",
|
||||||
"p = subprocess.Popen(['/content/ckds', '--model', Model], stdout=subprocess.PIPE, stderr=subprocess.PIPE)\n",
|
"if Provider == \"Localtunnel\":\n",
|
||||||
|
" p = subprocess.Popen(['/content/ckds', '--model', Model, '--localtunnel', 'yes'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)\n",
|
||||||
|
"else:\n",
|
||||||
|
" p = subprocess.Popen(['/content/ckds', '--model', Model], stdout=subprocess.PIPE, stderr=subprocess.PIPE)\n",
|
||||||
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"#Do not repeat! Tricks performed by a professional!\n",
|
"#Do not repeat! Tricks performed by a professional!\n",
|
||||||
"url = ''\n",
|
"url = ''\n",
|
||||||
|
8
config.conf
Normal file
8
config.conf
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
const port = 8000;
|
||||||
|
const whitelist = ['127.0.0.1']; //Example for add several IP in whitelist: ['127.0.0.1', '192.168.0.10']
|
||||||
|
const whitelistMode = true; //Disabling enabling the ip whitelist mode. true/false
|
||||||
|
const autorun = true; //Autorun in the browser. true/false
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
port, whitelist, whitelistMode, autorun
|
||||||
|
};
|
@ -1,5 +0,0 @@
|
|||||||
{
|
|
||||||
"port": 8000,
|
|
||||||
"whitelist": ["127.0.0.1"],
|
|
||||||
"whitelistMode": true
|
|
||||||
}
|
|
80
package-lock.json
generated
80
package-lock.json
generated
@ -1,13 +1,16 @@
|
|||||||
{
|
{
|
||||||
"name": "TavernAI",
|
"name": "TavernAI",
|
||||||
"version": "1.2.7",
|
"version": "1.2.8",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "TavernAI",
|
"name": "TavernAI",
|
||||||
"version": "1.2.7",
|
"version": "1.2.8",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"cookie-parser": "^1.4.6",
|
||||||
|
"cors": "^2.8.5",
|
||||||
|
"csrf-csrf": "^2.2.3",
|
||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
"multer": "^1.4.5-lts.1",
|
"multer": "^1.4.5-lts.1",
|
||||||
"node-rest-client": "^3.1.1",
|
"node-rest-client": "^3.1.1",
|
||||||
@ -283,6 +286,26 @@
|
|||||||
"node": ">= 0.6"
|
"node": ">= 0.6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/cookie-parser": {
|
||||||
|
"version": "1.4.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/cookie-parser/-/cookie-parser-1.4.6.tgz",
|
||||||
|
"integrity": "sha512-z3IzaNjdwUC2olLIB5/ITd0/setiaFMLYiZJle7xg5Fe9KWAceil7xszYfHHBtDFYLSgJduS2Ty0P1uJdPDJeA==",
|
||||||
|
"dependencies": {
|
||||||
|
"cookie": "0.4.1",
|
||||||
|
"cookie-signature": "1.0.6"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.8.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/cookie-parser/node_modules/cookie": {
|
||||||
|
"version": "0.4.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.1.tgz",
|
||||||
|
"integrity": "sha512-ZwrFkGJxUR3EIoXtO+yVE69Eb7KlixbaeAWfBQB9vVsNn/o+Yw69gBWSSDK825hQNdN+wF8zELf3dFNl/kxkUA==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.6"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/cookie-signature": {
|
"node_modules/cookie-signature": {
|
||||||
"version": "1.0.6",
|
"version": "1.0.6",
|
||||||
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",
|
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",
|
||||||
@ -293,6 +316,18 @@
|
|||||||
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz",
|
||||||
"integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ=="
|
"integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ=="
|
||||||
},
|
},
|
||||||
|
"node_modules/cors": {
|
||||||
|
"version": "2.8.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz",
|
||||||
|
"integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==",
|
||||||
|
"dependencies": {
|
||||||
|
"object-assign": "^4",
|
||||||
|
"vary": "^1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.10"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/crc-32": {
|
"node_modules/crc-32": {
|
||||||
"version": "0.3.0",
|
"version": "0.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/crc-32/-/crc-32-0.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/crc-32/-/crc-32-0.3.0.tgz",
|
||||||
@ -301,6 +336,14 @@
|
|||||||
"node": ">=0.8"
|
"node": ">=0.8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/csrf-csrf": {
|
||||||
|
"version": "2.2.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/csrf-csrf/-/csrf-csrf-2.2.3.tgz",
|
||||||
|
"integrity": "sha512-ph3Mt9Bn0IBe2hhm/HBFLAey9NjY+IFPj3RLiK76XBE196HGJrr0Emh3DllhwJtpW93YY0trW3qFyMRlpgPwTQ==",
|
||||||
|
"dependencies": {
|
||||||
|
"http-errors": "^2.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/debug": {
|
"node_modules/debug": {
|
||||||
"version": "4.3.4",
|
"version": "4.3.4",
|
||||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
|
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
|
||||||
@ -1689,6 +1732,22 @@
|
|||||||
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.5.0.tgz",
|
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.5.0.tgz",
|
||||||
"integrity": "sha512-YZ3GUyn/o8gfKJlnlX7g7xq4gyO6OSuhGPKaaGssGB2qgDUS0gPgtTvoyZLTt9Ab6dC4hfc9dV5arkvc/OCmrw=="
|
"integrity": "sha512-YZ3GUyn/o8gfKJlnlX7g7xq4gyO6OSuhGPKaaGssGB2qgDUS0gPgtTvoyZLTt9Ab6dC4hfc9dV5arkvc/OCmrw=="
|
||||||
},
|
},
|
||||||
|
"cookie-parser": {
|
||||||
|
"version": "1.4.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/cookie-parser/-/cookie-parser-1.4.6.tgz",
|
||||||
|
"integrity": "sha512-z3IzaNjdwUC2olLIB5/ITd0/setiaFMLYiZJle7xg5Fe9KWAceil7xszYfHHBtDFYLSgJduS2Ty0P1uJdPDJeA==",
|
||||||
|
"requires": {
|
||||||
|
"cookie": "0.4.1",
|
||||||
|
"cookie-signature": "1.0.6"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"cookie": {
|
||||||
|
"version": "0.4.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.1.tgz",
|
||||||
|
"integrity": "sha512-ZwrFkGJxUR3EIoXtO+yVE69Eb7KlixbaeAWfBQB9vVsNn/o+Yw69gBWSSDK825hQNdN+wF8zELf3dFNl/kxkUA=="
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"cookie-signature": {
|
"cookie-signature": {
|
||||||
"version": "1.0.6",
|
"version": "1.0.6",
|
||||||
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",
|
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",
|
||||||
@ -1699,11 +1758,28 @@
|
|||||||
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz",
|
||||||
"integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ=="
|
"integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ=="
|
||||||
},
|
},
|
||||||
|
"cors": {
|
||||||
|
"version": "2.8.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz",
|
||||||
|
"integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==",
|
||||||
|
"requires": {
|
||||||
|
"object-assign": "^4",
|
||||||
|
"vary": "^1"
|
||||||
|
}
|
||||||
|
},
|
||||||
"crc-32": {
|
"crc-32": {
|
||||||
"version": "0.3.0",
|
"version": "0.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/crc-32/-/crc-32-0.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/crc-32/-/crc-32-0.3.0.tgz",
|
||||||
"integrity": "sha512-kucVIjOmMc1f0tv53BJ/5WIX+MGLcKuoBhnGqQrgKJNqLByb/sVMWfW/Aw6hw0jgcqjJ2pi9E5y32zOIpaUlsA=="
|
"integrity": "sha512-kucVIjOmMc1f0tv53BJ/5WIX+MGLcKuoBhnGqQrgKJNqLByb/sVMWfW/Aw6hw0jgcqjJ2pi9E5y32zOIpaUlsA=="
|
||||||
},
|
},
|
||||||
|
"csrf-csrf": {
|
||||||
|
"version": "2.2.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/csrf-csrf/-/csrf-csrf-2.2.3.tgz",
|
||||||
|
"integrity": "sha512-ph3Mt9Bn0IBe2hhm/HBFLAey9NjY+IFPj3RLiK76XBE196HGJrr0Emh3DllhwJtpW93YY0trW3qFyMRlpgPwTQ==",
|
||||||
|
"requires": {
|
||||||
|
"http-errors": "^2.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"debug": {
|
"debug": {
|
||||||
"version": "4.3.4",
|
"version": "4.3.4",
|
||||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
|
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
"cors": "^2.8.5"
|
"cors": "^2.8.5"
|
||||||
},
|
},
|
||||||
"name": "TavernAI",
|
"name": "TavernAI",
|
||||||
"version": "1.2.7",
|
"version": "1.2.8",
|
||||||
"bin": {
|
"bin": {
|
||||||
"TavernAI": "server.js"
|
"TavernAI": "server.js"
|
||||||
},
|
},
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
<script type=module>
|
<script type=module>
|
||||||
import {encode, decode} from "../scripts/gpt-2-3-tokenizer/mod.js";
|
import {encode, decode} from "../scripts/gpt-2-3-tokenizer/mod.js";
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
const VERSION = '1.2.7';
|
const VERSION = '1.2.8';
|
||||||
var converter = new showdown.Converter();
|
var converter = new showdown.Converter();
|
||||||
var bg_menu_toggle = false;
|
var bg_menu_toggle = false;
|
||||||
const systemUserName = 'Chloe';
|
const systemUserName = 'Chloe';
|
||||||
@ -462,7 +462,7 @@
|
|||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"X-CSRF-Token": token,
|
"X-CSRF-Token": token
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
"": ""
|
"": ""
|
||||||
@ -484,7 +484,6 @@
|
|||||||
}
|
}
|
||||||
characters.sort((a,b) => a.create_date - b.create_date );
|
characters.sort((a,b) => a.create_date - b.create_date );
|
||||||
//characters.reverse();
|
//characters.reverse();
|
||||||
|
|
||||||
if(this_chid != undefined) $("#avatar_url_pole").val(characters[this_chid].avatar);
|
if(this_chid != undefined) $("#avatar_url_pole").val(characters[this_chid].avatar);
|
||||||
printCharaters();
|
printCharaters();
|
||||||
//console.log(propOwn.length);
|
//console.log(propOwn.length);
|
||||||
@ -539,6 +538,7 @@
|
|||||||
$('#colab_shadow_popup').css('display', 'none');
|
$('#colab_shadow_popup').css('display', 'none');
|
||||||
is_colab = true;
|
is_colab = true;
|
||||||
let url = String(getData.colaburl).split("flare.com")[0] + "flare.com";
|
let url = String(getData.colaburl).split("flare.com")[0] + "flare.com";
|
||||||
|
url = String(url).split("loca.lt")[0] + "loca.lt";
|
||||||
$('#api_url_text').val(url);
|
$('#api_url_text').val(url);
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
$('#api_button').click();
|
$('#api_button').click();
|
||||||
@ -1061,7 +1061,7 @@
|
|||||||
is_add_personality = true;
|
is_add_personality = true;
|
||||||
//chatString = chatString.substr(0,chatString.length-1);
|
//chatString = chatString.substr(0,chatString.length-1);
|
||||||
//anchorAndPersonality = "[Genre: roleplay chat][Tone: very long messages with descriptions]";
|
//anchorAndPersonality = "[Genre: roleplay chat][Tone: very long messages with descriptions]";
|
||||||
if(anchorTop != "" || charPersonality != ""){
|
if((anchorTop != "" || charPersonality != "") && !is_pygmalion){
|
||||||
if(anchorTop != "") charPersonality+=' ';
|
if(anchorTop != "") charPersonality+=' ';
|
||||||
item+="["+charPersonality+anchorTop+']\n';
|
item+="["+charPersonality+anchorTop+']\n';
|
||||||
}
|
}
|
||||||
@ -1249,7 +1249,7 @@
|
|||||||
if(is_pygmalion){
|
if(is_pygmalion){
|
||||||
if_typing_text = false;
|
if_typing_text = false;
|
||||||
message_already_generated +=getMessage;
|
message_already_generated +=getMessage;
|
||||||
if(message_already_generated.indexOf('You:') === -1 && tokens_already_generated < parseInt(amount_gen)){
|
if(message_already_generated.indexOf('You:') === -1 && tokens_already_generated < parseInt(amount_gen) && getMessage.length > 0){
|
||||||
runGenerate(getMessage);
|
runGenerate(getMessage);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
48
server.js
48
server.js
@ -20,10 +20,11 @@ const cookieParser = require('cookie-parser');
|
|||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
|
|
||||||
|
|
||||||
const config = require('./config.json');
|
const config = require('./config.conf');
|
||||||
const server_port = config.port;
|
const server_port = config.port;
|
||||||
const whitelist = config.whitelist;
|
const whitelist = config.whitelist;
|
||||||
const whitelistMode = config.whitelistMode;
|
const whitelistMode = config.whitelistMode;
|
||||||
|
const autorun = config.autorun;
|
||||||
|
|
||||||
var Client = require('node-rest-client').Client;
|
var Client = require('node-rest-client').Client;
|
||||||
var client = new Client();
|
var client = new Client();
|
||||||
@ -92,15 +93,15 @@ const cors = require('cors');
|
|||||||
const CORS = cors({
|
const CORS = cors({
|
||||||
origin: 'null',
|
origin: 'null',
|
||||||
methods: ['OPTIONS']
|
methods: ['OPTIONS']
|
||||||
})
|
});
|
||||||
|
|
||||||
app.use(CORS);
|
app.use(CORS);
|
||||||
|
|
||||||
app.use(function (req, res, next) { //Security
|
app.use(function (req, res, next) { //Security
|
||||||
const clientIp = req.connection.remoteAddress.split(':').pop();
|
const clientIp = req.connection.remoteAddress.split(':').pop();
|
||||||
if (whitelistMode === true && !whitelist.includes(clientIp)) {
|
if (whitelistMode === true && !whitelist.includes(clientIp)) {
|
||||||
console.log('Forbidden: Connection attempt from '+ clientIp+'. If you are attempting to connect, please add your IP address in whitelist or disable whitelist mode in config.json in root of TavernAI folder.\nExample for add several IP in whitelist: "whitelist": ["127.0.0.1", "'+ clientIp+'"]\nExample for disable whitelist mode: "whitelistMode": false');
|
console.log('Forbidden: Connection attempt from '+ clientIp+'. If you are attempting to connect, please add your IP address in whitelist or disable whitelist mode in config.conf in root of TavernAI folder.\n');
|
||||||
return res.status(403).send('<b>Forbidden</b>: Connection attempt from <b>'+ clientIp+'</b>. If you are attempting to connect, please add your IP address in whitelist or disable whitelist mode in config.json in root of TavernAI folder.<br>Example for add several IP in whitelist: "whitelist": ["127.0.0.1", "'+ clientIp+'"]<br>Example for disable whitelist mode: "whitelistMode": false');
|
return res.status(403).send('<b>Forbidden</b>: Connection attempt from <b>'+ clientIp+'</b>. If you are attempting to connect, please add your IP address in whitelist or disable whitelist mode in config.conf in root of TavernAI folder.');
|
||||||
}
|
}
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
@ -476,17 +477,18 @@ app.post("/editcharacter", urlencodedParser, function(request, response){
|
|||||||
var char = charaFormatData(request.body);//{"name": request.body.ch_name, "description": request.body.description, "personality": request.body.personality, "first_mes": request.body.first_mes, "avatar": request.body.avatar_url, "chat": request.body.chat, "last_mes": request.body.last_mes, "mes_example": ''};
|
var char = charaFormatData(request.body);//{"name": request.body.ch_name, "description": request.body.description, "personality": request.body.personality, "first_mes": request.body.first_mes, "avatar": request.body.avatar_url, "chat": request.body.chat, "last_mes": request.body.last_mes, "mes_example": ''};
|
||||||
char.chat = request.body.chat;
|
char.chat = request.body.chat;
|
||||||
char.create_date = request.body.create_date;
|
char.create_date = request.body.create_date;
|
||||||
|
|
||||||
char = JSON.stringify(char);
|
char = JSON.stringify(char);
|
||||||
|
let target_img = (request.body.avatar_url).replace('.png', '');
|
||||||
if(!filedata){
|
if(!filedata){
|
||||||
|
|
||||||
charaWrite(img_path+request.body.avatar_url, char, request.body.ch_name, response, 'Character saved');
|
charaWrite(img_path+request.body.avatar_url, char, target_img, response, 'Character saved');
|
||||||
}else{
|
}else{
|
||||||
//console.log(filedata.filename);
|
//console.log(filedata.filename);
|
||||||
img_path = "uploads/";
|
img_path = "uploads/";
|
||||||
img_file = filedata.filename;
|
img_file = filedata.filename;
|
||||||
|
|
||||||
charaWrite(img_path+img_file, char, request.body.ch_name, response, 'Character saved');
|
charaWrite(img_path+img_file, char, target_img, response, 'Character saved');
|
||||||
//response.send('Character saved');
|
//response.send('Character saved');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -513,7 +515,7 @@ app.post("/deletecharacter", urlencodedParser, function(request, response){
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
async function charaWrite(img_url, data, name, response = undefined, mes = 'ok'){
|
async function charaWrite(img_url, data, target_img, response = undefined, mes = 'ok'){
|
||||||
try {
|
try {
|
||||||
// Load the image in any format
|
// Load the image in any format
|
||||||
sharp.cache(false);
|
sharp.cache(false);
|
||||||
@ -526,7 +528,7 @@ async function charaWrite(img_url, data, name, response = undefined, mes = 'ok')
|
|||||||
|
|
||||||
// Get the chunks
|
// Get the chunks
|
||||||
var chunks = extract(image);
|
var chunks = extract(image);
|
||||||
var tEXtChunks = chunks.filter(chunk => chunk.name === 'tEXt');
|
var tEXtChunks = chunks.filter(chunk => chunk.create_date === 'tEXt');
|
||||||
|
|
||||||
// Remove all existing tEXt chunks
|
// Remove all existing tEXt chunks
|
||||||
for (var tEXtChunk of tEXtChunks) {
|
for (var tEXtChunk of tEXtChunks) {
|
||||||
@ -537,7 +539,7 @@ async function charaWrite(img_url, data, name, response = undefined, mes = 'ok')
|
|||||||
chunks.splice(-1, 0, PNGtext.encode('chara', base64EncodedData));
|
chunks.splice(-1, 0, PNGtext.encode('chara', base64EncodedData));
|
||||||
//chunks.splice(-1, 0, text.encode('lorem', 'ipsum'));
|
//chunks.splice(-1, 0, text.encode('lorem', 'ipsum'));
|
||||||
|
|
||||||
fs.writeFileSync(charactersPath+name+'.png', new Buffer.from(encode(chunks)));
|
fs.writeFileSync(charactersPath+target_img+'.png', new Buffer.from(encode(chunks)));
|
||||||
if(response !== undefined) response.send(mes);
|
if(response !== undefined) response.send(mes);
|
||||||
|
|
||||||
|
|
||||||
@ -1027,8 +1029,11 @@ app.post("/getallchatsofchatacter", jsonParser, function(request, response){
|
|||||||
|
|
||||||
});
|
});
|
||||||
function getPngName(file){
|
function getPngName(file){
|
||||||
if (fs.existsSync(charactersPath+file+'.png')) {
|
let i = 1;
|
||||||
file = file+'1';
|
let base_name = file;
|
||||||
|
while (fs.existsSync(charactersPath+file+'.png')) {
|
||||||
|
file = base_name+i;
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
@ -1051,12 +1056,12 @@ app.post("/importcharacter", urlencodedParser, function(request, response){
|
|||||||
|
|
||||||
if(jsonData.name !== undefined){
|
if(jsonData.name !== undefined){
|
||||||
png_name = getPngName(jsonData.name);
|
png_name = getPngName(jsonData.name);
|
||||||
var char = {"name": jsonData.name, "description": jsonData.description ?? '', "personality": jsonData.personality ?? '', "first_mes": jsonData.first_mes ?? '', "avatar": 'none', "chat": Date.now(), "mes_example": jsonData.mes_example ?? '', "scenario": jsonData.scenario ?? '', "create_date": Date.now()};
|
let char = {"name": jsonData.name, "description": jsonData.description ?? '', "personality": jsonData.personality ?? '', "first_mes": jsonData.first_mes ?? '', "avatar": 'none', "chat": Date.now(), "mes_example": jsonData.mes_example ?? '', "scenario": jsonData.scenario ?? '', "create_date": Date.now()};
|
||||||
char = JSON.stringify(char);
|
char = JSON.stringify(char);
|
||||||
charaWrite('./public/img/fluffy.png', char, png_name, response, {file_name: png_name});
|
charaWrite('./public/img/fluffy.png', char, png_name, response, {file_name: png_name});
|
||||||
}else if(jsonData.char_name !== undefined){//json Pygmalion notepad
|
}else if(jsonData.char_name !== undefined){//json Pygmalion notepad
|
||||||
png_name = getPngName(jsonData.char_name);
|
png_name = getPngName(jsonData.char_name);
|
||||||
var char = {"name": jsonData.char_name, "description": jsonData.char_persona ?? '', "personality": '', "first_mes": jsonData.char_greeting ?? '', "avatar": 'none', "chat": Date.now(), "mes_example": jsonData.example_dialogue ?? '', "scenario": jsonData.world_scenario ?? '', "create_date": Date.now()};
|
let char = {"name": jsonData.char_name, "description": jsonData.char_persona ?? '', "personality": '', "first_mes": jsonData.char_greeting ?? '', "avatar": 'none', "chat": Date.now(), "mes_example": jsonData.example_dialogue ?? '', "scenario": jsonData.world_scenario ?? '', "create_date": Date.now()};
|
||||||
char = JSON.stringify(char);
|
char = JSON.stringify(char);
|
||||||
charaWrite('./public/img/fluffy.png', char, png_name, response, {file_name: png_name});
|
charaWrite('./public/img/fluffy.png', char, png_name, response, {file_name: png_name});
|
||||||
}else{
|
}else{
|
||||||
@ -1068,9 +1073,14 @@ app.post("/importcharacter", urlencodedParser, function(request, response){
|
|||||||
try{
|
try{
|
||||||
|
|
||||||
var img_data = charaRead('./uploads/'+filedata.filename);
|
var img_data = charaRead('./uploads/'+filedata.filename);
|
||||||
let jsonObject = JSON.parse(img_data);
|
let jsonData = JSON.parse(img_data);
|
||||||
png_name = getPngName(jsonObject.name);
|
png_name = getPngName(jsonData.name);
|
||||||
if(jsonObject.name !== undefined){
|
|
||||||
|
if(jsonData.name !== undefined){
|
||||||
|
let char = {"name": jsonData.name, "description": jsonData.description ?? '', "personality": jsonData.personality ?? '', "first_mes": jsonData.first_mes ?? '', "avatar": 'none', "chat": Date.now(), "mes_example": jsonData.mes_example ?? '', "scenario": jsonData.scenario ?? '', "create_date": Date.now()};
|
||||||
|
char = JSON.stringify(char);
|
||||||
|
charaWrite('./uploads/'+filedata.filename, char, png_name, response, {file_name: png_name});
|
||||||
|
/*
|
||||||
fs.copyFile('./uploads/'+filedata.filename, charactersPath+png_name+'.png', (err) => {
|
fs.copyFile('./uploads/'+filedata.filename, charactersPath+png_name+'.png', (err) => {
|
||||||
if(err) {
|
if(err) {
|
||||||
response.send({error:true});
|
response.send({error:true});
|
||||||
@ -1080,7 +1090,7 @@ app.post("/importcharacter", urlencodedParser, function(request, response){
|
|||||||
response.send({file_name: png_name});
|
response.send({file_name: png_name});
|
||||||
}
|
}
|
||||||
//console.log('The image was copied from temp directory.');
|
//console.log('The image was copied from temp directory.');
|
||||||
});
|
});*/
|
||||||
}
|
}
|
||||||
}catch(err){
|
}catch(err){
|
||||||
console.log(err);
|
console.log(err);
|
||||||
@ -1539,7 +1549,7 @@ app.listen(server_port, function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log('Launching...');
|
console.log('Launching...');
|
||||||
open('http:127.0.0.1:'+server_port);
|
if(autorun) open('http:127.0.0.1:'+server_port);
|
||||||
console.log('TavernAI started: http://127.0.0.1:'+server_port);
|
console.log('TavernAI started: http://127.0.0.1:'+server_port);
|
||||||
if (fs.existsSync('public/characters/update.txt') && !is_colab) {
|
if (fs.existsSync('public/characters/update.txt') && !is_colab) {
|
||||||
convertStage1();
|
convertStage1();
|
||||||
|
Reference in New Issue
Block a user