mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
346 lines
14 KiB
Plaintext
346 lines
14 KiB
Plaintext
{
|
||
"cells": [
|
||
{
|
||
"attachments": {},
|
||
"cell_type": "markdown",
|
||
"metadata": {},
|
||
"source": [
|
||
"**Links**<br>\n",
|
||
"SillyTavern GitHub: https://github.com/Cohee1207/SillyTavern<br>\n",
|
||
"Extensions API GitHub: https://github.com/Cohee1207/TavernAI-extras/<br>\n",
|
||
"SillyTavern community Discord (support and discussion): https://discord.gg/RZdyAEUPvj<br>\n",
|
||
"Contact the maintainer directly: Cohee#1207"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"metadata": {
|
||
"cellView": "form",
|
||
"id": "_1gpebrnlp5-"
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"#@title <b><-- Convert TavernAI characters to SillyTavern format</b>\n",
|
||
"\n",
|
||
"!mkdir /convert\n",
|
||
"%cd /convert\n",
|
||
"\n",
|
||
"import os\n",
|
||
"from google.colab import drive\n",
|
||
"\n",
|
||
"drive.mount(\"/convert/drive\")\n",
|
||
"\n",
|
||
"!git clone -b tools https://github.com/EnergoStalin/SillyTavern.git\n",
|
||
"%cd SillyTavern\n",
|
||
"\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",
|
||
"\n",
|
||
"%cd tools/charaverter\n",
|
||
"\n",
|
||
"!npm i\n",
|
||
"\n",
|
||
"path = \"/convert/drive/MyDrive/TavernAI/characters\"\n",
|
||
"output = \"/convert/drive/MyDrive/SillyTavern/characters\"\n",
|
||
"if not os.path.exists(path):\n",
|
||
" path = output\n",
|
||
"\n",
|
||
"!mkdir -p $output\n",
|
||
"!node main.mjs $path $output\n",
|
||
"\n",
|
||
"drive.flush_and_unmount()\n",
|
||
"\n",
|
||
"%cd /\n",
|
||
"!rm -rf /convert"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"metadata": {
|
||
"id": "ewkXkyiFP2Hq"
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"#@title <-- Tap this if you play on Mobile { display-mode: \"form\" }\n",
|
||
"%%html\n",
|
||
"<b>Press play on the music player to keep the tab alive, then start KoboldAI below (Uses only 13MB of data)</b><br/>\n",
|
||
"<audio src=\"https://raw.githubusercontent.com/KoboldAI/KoboldAI-Client/main/colab/silence.m4a\" controls>"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"metadata": {
|
||
"cellView": "form",
|
||
"id": "lVftocpwCoYw"
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"#@title <b><-- Select your model below and then click this to start KoboldAI</b>\n",
|
||
"\n",
|
||
"Model = \"Руgmаlіоn 6В\" #@param [\"Nerys V2 6B\", \"Erebus 6B\", \"Skein 6B\", \"Janeway 6B\", \"Adventure 6B\", \"Руgmаlіоn 6В\", \"Руgmаlіоn 6В Dev\", \"Lit V2 6B\", \"Lit 6B\", \"Shinen 6B\", \"Nerys 2.7B\", \"AID 2.7B\", \"Erebus 2.7B\", \"Janeway 2.7B\", \"Picard 2.7B\", \"Horni LN 2.7B\", \"Horni 2.7B\", \"Shinen 2.7B\", \"OPT 2.7B\", \"Fairseq Dense 2.7B\", \"Neo 2.7B\", \"Руgwау 6B\", \"Nerybus 6.7B\", \"Руgwау v8p4\", \"PPO-Janeway 6B\", \"PPO Shуgmаlіоn 6B\", \"LLaMA 7B\", \"Janin-GPTJ\", \"Javelin-GPTJ\", \"Javelin-R\", \"Janin-R\", \"Javalion-R\", \"Javalion-GPTJ\", \"Javelion-6B\", \"GPT-J-Руg-PPO-6B\", \"ppo_hh_pythia-6B\", \"ppo_hh_gpt-j\", \"GPT-J-Руg_PPO-6B\", \"GPT-J-Руg_PPO-6B-Dev-V8p4\", \"Dolly_GPT-J-6b\", \"Dolly_Руg-6B\"] {allow-input: true}\n",
|
||
"Version = \"Official\" #@param [\"Official\", \"United\"] {allow-input: true}\n",
|
||
"Provider = \"Localtunnel\" #@param [\"Localtunnel\"]\n",
|
||
"ForceInitSteps = [] #@param {allow-input: true}\n",
|
||
"UseGoogleDrive = True #@param {type:\"boolean\"}\n",
|
||
"StartKoboldAI = True #@param {type:\"boolean\"}\n",
|
||
"ModelsFromDrive = False #@param {type:\"boolean\"}\n",
|
||
"UseExtrasExtensions = True #@param {type:\"boolean\"}\n",
|
||
"#@markdown Enables hosting of extensions backend for TavernAI Extras\n",
|
||
"extras_enable_captioning = True #@param {type:\"boolean\"}\n",
|
||
"#@markdown Loads the image captioning module\n",
|
||
"Captions_Model = \"Salesforce/blip-image-captioning-large\" #@param [ \"Salesforce/blip-image-captioning-large\", \"Salesforce/blip-image-captioning-base\" ]\n",
|
||
"#@markdown * Salesforce/blip-image-captioning-large - good base model\n",
|
||
"#@markdown * Salesforce/blip-image-captioning-base - slightly faster but less accurate\n",
|
||
"extras_enable_emotions = True #@param {type:\"boolean\"}\n",
|
||
"#@markdown Loads the sentiment classification model\n",
|
||
"Emotions_Model = \"bhadresh-savani/distilbert-base-uncased-emotion\" #@param [\"bhadresh-savani/distilbert-base-uncased-emotion\", \"joeddav/distilbert-base-uncased-go-emotions-student\"]\n",
|
||
"#@markdown * bhadresh-savani/distilbert-base-uncased-emotion = 6 supported emotions<br>\n",
|
||
"#@markdown * joeddav/distilbert-base-uncased-go-emotions-student = 28 supported emotions\n",
|
||
"extras_enable_memory = True #@param {type:\"boolean\"}\n",
|
||
"#@markdown Loads the story summarization module\n",
|
||
"Memory_Model = \"Qiliang/bart-large-cnn-samsum-ChatGPT_v3\" #@param [ \"Qiliang/bart-large-cnn-samsum-ChatGPT_v3\", \"Qiliang/bart-large-cnn-samsum-ElectrifAi_v10\", \"distilbart-xsum-12-3\" ]\n",
|
||
"#@markdown * Qiliang/bart-large-cnn-samsum-ChatGPT_v3 - summarization model optimized for chats\n",
|
||
"#@markdown * Qiliang/bart-large-cnn-samsum-ElectrifAi_v10 - nice results so far, but still being evaluated\n",
|
||
"#@markdown * distilbart-xsum-12-3 - faster, but pretty basic alternative\n",
|
||
"\n",
|
||
"\n",
|
||
"%cd /content\n",
|
||
"\n",
|
||
"!cat .ii\n",
|
||
"!nvidia-smi\n",
|
||
"\n",
|
||
"import os, subprocess, time, pathlib, json, base64, sys\n",
|
||
"\n",
|
||
"# ---\n",
|
||
"# Utils\n",
|
||
"class IncrementialInstall:\n",
|
||
" def __init__(self, root = \"/\", tasks = [], force = []):\n",
|
||
" self.tasks = tasks\n",
|
||
" self.path = os.path.join(root, \".ii\")\n",
|
||
" self.completed = list(filter(lambda x: not x in force, self.__completed()))\n",
|
||
"\n",
|
||
" def __completed(self):\n",
|
||
" try:\n",
|
||
" with open(self.path) as f:\n",
|
||
" return json.load(f)\n",
|
||
" except:\n",
|
||
" return []\n",
|
||
"\n",
|
||
" def addTask(self, name, func):\n",
|
||
" self.tasks.append({\"name\": name, \"func\": func})\n",
|
||
"\n",
|
||
" def run(self):\n",
|
||
" todo = list(filter(lambda x: not x[\"name\"] in self.completed, self.tasks))\n",
|
||
" try:\n",
|
||
" for task in todo:\n",
|
||
" task[\"func\"]()\n",
|
||
" self.completed.append(task[\"name\"])\n",
|
||
" finally:\n",
|
||
" with open(self.path, \"w\") as f:\n",
|
||
" json.dump(self.completed, f)\n",
|
||
"\n",
|
||
"def create_paths(paths):\n",
|
||
" for directory in paths:\n",
|
||
" if not os.path.exists(directory):\n",
|
||
" os.makedirs(directory)\n",
|
||
"\n",
|
||
"def link(srcDir, destDir, files):\n",
|
||
" '''\n",
|
||
" Link source to dest copying dest to source if not present first\n",
|
||
" '''\n",
|
||
" for file in files:\n",
|
||
" source = os.path.join(srcDir, file)\n",
|
||
" dest = os.path.join(destDir, file)\n",
|
||
" if not os.path.exists(source):\n",
|
||
" !cp -r \"$dest\" \"$source\"\n",
|
||
" !rm -rf \"$dest\"\n",
|
||
" !ln -fs \"$source\" \"$dest\"\n",
|
||
"\n",
|
||
"from google.colab import drive\n",
|
||
"if UseGoogleDrive:\n",
|
||
" drive.mount(\"/content/drive/\")\n",
|
||
"else:\n",
|
||
" create_paths([\n",
|
||
" \"/content/drive/MyDrive\"\n",
|
||
" ])\n",
|
||
"\n",
|
||
"ii = IncrementialInstall(force=ForceInitSteps)\n",
|
||
"\n",
|
||
"# ---\n",
|
||
"# SillyTavern py modules\n",
|
||
"def cloneTavern():\n",
|
||
" %cd /\n",
|
||
" !git clone https://github.com/Cohee1207/SillyTavern\n",
|
||
" %cd -\n",
|
||
" !cp /SillyTavern/colab/*.py ./\n",
|
||
"ii.addTask(\"Clone SillyTavern\", cloneTavern)\n",
|
||
"ii.run()\n",
|
||
"\n",
|
||
"from models import GetModels, ModelData\n",
|
||
"model = GetModels(Version).get(Model, ModelData(Model, Version))\n",
|
||
"\n",
|
||
"# ---\n",
|
||
"# KoboldAI\n",
|
||
"if StartKoboldAI:\n",
|
||
" def downloadKobold():\n",
|
||
" !wget https://koboldai.org/ckds && chmod +x ckds\n",
|
||
" def initKobold():\n",
|
||
" !./ckds --init only\n",
|
||
"\n",
|
||
" ii.addTask(\"Download KoboldAI\", downloadKobold)\n",
|
||
" ii.addTask(\"Init KoboldAI\", initKobold)\n",
|
||
" \n",
|
||
" ii.run()\n",
|
||
"\n",
|
||
"kargs = [\"/content/ckds\"]\n",
|
||
"if not ModelsFromDrive:\n",
|
||
" kargs += [\"-x\", \"colab\", \"-l\", \"colab\"]\n",
|
||
"if Provider == \"Localtunnel\":\n",
|
||
" kargs += [\"--localtunnel\", \"yes\"]\n",
|
||
"\n",
|
||
"kargs += model.args()\n",
|
||
"\n",
|
||
"url = \"\"\n",
|
||
"print(kargs)\n",
|
||
"\n",
|
||
"if StartKoboldAI:\n",
|
||
" p = subprocess.Popen(kargs, stdout=subprocess.PIPE, stderr=subprocess.PIPE)\n",
|
||
"\n",
|
||
" prefix = \"KoboldAI has finished loading and is available at the following link\"\n",
|
||
" urlprefix = f\"{prefix}: \"\n",
|
||
" ui1prefix = f\"{prefix} for UI 1: \"\n",
|
||
" while True:\n",
|
||
" line = p.stdout.readline().decode().strip()\n",
|
||
" print(line)\n",
|
||
" if urlprefix in line:\n",
|
||
" url = line.split(urlprefix)[1]\n",
|
||
" break\n",
|
||
" elif ui1prefix in line:\n",
|
||
" url = line.split(ui1prefix)[1]\n",
|
||
" break\n",
|
||
" elif not line:\n",
|
||
" break\n",
|
||
" if \"INIT\" in line and \"Transformers\" in line:\n",
|
||
" print(\"Model loading... (It will take 2 - 5 minutes)\")\n",
|
||
"\n",
|
||
"print(url)\n",
|
||
"\n",
|
||
"\n",
|
||
"# ---\n",
|
||
"# nodejs\n",
|
||
"%cd /\n",
|
||
"def installNode():\n",
|
||
" !npm install -g n\n",
|
||
" !n 19\n",
|
||
" !node --version\n",
|
||
"ii.addTask(\"Install node\", installNode)\n",
|
||
"\n",
|
||
"\n",
|
||
"# ---\n",
|
||
"# TavernAI extras\n",
|
||
"import globals\n",
|
||
"globals.extras_url = '(disabled)'\n",
|
||
"globals.params = []\n",
|
||
"globals.params.append('--cpu')\n",
|
||
"ExtrasModules = []\n",
|
||
"\n",
|
||
"if (extras_enable_captioning):\n",
|
||
" ExtrasModules.append('caption')\n",
|
||
"if (extras_enable_memory):\n",
|
||
" ExtrasModules.append('summarize')\n",
|
||
"if (extras_enable_emotions):\n",
|
||
" ExtrasModules.append('classify')\n",
|
||
"\n",
|
||
"globals.params.append(f'--classification-model={Emotions_Model}')\n",
|
||
"globals.params.append(f'--summarization-model={Memory_Model}')\n",
|
||
"globals.params.append(f'--captioning-model={Captions_Model}')\n",
|
||
"globals.params.append(f'--enable-modules={\",\".join(ExtrasModules)}')\n",
|
||
"\n",
|
||
"\n",
|
||
"if UseExtrasExtensions:\n",
|
||
" def cloneExtras():\n",
|
||
" %cd /\n",
|
||
" !git clone https://github.com/Cohee1207/TavernAI-extras\n",
|
||
" ii.addTask('clone extras', cloneExtras)\n",
|
||
"\n",
|
||
" def installRequirements():\n",
|
||
" %cd /TavernAI-extras\n",
|
||
" !npm install -g localtunnel\n",
|
||
" !pip install -r requirements.txt\n",
|
||
" !pip install tensorflow==2.11\n",
|
||
" ii.addTask('install requirements', installRequirements)\n",
|
||
"\n",
|
||
" from extras_server import runServer, extractUrl\n",
|
||
" ii.addTask('run server', runServer)\n",
|
||
" ii.addTask('extract extras URL', extractUrl)\n",
|
||
"\n",
|
||
"%cd /SillyTavern\n",
|
||
"\n",
|
||
"if UseGoogleDrive:\n",
|
||
" %env googledrive=2\n",
|
||
"\n",
|
||
" def setupTavernPaths():\n",
|
||
" %cd /SillyTavern\n",
|
||
" tdrive = \"/content/drive/MyDrive/SillyTavern\"\n",
|
||
" create_paths([\n",
|
||
" tdrive,\n",
|
||
" os.path.join(\"public\", \"groups\"),\n",
|
||
" os.path.join(\"public\", \"group chats\")\n",
|
||
" ])\n",
|
||
" link(tdrive, \"public\", [\n",
|
||
" \"settings.json\",\n",
|
||
" \"backgrounds\",\n",
|
||
" \"characters\",\n",
|
||
" \"chats\",\n",
|
||
" \"User Avatars\",\n",
|
||
" \"worlds\",\n",
|
||
" \"group chats\",\n",
|
||
" \"groups\",\n",
|
||
" ])\n",
|
||
" ii.addTask(\"Setup Tavern Paths\", setupTavernPaths)\n",
|
||
"\n",
|
||
"def installTavernDependencies():\n",
|
||
" %cd /SillyTavern\n",
|
||
" !npm install\n",
|
||
" !npm install -g localtunnel\n",
|
||
" !npm install -g forever\n",
|
||
" !pip install flask-cloudflared==0.0.10\n",
|
||
"ii.addTask(\"Install Tavern Dependencies\", installTavernDependencies)\n",
|
||
"ii.run()\n",
|
||
"\n",
|
||
"%env colaburl=$url\n",
|
||
"%env SILLY_TAVERN_PORT=5001\n",
|
||
"!sed -i 's/listen = true/listen = false/g' config.conf\n",
|
||
"!touch stdout.log stderr.log\n",
|
||
"!forever start -o stdout.log -e stderr.log server.js\n",
|
||
"print(\"KoboldAI LINK:\", url, '###Extensions API LINK###', globals.extras_url, \"###SillyTavern LINK###\", sep=\"\\n\")\n",
|
||
"from flask_cloudflared import _run_cloudflared\n",
|
||
"cloudflare = _run_cloudflared(5001)\n",
|
||
"print(cloudflare)\n",
|
||
"!tail -f stdout.log stderr.log"
|
||
]
|
||
}
|
||
],
|
||
"metadata": {
|
||
"accelerator": "GPU",
|
||
"colab": {
|
||
"private_outputs": true,
|
||
"provenance": []
|
||
},
|
||
"gpuClass": "standard",
|
||
"kernelspec": {
|
||
"display_name": "Python 3",
|
||
"name": "python3"
|
||
},
|
||
"language_info": {
|
||
"name": "python"
|
||
}
|
||
},
|
||
"nbformat": 4,
|
||
"nbformat_minor": 0
|
||
}
|