From bb51127bbfd41ba8172c17231d0b418209c8619e Mon Sep 17 00:00:00 2001 From: henk717 Date: Tue, 4 Apr 2023 19:37:15 +0200 Subject: [PATCH 1/6] We no longer support Pygmalion on Colab due to Google's Pygmalion ban --- colab/GPU.ipynb | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/colab/GPU.ipynb b/colab/GPU.ipynb index c22eb8b6..517d0661 100644 --- a/colab/GPU.ipynb +++ b/colab/GPU.ipynb @@ -82,7 +82,7 @@ "#@title <-- Select your model below and then click this to start KoboldAI\n", "#@markdown You can find a description of the models below along with instructions on how to start KoboldAI.\n", "\n", - "Model = \"Nerys V2 6B\" #@param [\"Nerys V2 6B\", \"Nerybus 6B\", \"Erebus 6B\", \"Skein 6B\", \"Janeway 6B\", \"Adventure 6B\", \"PPO_Pygway 6B\", \"Pygmalion 6B\", \"Pygmalion 6B 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\"] {allow-input: true}\n", + "Model = \"Nerys V2 6B\" #@param [\"Nerys V2 6B\", \"Nerybus 6B\", \"Erebus 6B\", \"Skein 6B\", \"Janeway 6B\", \"Adventure 6B\", \"PPO_Pygway 6B\", \"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\"] {allow-input: true}\n", "Version = \"Official\" #@param [\"Official\", \"United\"] {allow-input: true}\n", "Provider = \"Cloudflare\" #@param [\"Localtunnel\", \"Cloudflare\"]\n", "use_google_drive = True #@param {type:\"boolean\"}\n", @@ -129,17 +129,6 @@ " path = \"\"\n", " download = \"\"\n", " Version = \"United\"\n", - "elif Model == \"Pygmalion 6B\":\n", - " Model = \"PygmalionAI/pygmalion-6b\"\n", - " path = \"\"\n", - " download = \"\"\n", - " Version = \"United\"\n", - "elif Model == \"Pygmalion 6B Dev\":\n", - " Model = \"PygmalionAI/pygmalion-6b\"\n", - " Revision = \"--revision dev\"\n", - " path = \"\"\n", - " Version = \"United\"\n", - " download = \"\"\n", "elif Model == \"Lit 6B\":\n", " Model = \"hakurei/lit-6B\"\n", " path = \"\"\n", @@ -264,4 +253,4 @@ } } ] -} +} \ No newline at end of file From fd12214091d33af78c66decf540cde239a798cfd Mon Sep 17 00:00:00 2001 From: henk717 Date: Tue, 4 Apr 2023 19:40:22 +0200 Subject: [PATCH 2/6] Clean the description of the GPU colab --- colab/GPU.ipynb | 2 -- 1 file changed, 2 deletions(-) diff --git a/colab/GPU.ipynb b/colab/GPU.ipynb index 517d0661..c6c1e5ba 100644 --- a/colab/GPU.ipynb +++ b/colab/GPU.ipynb @@ -203,7 +203,6 @@ "| [Janeway](https://huggingface.co/KoboldAI/GPT-Neo-2.7B-Janeway) by Mr Seeker | Novel | Janeway is a model created from Picard's dataset combined with a brand new collection of ebooks. This model is trained on 20% more content than Picard and has been trained on literature from various genres. Although the model is mainly focussed on SFW, romantic scenes might involve a degree of nudity. |\n", "| [Picard](https://huggingface.co/KoboldAI/GPT-Neo-2.7B-Picard) by Mr Seeker | Novel | Picard is a model trained for SFW Novels based on Neo 2.7B. It is focused on Novel style writing without the NSFW bias. While the name suggests a sci-fi model this model is designed for Novels of a variety of genre's. It is meant to be used in KoboldAI's regular mode. |\n", "| [AID](https://huggingface.co/KoboldAI/GPT-Neo-2.7B-AID) by melastacho | Adventure | Also know as Adventure 2.7B this is a clone of the AI Dungeon Classic model and is best known for the epic wackey adventures that AI Dungeon Classic players love. |\n", - "| [Pygmalion](https://huggingface.co/KoboldAI/GPT-J-6B-Adventure) by PygmalionAI | Chatbot | Pygmalion is a chat model that has been based on a few models that came before it. First the model originates from LitV2, it was then trained by Haru on a chat dataset to create ConvoGPT. ConvoGPT was then trained by PygmalionAI on chat data that contains longer responses and emotions. Making for a higher quality chat experience than you can get from other models such as Erebus that are not directly trained on chatting. |\n", "| [Horni LN](https://huggingface.co/KoboldAI/GPT-Neo-2.7B-Horni-LN) by finetune | Novel | This model is based on Horni 2.7B and retains its NSFW knowledge, but was then further biased towards SFW novel stories. If you seek a balance between a SFW Novel model and a NSFW model this model should be a good choice. |\n", "| [Horni](https://huggingface.co/KoboldAI/GPT-Neo-2.7B-Horni) by finetune | NSFW | This model is tuned on Literotica to produce a Novel style model biased towards NSFW content. Can still be used for SFW stories but will have a bias towards NSFW content. It is meant to be used in KoboldAI's regular mode. |\n", "| [Shinen](https://huggingface.co/KoboldAI/GPT-Neo-2.7B-Shinen) by Mr Seeker | NSFW | Shinen is an alternative to the Horni model designed to be more explicit. If Horni is to tame for you Shinen might produce better results. While it is a Novel model it is unsuitable for SFW stories due to its heavy NSFW bias. Shinen will not hold back. It is meant to be used in KoboldAI's regular mode. |\n", @@ -221,7 +220,6 @@ "| [Shinen](https://huggingface.co/KoboldAI/fairseq-dense-13B-Shinen) by Mr Seeker | NSFW | Shinen is an NSFW model trained on a variety of stories from the website Sexstories it contains many different kinks. It has been merged into the larger (and better) Erebus model. |\n", "| [Skein](https://huggingface.co/KoboldAI/GPT-J-6B-Skein) by VE\\_FORBRYDERNE | Adventure | Skein is best used with Adventure mode enabled, it consists of a 4 times larger adventure dataset than the Adventure model making it excellent for text adventure gaming. On top of that it also consists of light novel training further expanding its knowledge and writing capabilities. It can be used with the You filter bias if you wish to write Novels with it, but dedicated Novel models can perform better for this task. |\n", "| [Adventure](https://huggingface.co/KoboldAI/GPT-J-6B-Adventure) by VE\\_FORBRYDERNE | Adventure | Adventure is a 6B model designed to mimick the behavior of AI Dungeon. It is exclusively for Adventure Mode and can take you on the epic and wackey adventures that AI Dungeon players love. It also features the many tropes of AI Dungeon as it has been trained on very similar data. It must be used in second person (You). |\n", - "| [Pygmalion](https://huggingface.co/KoboldAI/GPT-J-6B-Adventure) by PygmalionAI | Chatbot | Pygmalion is a chat model that has been based on a few models that came before it. First the model originates from LitV2, it was then trained by Haru on a chat dataset to create ConvoGPT. ConvoGPT was then trained by PygmalionAI on chat data that contains longer responses and emotions. Making for a higher quality chat experience than you can get from other models such as Erebus that are not directly trained on chatting. |\n", "| [Lit](https://huggingface.co/hakurei/lit-6B) by Haru | NSFW | Lit is a great NSFW model trained by Haru on both a large set of Literotica stories and high quality novels along with tagging support. Creating a high quality model for your NSFW stories. This model is exclusively a novel model and is best used in third person. |\n", "| [OPT](https://huggingface.co/facebook/opt-13b) by Metaseq | Generic | OPT is considered one of the best base models as far as content goes, its behavior has the strengths of both GPT-Neo and Fairseq Dense. Compared to Neo duplicate and unnecessary content has been left out, while additional literature was added in similar to the Fairseq Dense model. The Fairseq Dense model however lacks the broader data that OPT does have. The biggest downfall of OPT is its license, which prohibits any commercial usage, or usage beyond research purposes. |\n", "| [Neo(X)](https://huggingface.co/EleutherAI/gpt-neox-20b) by EleutherAI | Generic | NeoX is the largest EleutherAI model currently available, being a generic model it is not particularly trained towards anything and can do a variety of writing, Q&A and coding tasks. 20B's performance is closely compared to the 13B models and it is worth trying both especially if you have a task that does not involve english writing. Its behavior will be similar to the GPT-J-6B model since they are trained on the same dataset but with more sensitivity towards repetition penalty and with more knowledge. |\n", From 29c2d4b7a6f35bad14b52c7e252da9e20e00aa62 Mon Sep 17 00:00:00 2001 From: henk717 Date: Tue, 4 Apr 2023 19:51:18 +0200 Subject: [PATCH 3/6] Removing Pygmalion from the TPU colab to get it unbanned --- colab/TPU.ipynb | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/colab/TPU.ipynb b/colab/TPU.ipynb index e432b958..48fc7bdc 100644 --- a/colab/TPU.ipynb +++ b/colab/TPU.ipynb @@ -79,7 +79,7 @@ "#@title <-- Select your model below and then click this to start KoboldAI\n", "#@markdown You can find a description of the models below along with instructions on how to start KoboldAI.\n", "\n", - "Model = \"Nerys 13B V2\" #@param [\"Nerys 13B V2\", \"Nerybus 13B\", \"Erebus 13B\", \"Janeway 13B\", \"Shinen 13B\", \"Skein 20B\", \"Erebus 20B\", \"Skein 6B\", \"Janeway 6B\", \"Adventure 6B\", \"Shinen 6B\", \"Pygmalion 6B\", \"Pygmalion 6B Dev\", \"Lit V2 6B\", \"Lit 6B\", \"NeoX 20B\", \"OPT 13B\", \"Fairseq Dense 13B\", \"GPT-J-6B\"] {allow-input: true}\n", + "Model = \"Nerys 13B V2\" #@param [\"Nerys 13B V2\", \"Nerybus 13B\", \"Erebus 13B\", \"Janeway 13B\", \"Shinen 13B\", \"Skein 20B\", \"Erebus 20B\", \"Skein 6B\", \"Janeway 6B\", \"Adventure 6B\", \"Shinen 6B\", \"Lit V2 6B\", \"Lit 6B\", \"NeoX 20B\", \"OPT 13B\", \"Fairseq Dense 13B\", \"GPT-J-6B\"] {allow-input: true}\n", "Version = \"Official\" #@param [\"Official\", \"United\"] {allow-input: true}\n", "Provider = \"Cloudflare\" #@param [\"Localtunnel\", \"Cloudflare\"]\n", "use_google_drive = True #@param {type:\"boolean\"}\n", @@ -148,17 +148,6 @@ " Model = \"KoboldAI/GPT-J-6B-Adventure\"\n", " path = \"\"\n", " download = \"\"\n", - "elif Model == \"Pygmalion 6B\":\n", - " Model = \"PygmalionAI/pygmalion-6b\"\n", - " path = \"\"\n", - " download = \"\"\n", - " Version = \"United\"\n", - "elif Model == \"Pygmalion 6B Dev\":\n", - " Model = \"PygmalionAI/pygmalion-6b\"\n", - " Revision = \"--revision dev\"\n", - " path = \"\"\n", - " Version = \"United\"\n", - " download = \"\"\n", "elif Model == \"Lit V2 6B\":\n", " Model = \"hakurei/litv2-6B-rev3\"\n", " path = \"\"\n", @@ -208,7 +197,6 @@ "| [Shinen](https://huggingface.co/KoboldAI/fairseq-dense-13B-Shinen) by Mr Seeker | NSFW | Shinen is an NSFW model trained on a variety of stories from the website Sexstories it contains many different kinks. It has been merged into the larger (and better) Erebus model. |\n", "| [Skein](https://huggingface.co/KoboldAI/GPT-J-6B-Skein) by VE\\_FORBRYDERNE | Adventure | Skein is best used with Adventure mode enabled, it consists of a 4 times larger adventure dataset than the Adventure model making it excellent for text adventure gaming. On top of that it also consists of light novel training further expanding its knowledge and writing capabilities. It can be used with the You filter bias if you wish to write Novels with it, but dedicated Novel models can perform better for this task. |\n", "| [Adventure](https://huggingface.co/KoboldAI/GPT-J-6B-Adventure) by VE\\_FORBRYDERNE | Adventure | Adventure is a 6B model designed to mimick the behavior of AI Dungeon. It is exclusively for Adventure Mode and can take you on the epic and wackey adventures that AI Dungeon players love. It also features the many tropes of AI Dungeon as it has been trained on very similar data. It must be used in second person (You). |\n", - "| [Pygmalion](https://huggingface.co/KoboldAI/GPT-J-6B-Adventure) by PygmalionAI | Chatbot | Pygmalion is a chat model that has been based on a few models that came before it. First the model originates from LitV2, it was then trained by Haru on a chat dataset to create ConvoGPT. ConvoGPT was then trained by PygmalionAI on chat data that contains longer responses and emotions. Making for a higher quality chat experience than you can get from other models such as Erebus that are not directly trained on chatting. |\n", "| [Lit](https://huggingface.co/hakurei/lit-6B) ([V2](https://huggingface.co/hakurei/litv2-6B-rev3)) by Haru | NSFW | Lit is a great NSFW model trained by Haru on both a large set of Literotica stories and high quality novels along with tagging support. Creating a high quality model for your NSFW stories. This model is exclusively a novel model and is best used in third person. |\n", "| [OPT](https://huggingface.co/facebook/opt-13b) by Metaseq | Generic | OPT is considered one of the best base models as far as content goes, its behavior has the strengths of both GPT-Neo and Fairseq Dense. Compared to Neo duplicate and unnecessary content has been left out, while additional literature was added in similar to the Fairseq Dense model. The Fairseq Dense model however lacks the broader data that OPT does have. The biggest downfall of OPT is its license, which prohibits any commercial usage, or usage beyond research purposes. |\n", "| [Neo(X)](https://huggingface.co/EleutherAI/gpt-neox-20b) by EleutherAI | Generic | NeoX is the largest EleutherAI model currently available, being a generic model it is not particularly trained towards anything and can do a variety of writing, Q&A and coding tasks. 20B's performance is closely compared to the 13B models and it is worth trying both especially if you have a task that does not involve english writing. Its behavior will be similar to the GPT-J-6B model since they are trained on the same dataset but with more sensitivity towards repetition penalty and with more knowledge. |\n", From 71e5d23a5b3619fa3cb02491fe27d80356575b22 Mon Sep 17 00:00:00 2001 From: YellowRoseCx <80486540+YellowRoseCx@users.noreply.github.com> Date: Wed, 5 Apr 2023 21:23:24 -0500 Subject: [PATCH 4/6] Add IP whitelisting to --host --- aiserver.py | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 88 insertions(+), 3 deletions(-) diff --git a/aiserver.py b/aiserver.py index 7cbbc8ac..c22be16c 100644 --- a/aiserver.py +++ b/aiserver.py @@ -73,6 +73,8 @@ import torch from transformers import StoppingCriteria, GPT2Tokenizer, GPT2LMHeadModel, GPTNeoForCausalLM, GPTNeoModel, AutoModelForCausalLM, AutoModelForSeq2SeqLM, AutoTokenizer, PreTrainedModel, modeling_utils, AutoModelForTokenClassification from transformers import __version__ as transformers_version import transformers +import ipaddress +from functools import wraps try: from transformers.models.opt.modeling_opt import OPTDecoder except: @@ -86,6 +88,9 @@ from PIL import Image from io import BytesIO global tpu_mtj_backend +global allowed_ips +allowed_ips = set() # empty set +enable_whitelist = False if lupa.LUA_VERSION[:2] != (5, 4): @@ -1469,13 +1474,15 @@ def spRequest(filename): #==================================================================# def general_startup(override_args=None): global args + global enable_whitelist + global allowed_ips # Parsing Parameters parser = argparse.ArgumentParser(description="KoboldAI Server") parser.add_argument("--remote", action='store_true', help="Optimizes KoboldAI for Remote Play") parser.add_argument("--noaimenu", action='store_true', help="Disables the ability to select the AI") parser.add_argument("--ngrok", action='store_true', help="Optimizes KoboldAI for Remote Play using Ngrok") parser.add_argument("--localtunnel", action='store_true', help="Optimizes KoboldAI for Remote Play using Localtunnel") - parser.add_argument("--host", action='store_true', help="Optimizes KoboldAI for Remote Play without using a proxy service") + parser.add_argument("--host", type=str, default="", nargs="?", const="", help="Optimizes KoboldAI for LAN Remote Play without using a proxy service. --host opens to all LAN. Enable IP whitelisting by using a comma separated IP list. Supports individual IPs, ranges, and subnets --host 127.0.0.1,127.0.0.2,127.0.0.3,192.168.1.0-192.168.1.255,10.0.0.0/24,etc") parser.add_argument("--port", type=int, help="Specify the port on which the application will be joinable") parser.add_argument("--aria2_port", type=int, help="Specify the port on which aria2's RPC interface will be open if aria2 is installed (defaults to 6799)") parser.add_argument("--model", help="Specify the Model Type to skip the Menu") @@ -1525,6 +1532,10 @@ def general_startup(override_args=None): utils.args = args + + + + #load system and user settings for setting in ['user_settings', 'system_settings']: @@ -1602,9 +1613,32 @@ def general_startup(override_args=None): if args.localtunnel: koboldai_vars.host = True; + if args.host == "": + koboldai_vars.host = True + args.unblock = True if args.host: - koboldai_vars.host = True; - args.unblock = True; + # This means --host option was submitted without an argument + # Enable all LAN IPs (0.0.0.0/0) + if args.host != "": + # Check if --host option was submitted with an argument + # Parse the supplied IP(s) and add them to the allowed IPs list + koboldai_vars.host = True + args.unblock = True + enable_whitelist = True + for ip_str in args.host.split(","): + if "/" in ip_str: + allowed_ips |= set(str(ip) for ip in ipaddress.IPv4Network(ip_str, strict=False).hosts()) + elif "-" in ip_str: + start_ip, end_ip = ip_str.split("-") + start_ip_int = int(ipaddress.IPv4Address(start_ip)) + end_ip_int = int(ipaddress.IPv4Address(end_ip)) + allowed_ips |= set(str(ipaddress.IPv4Address(ip)) for ip in range(start_ip_int, end_ip_int + 1)) + else: + allowed_ips.add(ip_str.strip()) + # Sort and print the allowed IPs list + allowed_ips = sorted(allowed_ips, key=lambda ip: int(''.join([i.zfill(3) for i in ip.split('.')]))) + print(f"Allowed IPs: {allowed_ips}") + if args.cpu: koboldai_vars.use_colab_tpu = False @@ -3450,22 +3484,52 @@ def load_model(use_gpu=True, gpu_layers=None, disk_layers=None, initial_load=Fal print(format(colors.GREEN) + "KoboldAI has finished loading and is available at the following link for UI 1: " + koboldai_vars.cloudflare_link + format(colors.END)) print(format(colors.GREEN) + "KoboldAI has finished loading and is available at the following link for UI 2: " + koboldai_vars.cloudflare_link + "/new_ui" + format(colors.END)) + +# Setup IP Whitelisting +# Define a function to check if IP is allowed +def is_allowed_ip(): + global allowed_ips + client_ip = request.remote_addr + if request.path != '/genre_data.json': + print("Connection Attempt: " + request.remote_addr) + print("Allowed?: ", request.remote_addr in allowed_ips) + return client_ip in allowed_ips + + + +# Define a decorator to enforce IP whitelisting +def require_allowed_ip(func): + @wraps(func) + def decorated(*args, **kwargs): + + if enable_whitelist and not is_allowed_ip(): + return abort(403) + return func(*args, **kwargs) + return decorated + + + + # Set up Flask routes @app.route('/') @app.route('/index') +@require_allowed_ip def index(): if args.no_ui: return redirect('/api/latest') else: return render_template('index.html', hide_ai_menu=args.noaimenu) @app.route('/api', strict_slashes=False) +@require_allowed_ip def api(): return redirect('/api/latest') @app.route('/favicon.ico') + def favicon(): return send_from_directory(app.root_path, 'koboldai.ico', mimetype='image/vnd.microsoft.icon') @app.route('/download') +@require_allowed_ip def download(): if args.no_ui: raise NotFound() @@ -4126,6 +4190,8 @@ def execute_outmod(): #==================================================================# @socketio.on('connect') def do_connect(): + print("Connection Attempt: " + request.remote_addr) + print("Allowed?: ", request.remote_addr in allowed_ips) if request.args.get("rely") == "true": return logger.info("Client connected! UI_{}".format(request.args.get('ui'))) @@ -8021,6 +8087,7 @@ def show_folder_usersripts(data): # UI V2 CODE #==================================================================# @app.route('/new_ui') +@require_allowed_ip @logger.catch def new_ui_index(): if args.no_ui: @@ -8048,6 +8115,7 @@ def ui2_connect(): # UI V2 CODE Themes #==================================================================# @app.route('/themes/') +#@require_allowed_ip @logger.catch def ui2_serve_themes(path): return send_from_directory('themes', path) @@ -8086,6 +8154,7 @@ def upload_file(data): get_files_folders(session['current_folder']) @app.route("/upload_kai_story/", methods=["POST"]) +@require_allowed_ip @logger.catch def UI_2_upload_kai_story(file_name: str): @@ -8549,6 +8618,7 @@ def directory_to_zip_data(directory: str, overrides: Optional[dict]) -> bytes: # Save story to json #==================================================================# @app.route("/story_download") +@require_allowed_ip @logger.catch def UI_2_download_story(): if args.no_ui: @@ -9011,6 +9081,7 @@ def UI_2_delete_wi_folder(folder): # Event triggered when user exports world info folder #==================================================================# @app.route('/export_world_info_folder') +@require_allowed_ip @logger.catch def UI_2_export_world_info_folder(): if 'folder' in request.args: @@ -9038,6 +9109,7 @@ def UI_2_upload_world_info_folder(data): koboldai_vars.calc_ai_text() @app.route("/upload_wi", methods=["POST"]) +@require_allowed_ip @logger.catch def UI_2_import_world_info(): wi_data = request.get_json() @@ -9115,6 +9187,7 @@ def UI_2_update_wi_keys(data): socketio.emit("world_info_entry", koboldai_vars.worldinfo_v2.world_info[uid], broadcast=True, room="UI_2") @app.route("/set_wi_image/", methods=["POST"]) +@require_allowed_ip @logger.catch def UI_2_set_wi_image(uid): if uid < 0: @@ -9146,6 +9219,7 @@ def UI_2_set_wi_image(uid): return ":)" @app.route("/get_wi_image/", methods=["GET"]) +@require_allowed_ip @logger.catch def UI_2_get_wi_image(uid): if args.no_ui: @@ -9157,6 +9231,7 @@ def UI_2_get_wi_image(uid): return ":( Couldn't find image", 204 @app.route("/set_commentator_picture/", methods=["POST"]) +@require_allowed_ip @logger.catch def UI_2_set_commentator_image(commentator_id): data = request.get_data() @@ -9165,6 +9240,7 @@ def UI_2_set_commentator_image(commentator_id): return ":)" @app.route("/image_db.json", methods=["GET"]) +@require_allowed_ip @logger.catch def UI_2_get_image_db(): if args.no_ui: @@ -9175,6 +9251,7 @@ def UI_2_get_image_db(): return jsonify([]) @app.route("/action_composition.json", methods=["GET"]) +@require_allowed_ip @logger.catch def UI_2_get_action_composition(): if args.no_ui: @@ -9200,6 +9277,7 @@ def UI_2_get_action_composition(): return jsonify(ret) @app.route("/generated_images/") +@require_allowed_ip def UI_2_send_generated_images(path): return send_from_directory(koboldai_vars.save_paths.generated_images, path) @@ -9509,6 +9587,7 @@ def UI_2_generate_wi(data): socketio.emit("generated_wi", {"uid": uid, "field": field, "out": out_text}, room="UI_2") @app.route("/generate_raw", methods=["GET"]) +@require_allowed_ip def UI_2_generate_raw(): prompt = request.args.get("prompt") @@ -10210,6 +10289,7 @@ def UI_2_privacy_mode(data): # Genres #==================================================================# @app.route("/genre_data.json", methods=["GET"]) +@require_allowed_ip def UI_2_get_applicable_genres(): with open("data/genres.json", "r") as file: genre_list = json.load(file) @@ -10275,12 +10355,14 @@ def UI_2_get_log(data): emit("log_message", web_log_history) @app.route("/get_log") +@require_allowed_ip def UI_2_get_log_get(): if args.no_ui: return redirect('/api/latest') return {'aiserver_log': web_log_history} @app.route("/test_match") +@require_allowed_ip @logger.catch def UI_2_test_match(): koboldai_vars.assign_world_info_to_actions() @@ -10290,6 +10372,7 @@ def UI_2_test_match(): # Download of the audio file #==================================================================# @app.route("/audio") +@require_allowed_ip @logger.catch def UI_2_audio(): if args.no_ui: @@ -10316,6 +10399,7 @@ def UI_2_audio(): # Download of the image for an action #==================================================================# @app.route("/action_image") +@require_allowed_ip @logger.catch def UI_2_action_image(): if args.no_ui: @@ -10375,6 +10459,7 @@ def model_info(): return {"Model Type": "Read Only", "Model Size": "0", "Model Name": koboldai_vars.model.replace("_", "/")} @app.route("/vars") +@require_allowed_ip @logger.catch def show_vars(): if args.no_ui: From ac98cd6dd1b9f0d3372694793e11716501521edb Mon Sep 17 00:00:00 2001 From: YellowRoseCx <80486540+YellowRoseCx@users.noreply.github.com> Date: Wed, 5 Apr 2023 21:27:59 -0500 Subject: [PATCH 5/6] add IP_whitelisting to koboldai_settings.py --- koboldai_settings.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/koboldai_settings.py b/koboldai_settings.py index d1bc1e5d..be86e302 100644 --- a/koboldai_settings.py +++ b/koboldai_settings.py @@ -19,6 +19,8 @@ import inspect serverstarted = False queue = None multi_story = False +global enable_whitelist +enable_whitelist = False if importlib.util.find_spec("tortoise") is not None: from tortoise import api @@ -654,6 +656,7 @@ class model_settings(settings): default_settings = {"rep_pen" : 1.1, "rep_pen_slope": 0.7, "rep_pen_range": 1024, "temp": 0.5, "top_p": 0.9, "top_k": 0, "top_a": 0.0, "tfs": 1.0, "typical": 1.0, "sampler_order": [6,0,1,2,3,4,5]} def __init__(self, socketio, koboldai_vars): + self.enable_whitelist = False self._socketio = socketio self.reset_for_model_load() self.model = "" # Model ID string chosen at startup @@ -2745,4 +2748,4 @@ default_preset = { ] } badwordsids_default = [[6880], [50256], [42496], [4613], [17414], [22039], [16410], [27], [29], [38430], [37922], [15913], [24618], [28725], [58], [47175], [36937], [26700], [12878], [16471], [37981], [5218], [29795], [13412], [45160], [3693], [49778], [4211], [20598], [36475], [33409], [44167], [32406], [29847], [29342], [42669], [685], [25787], [7359], [3784], [5320], [33994], [33490], [34516], [43734], [17635], [24293], [9959], [23785], [21737], [28401], [18161], [26358], [32509], [1279], [38155], [18189], [26894], [6927], [14610], [23834], [11037], [14631], [26933], [46904], [22330], [25915], [47934], [38214], [1875], [14692], [41832], [13163], [25970], [29565], [44926], [19841], [37250], [49029], [9609], [44438], [16791], [17816], [30109], [41888], [47527], [42924], [23984], [49074], [33717], [31161], [49082], [30138], [31175], [12240], [14804], [7131], [26076], [33250], [3556], [38381], [36338], [32756], [46581], [17912], [49146]] # Tokenized array of badwords used to prevent AI artifacting -badwordsids_neox = [[0], [1], [44162], [9502], [12520], [31841], [36320], [49824], [34417], [6038], [34494], [24815], [26635], [24345], [3455], [28905], [44270], [17278], [32666], [46880], [7086], [43189], [37322], [17778], [20879], [49821], [3138], [14490], [4681], [21391], [26786], [43134], [9336], [683], [48074], [41256], [19181], [29650], [28532], [36487], [45114], [46275], [16445], [15104], [11337], [1168], [5647], [29], [27482], [44965], [43782], [31011], [42944], [47389], [6334], [17548], [38329], [32044], [35487], [2239], [34761], [7444], [1084], [12399], [18990], [17636], [39083], [1184], [35830], [28365], [16731], [43467], [47744], [1138], [16079], [40116], [45564], [18297], [42368], [5456], [18022], [42696], [34476], [23505], [23741], [39334], [37944], [45382], [38709], [33440], [26077], [43600], [34418], [36033], [6660], [48167], [48471], [15775], [19884], [41533], [1008], [31053], [36692], [46576], [20095], [20629], [31759], [46410], [41000], [13488], [30952], [39258], [16160], [27655], [22367], [42767], [43736], [49694], [13811], [12004], [46768], [6257], [37471], [5264], [44153], [33805], [20977], [21083], [25416], [14277], [31096], [42041], [18331], [33376], [22372], [46294], [28379], [38475], [1656], [5204], [27075], [50001], [16616], [11396], [7748], [48744], [35402], [28120], [41512], [4207], [43144], [14767], [15640], [16595], [41305], [44479], [38958], [18474], [22734], [30522], [46267], [60], [13976], [31830], [48701], [39822], [9014], [21966], [31422], [28052], [34607], [2479], [3851], [32214], [44082], [45507], [3001], [34368], [34758], [13380], [38363], [4299], [46802], [30996], [12630], [49236], [7082], [8795], [5218], [44740], [9686], [9983], [45301], [27114], [40125], [1570], [26997], [544], [5290], [49193], [23781], [14193], [40000], [2947], [43781], [9102], [48064], [42274], [18772], [49384], [9884], [45635], [43521], [31258], [32056], [47686], [21760], [13143], [10148], [26119], [44308], [31379], [36399], [23983], [46694], [36134], [8562], [12977], [35117], [28591], [49021], [47093], [28653], [29013], [46468], [8605], [7254], [25896], [5032], [8168], [36893], [38270], [20499], [27501], [34419], [29547], [28571], [36586], [20871], [30537], [26842], [21375], [31148], [27618], [33094], [3291], [31789], [28391], [870], [9793], [41361], [47916], [27468], [43856], [8850], [35237], [15707], [47552], [2730], [41449], [45488], [3073], [49806], [21938], [24430], [22747], [20924], [46145], [20481], [20197], [8239], [28231], [17987], [42804], [47269], [29972], [49884], [21382], [46295], [36676], [34616], [3921], [26991], [27720], [46265], [654], [9855], [40354], [5291], [34904], [44342], [2470], [14598], [880], [19282], [2498], [24237], [21431], [16369], [8994], [44524], [45662], [13663], [37077], [1447], [37786], [30863], [42854], [1019], [20322], [4398], [12159], [44072], [48664], [31547], [18736], [9259], [31], [16354], [21810], [4357], [37982], [5064], [2033], [32871], [47446], [62], [22158], [37387], [8743], [47007], [17981], [11049], [4622], [37916], [36786], [35138], [29925], [14157], [18095], [27829], [1181], [22226], [5709], [4725], [30189], [37014], [1254], [11380], [42989], [696], [24576], [39487], [30119], [1092], [8088], [2194], [9899], [14412], [21828], [3725], [13544], [5180], [44679], [34398], [3891], [28739], [14219], [37594], [49550], [11326], [6904], [17266], [5749], [10174], [23405], [9955], [38271], [41018], [13011], [48392], [36784], [24254], [21687], [23734], [5413], [41447], [45472], [10122], [17555], [15830], [47384], [12084], [31350], [47940], [11661], [27988], [45443], [905], [49651], [16614], [34993], [6781], [30803], [35869], [8001], [41604], [28118], [46462], [46762], [16262], [17281], [5774], [10943], [5013], [18257], [6750], [4713], [3951], [11899], [38791], [16943], [37596], [9318], [18413], [40473], [13208], [16375]] \ No newline at end of file +badwordsids_neox = [[0], [1], [44162], [9502], [12520], [31841], [36320], [49824], [34417], [6038], [34494], [24815], [26635], [24345], [3455], [28905], [44270], [17278], [32666], [46880], [7086], [43189], [37322], [17778], [20879], [49821], [3138], [14490], [4681], [21391], [26786], [43134], [9336], [683], [48074], [41256], [19181], [29650], [28532], [36487], [45114], [46275], [16445], [15104], [11337], [1168], [5647], [29], [27482], [44965], [43782], [31011], [42944], [47389], [6334], [17548], [38329], [32044], [35487], [2239], [34761], [7444], [1084], [12399], [18990], [17636], [39083], [1184], [35830], [28365], [16731], [43467], [47744], [1138], [16079], [40116], [45564], [18297], [42368], [5456], [18022], [42696], [34476], [23505], [23741], [39334], [37944], [45382], [38709], [33440], [26077], [43600], [34418], [36033], [6660], [48167], [48471], [15775], [19884], [41533], [1008], [31053], [36692], [46576], [20095], [20629], [31759], [46410], [41000], [13488], [30952], [39258], [16160], [27655], [22367], [42767], [43736], [49694], [13811], [12004], [46768], [6257], [37471], [5264], [44153], [33805], [20977], [21083], [25416], [14277], [31096], [42041], [18331], [33376], [22372], [46294], [28379], [38475], [1656], [5204], [27075], [50001], [16616], [11396], [7748], [48744], [35402], [28120], [41512], [4207], [43144], [14767], [15640], [16595], [41305], [44479], [38958], [18474], [22734], [30522], [46267], [60], [13976], [31830], [48701], [39822], [9014], [21966], [31422], [28052], [34607], [2479], [3851], [32214], [44082], [45507], [3001], [34368], [34758], [13380], [38363], [4299], [46802], [30996], [12630], [49236], [7082], [8795], [5218], [44740], [9686], [9983], [45301], [27114], [40125], [1570], [26997], [544], [5290], [49193], [23781], [14193], [40000], [2947], [43781], [9102], [48064], [42274], [18772], [49384], [9884], [45635], [43521], [31258], [32056], [47686], [21760], [13143], [10148], [26119], [44308], [31379], [36399], [23983], [46694], [36134], [8562], [12977], [35117], [28591], [49021], [47093], [28653], [29013], [46468], [8605], [7254], [25896], [5032], [8168], [36893], [38270], [20499], [27501], [34419], [29547], [28571], [36586], [20871], [30537], [26842], [21375], [31148], [27618], [33094], [3291], [31789], [28391], [870], [9793], [41361], [47916], [27468], [43856], [8850], [35237], [15707], [47552], [2730], [41449], [45488], [3073], [49806], [21938], [24430], [22747], [20924], [46145], [20481], [20197], [8239], [28231], [17987], [42804], [47269], [29972], [49884], [21382], [46295], [36676], [34616], [3921], [26991], [27720], [46265], [654], [9855], [40354], [5291], [34904], [44342], [2470], [14598], [880], [19282], [2498], [24237], [21431], [16369], [8994], [44524], [45662], [13663], [37077], [1447], [37786], [30863], [42854], [1019], [20322], [4398], [12159], [44072], [48664], [31547], [18736], [9259], [31], [16354], [21810], [4357], [37982], [5064], [2033], [32871], [47446], [62], [22158], [37387], [8743], [47007], [17981], [11049], [4622], [37916], [36786], [35138], [29925], [14157], [18095], [27829], [1181], [22226], [5709], [4725], [30189], [37014], [1254], [11380], [42989], [696], [24576], [39487], [30119], [1092], [8088], [2194], [9899], [14412], [21828], [3725], [13544], [5180], [44679], [34398], [3891], [28739], [14219], [37594], [49550], [11326], [6904], [17266], [5749], [10174], [23405], [9955], [38271], [41018], [13011], [48392], [36784], [24254], [21687], [23734], [5413], [41447], [45472], [10122], [17555], [15830], [47384], [12084], [31350], [47940], [11661], [27988], [45443], [905], [49651], [16614], [34993], [6781], [30803], [35869], [8001], [41604], [28118], [46462], [46762], [16262], [17281], [5774], [10943], [5013], [18257], [6750], [4713], [3951], [11899], [38791], [16943], [37596], [9318], [18413], [40473], [13208], [16375]] From bde9c6980fadd5670a045fe7741649dcc116c993 Mon Sep 17 00:00:00 2001 From: Henk Date: Fri, 14 Apr 2023 14:13:46 +0200 Subject: [PATCH 6/6] Transformers 4.28 support --- aiserver.py | 2 +- environments/huggingface.yml | 2 +- environments/rocm.yml | 2 +- requirements.txt | 2 +- requirements_mtj.txt | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/aiserver.py b/aiserver.py index c22be16c..2ec6d817 100644 --- a/aiserver.py +++ b/aiserver.py @@ -2951,7 +2951,7 @@ def load_model(use_gpu=True, gpu_layers=None, disk_layers=None, initial_load=Fal koboldai_vars.status_message = "Loading model" koboldai_vars.total_layers = num_tensors koboldai_vars.loaded_layers = 0 - utils.bar = tqdm(total=num_tensors, desc="Loading model tensors", file=Send_to_socketio()) + utils.bar = tqdm(total=num_tensors, desc="Loading model tensors", file=Send_to_socketio(), position=1) with zipfile.ZipFile(f, "r") as z: try: diff --git a/environments/huggingface.yml b/environments/huggingface.yml index 2eb1bfe0..138993dd 100644 --- a/environments/huggingface.yml +++ b/environments/huggingface.yml @@ -30,7 +30,7 @@ dependencies: - flask-ngrok - flask-cors - lupa==1.10 - - transformers==4.25.1 + - transformers==4.28.0 - huggingface_hub==0.12.1 - safetensors - accelerate==0.18.0 diff --git a/environments/rocm.yml b/environments/rocm.yml index 43fd331f..e28c86cb 100644 --- a/environments/rocm.yml +++ b/environments/rocm.yml @@ -29,7 +29,7 @@ dependencies: - flask-ngrok - flask-cors - lupa==1.10 - - transformers==4.25.1 + - transformers==4.28.0 - huggingface_hub==0.12.1 - safetensors - accelerate diff --git a/requirements.txt b/requirements.txt index d85c61fd..c2a61ca6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -transformers==4.25.1 +transformers==4.28.0 huggingface_hub==0.12.1 Flask==2.2.3 Flask-SocketIO==5.3.2 diff --git a/requirements_mtj.txt b/requirements_mtj.txt index 076d9429..37b76a23 100644 --- a/requirements_mtj.txt +++ b/requirements_mtj.txt @@ -5,7 +5,7 @@ requests dm-haiku == 0.0.5 jax == 0.2.21 jaxlib >= 0.1.69, <= 0.3.7 -transformers == 4.25.1 +transformers == 4.28.0 chex == 0.1.5 huggingface_hub==0.12.1 progressbar2