From 3eda7269f72bfa954a13aebb9d965b9c7dad9e61 Mon Sep 17 00:00:00 2001 From: Henk Date: Sat, 15 Apr 2023 14:58:24 +0200 Subject: [PATCH 1/8] Fix incorrect host merge --- aiserver.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/aiserver.py b/aiserver.py index 2ec6d817..59cfac0c 100644 --- a/aiserver.py +++ b/aiserver.py @@ -1613,9 +1613,6 @@ 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: # This means --host option was submitted without an argument # Enable all LAN IPs (0.0.0.0/0) From 67334bd69848bc8f3c00f1015f9f95170d2c98a3 Mon Sep 17 00:00:00 2001 From: Henk Date: Sat, 15 Apr 2023 17:45:00 +0200 Subject: [PATCH 2/8] Pin accelerate version --- environments/rocm.yml | 2 +- requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/environments/rocm.yml b/environments/rocm.yml index e28c86cb..c3e95496 100644 --- a/environments/rocm.yml +++ b/environments/rocm.yml @@ -32,7 +32,7 @@ dependencies: - transformers==4.28.0 - huggingface_hub==0.12.1 - safetensors - - accelerate + - accelerate==0.18.0 - git+https://github.com/VE-FORBRYDERNE/mkultra - ansi2html - flask_compress diff --git a/requirements.txt b/requirements.txt index c2a61ca6..23468656 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,7 +15,7 @@ markdown bleach==4.1.0 sentencepiece protobuf -accelerate +accelerate==0.18.0 flask-session==0.4.0 marshmallow>=3.13 apispec-webframeworks From b68860b3de1adef4e162834bd524c92e39dbe264 Mon Sep 17 00:00:00 2001 From: Henk Date: Sat, 15 Apr 2023 18:31:39 +0200 Subject: [PATCH 3/8] Workaround to make --host work again --- aiserver.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/aiserver.py b/aiserver.py index 59cfac0c..886a802e 100644 --- a/aiserver.py +++ b/aiserver.py @@ -1482,7 +1482,7 @@ def general_startup(override_args=None): 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", 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("--host", type=str, default="Disabled", 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") @@ -1613,14 +1613,14 @@ def general_startup(override_args=None): if args.localtunnel: koboldai_vars.host = True; - if args.host: + if args.host != "Disabled": # This means --host option was submitted without an argument # Enable all LAN IPs (0.0.0.0/0) + koboldai_vars.host = True + args.unblock = True 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: @@ -1637,6 +1637,7 @@ def general_startup(override_args=None): print(f"Allowed IPs: {allowed_ips}") + if args.cpu: koboldai_vars.use_colab_tpu = False From b1d3a37fb082197115765cc16e8faa074f1920b4 Mon Sep 17 00:00:00 2001 From: Henk Date: Sun, 16 Apr 2023 19:31:17 +0200 Subject: [PATCH 4/8] <|comments|> now are [<|comments|>] to support OA --- koboldai_settings.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/koboldai_settings.py b/koboldai_settings.py index be86e302..fdd89ba9 100644 --- a/koboldai_settings.py +++ b/koboldai_settings.py @@ -1204,13 +1204,13 @@ class undefined_settings(settings): class system_settings(settings): local_only_variables = ['lua_state', 'lua_logname', 'lua_koboldbridge', 'lua_kobold', 'lua_koboldcore', 'regex_sl', 'acregex_ai', 'acregex_ui', 'comregex_ai', - 'comregex_ui', 'sp', '_horde_pid', 'inference_config', 'image_pipeline', + 'sp', '_horde_pid', 'inference_config', 'image_pipeline', 'summarizer', 'summary_tokenizer', 'tts_model', 'rng_states'] no_save_variables = ['lua_state', 'lua_logname', 'lua_koboldbridge', 'lua_kobold', 'lua_koboldcore', 'sp', 'sp_length', '_horde_pid', 'horde_share', 'aibusy', 'serverstarted', 'inference_config', 'image_pipeline', 'summarizer', 'summary_tokenizer', 'use_colab_tpu', 'noai', 'disable_set_aibusy', 'cloudflare_link', 'tts_model', - 'generating_image', 'bit_8_available', 'host', 'hascuda', 'usegpu', 'rng_states'] + 'generating_image', 'bit_8_available', 'host', 'hascuda', 'usegpu', 'rng_states', 'comregex_ai', 'comregex_ui'] settings_name = "system" def __init__(self, socketio, koboldai_var): self._socketio = socketio @@ -1252,8 +1252,8 @@ class system_settings(settings): self.regex_sl = re.compile(r'\n*(?<=.) *\n(.|\n)*') # Pattern for limiting the output to a single line self.acregex_ai = re.compile(r'\n* *>(.|\n)*') # Pattern for matching adventure actions from the AI so we can remove them self.acregex_ui = re.compile(r'^ *(>.*)$', re.MULTILINE) # Pattern for matching actions in the HTML-escaped story so we can apply colouring, etc (make sure to encase part to format in parentheses) - self.comregex_ai = re.compile(r'(?:\n<\|(?:.|\n)*?\|>(?=\n|$))|(?:<\|(?:.|\n)*?\|>\n?)') # Pattern for matching comments to remove them before sending them to the AI - self.comregex_ui = re.compile(r'(<\|(?:.|\n)*?\|>)') # Pattern for matching comments in the editor + self.comregex_ai = re.compile(r'(?:\n\[<\|(?:.|\n)*?\|>\](?=\n|$))|(?:\[<\|(?:.|\n)*?\|>\]\n?)') # Pattern for matching comments to remove them before sending them to the AI + self.comregex_ui = re.compile(r'(\[<\|(?:.|\n)*?\|>\])') # Pattern for matching comments in the editor self.host = False self.flaskwebgui = False self.quiet = False # If set will suppress any story text from being printed to the console (will only be seen on the client web page) From 2926dac72b4c8cd5a2c93eaad4d901cc109e66d4 Mon Sep 17 00:00:00 2001 From: Henk Date: Sun, 16 Apr 2023 23:59:13 +0200 Subject: [PATCH 5/8] Don't print allowed_ips if unused --- aiserver.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/aiserver.py b/aiserver.py index 886a802e..b8ff4f3e 100644 --- a/aiserver.py +++ b/aiserver.py @@ -3490,7 +3490,8 @@ def is_allowed_ip(): 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) + if allowed_ips: + print("Allowed?: ", request.remote_addr in allowed_ips) return client_ip in allowed_ips @@ -4189,7 +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 allowed_ips: + 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'))) From fcba26f631e7efcd4a92de206d2bd6da40ed65c3 Mon Sep 17 00:00:00 2001 From: ebolam Date: Sun, 16 Apr 2023 20:32:51 -0400 Subject: [PATCH 6/8] Fix for uploading files in UI2 --- koboldai_settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/koboldai_settings.py b/koboldai_settings.py index fdd89ba9..06a15e4e 100644 --- a/koboldai_settings.py +++ b/koboldai_settings.py @@ -1205,7 +1205,7 @@ class system_settings(settings): local_only_variables = ['lua_state', 'lua_logname', 'lua_koboldbridge', 'lua_kobold', 'lua_koboldcore', 'regex_sl', 'acregex_ai', 'acregex_ui', 'comregex_ai', 'sp', '_horde_pid', 'inference_config', 'image_pipeline', - 'summarizer', 'summary_tokenizer', 'tts_model', 'rng_states'] + 'summarizer', 'summary_tokenizer', 'tts_model', 'rng_states', 'comregex_ai', 'comregex_ui'] no_save_variables = ['lua_state', 'lua_logname', 'lua_koboldbridge', 'lua_kobold', 'lua_koboldcore', 'sp', 'sp_length', '_horde_pid', 'horde_share', 'aibusy', 'serverstarted', 'inference_config', 'image_pipeline', 'summarizer', From a34ce85d21ac750b6a0b69a3e33ff24e9179a224 Mon Sep 17 00:00:00 2001 From: ebolam Date: Sun, 16 Apr 2023 20:43:03 -0400 Subject: [PATCH 7/8] Fix for UI1 remote mode file loading from browser --- aiserver.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/aiserver.py b/aiserver.py index b8ff4f3e..9dd621ef 100644 --- a/aiserver.py +++ b/aiserver.py @@ -7454,13 +7454,13 @@ def loadRequest(loadpath, filename=None): if not loadpath: return - + #Original UI only sends the story name and assumes it's always a .json file... here we check to see if it's a directory to load that way - if not os.path.exists(loadpath): + if not isinstance(loadpath, dict) and not os.path.exists(loadpath): if os.path.exists(loadpath.replace(".json", "")): loadpath = loadpath.replace(".json", "") - if os.path.isdir(loadpath): + if not isinstance(loadpath, dict) and os.path.isdir(loadpath): if not valid_v3_story(loadpath): raise RuntimeError(f"Tried to load {loadpath}, a non-save directory.") koboldai_vars.update_story_path_structure(loadpath) From d16a3f4dc3746e65bc16e92d55b91dc15d7b3641 Mon Sep 17 00:00:00 2001 From: ebolam Date: Sun, 16 Apr 2023 21:02:42 -0400 Subject: [PATCH 8/8] Added comregex_ui and comregex_ai to the UI under other settings. Needs proper titles and descriptions still. --- gensettings.py | 32 ++++++++++++++++++++++++++++++++ koboldai_settings.py | 16 ++++++++++++---- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/gensettings.py b/gensettings.py index 8d68b4b5..a0a20908 100644 --- a/gensettings.py +++ b/gensettings.py @@ -881,6 +881,38 @@ gensettingstf = [ "classname": "system", "name": "seed", "extra_classes": "var_sync_alt_system_seed_specified", + "ui_level": 2 + }, + { + "uitype": "text", + "unit": "text", + "label": "comregex_ai_string", + "id": "comregex_ai_string", + "min": 0, + "max": 1, + "step": 1, + "default": 1, + "tooltip": "Pattern for matching comments to remove them before sending them to the AI.", + "menu_path": "Settings", + "sub_path": "Other", + "classname": "system", + "name": "comregex_ai_string", + "ui_level": 2 + }, + { + "uitype": "text", + "unit": "text", + "label": "comregex_ui_string", + "id": "comregex_ui_string", + "min": 0, + "max": 1, + "step": 1, + "default": 1, + "tooltip": "Pattern for matching comments in the editor.", + "menu_path": "Settings", + "sub_path": "Other", + "classname": "system", + "name": "comregex_ui_string", "ui_level": 2 }, { diff --git a/koboldai_settings.py b/koboldai_settings.py index 06a15e4e..407ae1e1 100644 --- a/koboldai_settings.py +++ b/koboldai_settings.py @@ -1203,9 +1203,9 @@ class undefined_settings(settings): class system_settings(settings): local_only_variables = ['lua_state', 'lua_logname', 'lua_koboldbridge', 'lua_kobold', - 'lua_koboldcore', 'regex_sl', 'acregex_ai', 'acregex_ui', 'comregex_ai', + 'lua_koboldcore', 'regex_sl', 'acregex_ai', 'acregex_ui', 'comregex_ai', 'comregex_ui', 'sp', '_horde_pid', 'inference_config', 'image_pipeline', - 'summarizer', 'summary_tokenizer', 'tts_model', 'rng_states', 'comregex_ai', 'comregex_ui'] + 'summarizer', 'summary_tokenizer', 'tts_model', 'rng_states'] no_save_variables = ['lua_state', 'lua_logname', 'lua_koboldbridge', 'lua_kobold', 'lua_koboldcore', 'sp', 'sp_length', '_horde_pid', 'horde_share', 'aibusy', 'serverstarted', 'inference_config', 'image_pipeline', 'summarizer', @@ -1252,8 +1252,10 @@ class system_settings(settings): self.regex_sl = re.compile(r'\n*(?<=.) *\n(.|\n)*') # Pattern for limiting the output to a single line self.acregex_ai = re.compile(r'\n* *>(.|\n)*') # Pattern for matching adventure actions from the AI so we can remove them self.acregex_ui = re.compile(r'^ *(>.*)$', re.MULTILINE) # Pattern for matching actions in the HTML-escaped story so we can apply colouring, etc (make sure to encase part to format in parentheses) - self.comregex_ai = re.compile(r'(?:\n\[<\|(?:.|\n)*?\|>\](?=\n|$))|(?:\[<\|(?:.|\n)*?\|>\]\n?)') # Pattern for matching comments to remove them before sending them to the AI - self.comregex_ui = re.compile(r'(\[<\|(?:.|\n)*?\|>\])') # Pattern for matching comments in the editor + self.comregex_ai_string = '(?:\n\[<\|(?:.|\n)*?\|>\](?=\n|$))|(?:\[<\|(?:.|\n)*?\|>\]\n?)' # Pattern for matching comments to remove them before sending them to the AI + self.comregex_ui_string = '(\[<\|(?:.|\n)*?\|>\])' # Pattern for matching comments in the editor + self.comregex_ai = re.compile(self.comregex_ai_string) # Pattern for matching comments to remove them before sending them to the AI + self.comregex_ui = re.compile(self.comregex_ui_string) # Pattern for matching comments in the editor self.host = False self.flaskwebgui = False self.quiet = False # If set will suppress any story text from being printed to the console (will only be seen on the client web page) @@ -1340,6 +1342,12 @@ class system_settings(settings): self._socketio.emit('from_server', {'cmd': 'spstatitems', 'data': {self.spfilename: self.spmeta} if self.allowsp and len(self.spfilename) else {}}, namespace=None, broadcast=True, room="UI_1") super().__setattr__("sp_changed", False) + if name == 'comregex_ai_string': + self.comregex_ai = re.compile(self.comregex_ai_string) + + if name == 'comregex_ui_string': + self.comregex_ui = re.compile(self.comregex_ui_string) + if name == 'keep_img_gen_in_memory' and value == False: self.image_pipeline = None