From 0a13b2da5339af33cf602de5d2feef2386608a6d Mon Sep 17 00:00:00 2001 From: Ash Date: Thu, 9 Feb 2023 13:55:18 +0400 Subject: [PATCH 1/9] security update --- config.json | 5 ++++ public/index.html | 2 +- server.js | 75 +++++++++++++++++++++++++++-------------------- 3 files changed, 50 insertions(+), 32 deletions(-) create mode 100644 config.json diff --git a/config.json b/config.json new file mode 100644 index 000000000..b24016f3c --- /dev/null +++ b/config.json @@ -0,0 +1,5 @@ +{ + "port": 8000, + "whitelist": ["127.0.0.1"], + "whitelistMode": true +} diff --git a/public/index.html b/public/index.html index 0bf1d3a32..e19a7131c 100644 --- a/public/index.html +++ b/public/index.html @@ -37,7 +37,7 @@ create_date: 0, mes: '\n*You went inside. The air smelled of fried meat, tobacco and a hint of wine. A dim light was cast by candles, and a fire crackled in the fireplace. It seems to be a very pleasant place. Behind the wooden bar is an elf waitress, she is smiling. Her ears are very pointy, and there is a twinkle in her eye. She wears glasses and a white apron. As soon as she noticed you, she immediately came right up close to you.*\n\n' + ' Hello there! How is your evening going?\n' + - '\n@@@TavernAI v'+VERSION+'@@@
Cloud




' + '\n@@@TavernAI v'+VERSION+'@@@
Cloud




' }]; var chat_create_date = 0; diff --git a/server.js b/server.js index b1d1ad1c4..1156d1929 100644 --- a/server.js +++ b/server.js @@ -16,11 +16,16 @@ const sharp = require('sharp'); sharp.cache(false); const path = require('path'); +const config = require('./config.json'); +const server_port = config.port; +const whitelist = config.whitelist; +const whitelistMode = config.whitelistMode; + var Client = require('node-rest-client').Client; var client = new Client(); var api_server = "";//"http://127.0.0.1:5000"; -var server_port = 8000; +//var server_port = 8000; var api_novelai = "https://api.novelai.net"; @@ -45,38 +50,17 @@ const jsonParser = express.json({limit: '100mb'}); const urlencodedParser = express.urlencoded({extended: true, limit: '100mb'}); - - -app.post("/getlastversion", jsonParser, function(request, response_getlastversion = response){ - if(!request.body) return response_getlastversion.sendStatus(400); - - const repo = 'TavernAI/TavernAI'; - - const req = https.request({ - hostname: 'github.com', - path: `/${repo}/releases/latest`, - method: 'HEAD' - }, (res) => { - if(res.statusCode === 302) { - const glocation = res.headers.location; - const versionStartIndex = glocation.lastIndexOf('@')+1; - const version = glocation.substring(versionStartIndex); - //console.log(version); - response_getlastversion.send({version: version}); - }else{ - response_getlastversion.send({version: 'error'}); - } - }); - - req.on('error', (error) => { - console.error(error); - response_getlastversion.send({version: 'error'}); - }); - - req.end(); - +app.use(function (req, res, next) { //Security + const clientIp = req.connection.remoteAddress.split(':').pop(); + 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'); + return res.status(403).send('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.
Example for add several IP in whitelist: "whitelist": ["127.0.0.1", "'+ clientIp+'"]
Example for disable whitelist mode: "whitelistMode": false'); + } + next(); }); + + app.use(express.static(__dirname + "/public", { refresh: true })); app.use('/backgrounds', (req, res) => { const filePath = path.join(process.cwd(), 'public/backgrounds', req.url); @@ -108,6 +92,35 @@ app.get("/", function(request, response){ app.get("/notes/*", function(request, response){     response.sendFile(__dirname + "/public"+request.url+".html");      //response.send("

Главная страница

"); +}); +app.post("/getlastversion", jsonParser, function(request, response_getlastversion = response){ + if(!request.body) return response_getlastversion.sendStatus(400); + + const repo = 'TavernAI/TavernAI'; + let req; + req = https.request({ + hostname: 'github.com', + path: `/${repo}/releases/latest`, + method: 'HEAD' + }, (res) => { + if(res.statusCode === 302) { + const glocation = res.headers.location; + const versionStartIndex = glocation.lastIndexOf('@')+1; + const version = glocation.substring(versionStartIndex); + //console.log(version); + response_getlastversion.send({version: version}); + }else{ + response_getlastversion.send({version: 'error'}); + } + }); + + req.on('error', (error) => { + console.error(error); + response_getlastversion.send({version: 'error'}); + }); + + req.end(); + }); //**************Kobold api app.post("/generate", jsonParser, function(request, response_generate = response){ From abc2bce7cfbc3c4594bfa8c5419209637865ae3b Mon Sep 17 00:00:00 2001 From: Ash Date: Sat, 11 Feb 2023 01:56:15 +0400 Subject: [PATCH 2/9] colab --- colab/GPU.ipynb | 109 +++++++++++++++++++++++++++++++++++++++++------ public/style.css | 2 +- 2 files changed, 96 insertions(+), 15 deletions(-) diff --git a/colab/GPU.ipynb b/colab/GPU.ipynb index 30d1c42cf..b3fefe403 100644 --- a/colab/GPU.ipynb +++ b/colab/GPU.ipynb @@ -67,32 +67,102 @@ "Model = \"Pygmalion 6B\" #@param [ \"Pygmalion 6B\", \"Pygmalion 6B Dev\"] {allow-input: true}\n", "Version = \"Official\" \n", "Provider = \"Cloudflare\" \n", - "use_google_drive = False #@param {type:\"boolean\"}\n", + "use_google_drive = True #@param {type:\"boolean\"}\n", "\n", "!nvidia-smi\n", "import subprocess\n", "import time\n", "import sys\n", "import os\n", + "import threading\n", "from google.colab import drive\n", + "def copy_chats():\n", + " for dirpath, dirnames, filenames in os.walk(\"/content/drive/MyDrive/TavernAI/chats/\"):\n", + " for filename in filenames:\n", + " source_file = os.path.join(dirpath, filename)\n", + " destination_file = source_file.replace(\"/content/drive/MyDrive/TavernAI/chats/\", \"/TavernAIColab/public/chats/\")\n", + "\n", + " if not os.path.exists(destination_file):\n", + " if not os.path.exists(os.path.dirname(destination_file)):\n", + " os.makedirs(os.path.dirname(destination_file))\n", + " !cp -r {source_file} {destination_file}\n", + " else:\n", + " !cp -r {source_file} {destination_file}\n", + " \n", + "def copy_characters():\n", + " source_files2 = os.listdir(\"/content/drive/MyDrive/TavernAI/characters\")\n", + " destination_files2 = os.listdir(\"/TavernAIColab/public/characters/\")\n", + "\n", + " new_files2 = set(source_files2) - set(destination_files2)\n", + " deleted_files2 = set(destination_files2) - set(source_files2)\n", + " updated_files2 = [file for file in source_files2 if file in destination_files2 and \n", + " os.path.getmtime(f'/content/drive/MyDrive/TavernAI/characters/{file}') > \n", + " os.path.getmtime(f'/TavernAIColab/public/characters/{file}')]\n", + "\n", + " if new_files2:\n", + " for file in new_files2:\n", + " if os.path.isdir(f'/content/drive/MyDrive/TavernAI/characters/{file}'):\n", + " !cp -r /content/drive/MyDrive/TavernAI/characters/{file} /TavernAIColab/public/characters/\n", + " else:\n", + " !cp /content/drive/MyDrive/TavernAI/characters/{file} /TavernAIColab/public/characters/\n", + "\n", + " if updated_files2:\n", + " for file in updated_files2:\n", + " !cp /content/drive/MyDrive/TavernAI/characters/{file} /TavernAIColab/public/characters/\n", + " \n", "def sync_files():\n", " while True:\n", - " source_files = os.listdir(\"/taicolabtest/public/chats/\")\n", - " destination_files = os.listdir(\"/content/drive/MyDrive/TavernAI/chats\")\n", + " #chats\n", + " for dirpath, dirnames, filenames in os.walk(\"/TavernAIColab/public/chats/\"):\n", + " for filename in filenames:\n", + " source_file = os.path.join(dirpath, filename)\n", + " destination_file = source_file.replace(\"/TavernAIColab/public/chats/\", \"/content/drive/MyDrive/TavernAI/chats/\")\n", "\n", - " new_files = set(source_files) - set(destination_files)\n", - " deleted_files = set(destination_files) - set(source_files)\n", + " if not os.path.exists(destination_file):\n", + " if not os.path.exists(os.path.dirname(destination_file)):\n", + " os.makedirs(os.path.dirname(destination_file))\n", + " !cp -r {source_file} {destination_file}\n", + " elif os.path.getmtime(source_file) > os.path.getmtime(destination_file):\n", + " !cp -r {source_file} {destination_file}\n", "\n", - " if new_files:\n", - " for file in new_files:\n", - " !cp /taicolabtest/public/chats/{file} /content/drive/MyDrive/TavernAI/chats\n", + " source_files2 = os.listdir(\"/TavernAIColab/public/chats/\")\n", + " destination_files2 = os.listdir(\"/content/drive/MyDrive/TavernAI/chats\")\n", "\n", + " deleted_files = set(destination_files2) - set(source_files2)\n", " if deleted_files:\n", " for file in deleted_files:\n", - " !rm /content/drive/MyDrive/TavernAI/chats/{file}\n", + " if os.path.isdir(f'/content/drive/MyDrive/TavernAI/chats/{file}'):\n", + " !rm -r /content/drive/MyDrive/TavernAI/chats/{file}\n", + " else:\n", + " !rm /content/drive/MyDrive/TavernAI/chats/{file}\n", "\n", - " time.sleep(3) # Wait\n", "\n", + " #characters\n", + " source_files2 = os.listdir(\"/TavernAIColab/public/characters/\")\n", + " destination_files2 = os.listdir(\"/content/drive/MyDrive/TavernAI/characters\")\n", + "\n", + " new_files2 = set(source_files2) - set(destination_files2)\n", + " deleted_files2 = set(destination_files2) - set(source_files2)\n", + " updated_files2 = [file for file in source_files2 if file in destination_files2 and \n", + " os.path.getmtime(f'/TavernAIColab/public/characters/{file}') > \n", + " os.path.getmtime(f'/content/drive/MyDrive/TavernAI/characters/{file}')]\n", + "\n", + " if new_files2:\n", + " for file in new_files2:\n", + " if os.path.isdir(f'/taicolabtest/public/characters/{file}'):\n", + " !cp -r /TavernAIColab/public/characters/{file} /content/drive/MyDrive/TavernAI/characters\n", + " else:\n", + " !cp /TavernAIColab/public/characters/{file} /content/drive/MyDrive/TavernAI/characters\n", + "\n", + " if deleted_files2:\n", + " for file in deleted_files2:\n", + " !rm /content/drive/MyDrive/TavernAI/characters/{file}\n", + "\n", + " if updated_files2:\n", + " for file in updated_files2:\n", + " !cp /TavernAIColab/public/characters/{file} /content/drive/MyDrive/TavernAI/characters\n", + " time.sleep(3) \n", + " \n", "if use_google_drive:\n", " drive.mount('/content/drive/')\n", " if not os.path.exists(\"/content/drive/MyDrive/TavernAI/\"):\n", @@ -126,12 +196,13 @@ "else:\n", " tunnel = \"\"\n", "\n", + "\n", "#Henk's KoboldAI script\n", "!wget https://koboldai.org/ckds && chmod +x ckds\n", "!./ckds --init only\n", "p = subprocess.Popen(['/content/ckds', '--model', Model], stdout=subprocess.PIPE, stderr=subprocess.PIPE)\n", "\n", - "#Tricks\n", + "#Do not repeat! Tricks performed by a professional!\n", "url = ''\n", "while True:\n", " line = p.stdout.readline().decode().strip()\n", @@ -151,21 +222,31 @@ " if \"INIT\" in line and \"Transformers\" in line:\n", " print(\"Model loading... (It will take 2 - 5 minutes)\")\n", "\n", + "\n", + "\n", "#TavernAI\n", "%cd /\n", "!curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash\n", "!nvm install 19.1.0\n", "!nvm use 19.1.0\n", "!node -v\n", - "!git clone https://github.com/TavernAI/taicolabtest\n", - "%cd taicolabtest\n", + "!git clone https://github.com/TavernAI/TavernAIColab\n", + "%cd TavernAIColab\n", "!npm install\n", "time.sleep(1)\n", "%env colab=2\n", "%env colaburl=$url\n", "!nohup node server.js &\n", "time.sleep(3)\n", - "\n", + "%cd /\n", + "copy_characters()\n", + "time.sleep(1)\n", + "copy_chats()\n", + "time.sleep(1)\n", + "if use_google_drive:\n", + " t = threading.Thread(target=sync_files)\n", + " t.daemon = True # Daemonize\n", + " t.start()\n", "print('KoboldAI LINK:')\n", "print(url)\n", "print('')\n", diff --git a/public/style.css b/public/style.css index f5f5a6693..7db39645b 100644 --- a/public/style.css +++ b/public/style.css @@ -800,7 +800,7 @@ input[type=button] { right: 0; text-align: center; margin-top: 36vh; - box-shadow: 0 0 2px rgba(200,200,200,0.1); + /*box-shadow: 0 0 2px rgba(200,200,200,0.1);*/ padding: 4px; background: #191b3100; border-radius: 10px; From 2dec0ffce630a92f14a9bb74055ea89dc1d01cfb Mon Sep 17 00:00:00 2001 From: Ash Date: Sat, 11 Feb 2023 02:31:12 +0400 Subject: [PATCH 3/9] colab --- colab/GPU.ipynb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/colab/GPU.ipynb b/colab/GPU.ipynb index b3fefe403..af1de5f53 100644 --- a/colab/GPU.ipynb +++ b/colab/GPU.ipynb @@ -52,6 +52,21 @@ "id": "d-Yihz3hAb2E" } }, + { + "cell_type": "code", + "source": [ + "#@title <-- Tap this if you play on Mobile { display-mode: \"form\" }\n", + "#Taken from KoboldAI colab\n", + "%%html\n", + "Press play on the music player to keep the tab alive, then start TavernAI below (Uses only 13MB of data)
\n", + "