From be0319cf0377d9a4d65b8ec357d33f1a36f0eaf7 Mon Sep 17 00:00:00 2001 From: ebolam Date: Fri, 14 Apr 2023 13:54:11 -0400 Subject: [PATCH] added VERSION link in the left flyout menu footer that will show which git REPO and BRANCH the system is running on. Fix for pasting text into the game area Fix for ctrl+a then delete Fix for changing text then back/forward a bunch loosing text --- aiserver.py | 39 ++++++++++++++++++---------- koboldai_settings.py | 34 +++++++++++++++--------- static/koboldai.js | 47 ++++++++++++++++++++++++++++------ templates/index_new.html | 2 +- templates/popups.html | 17 +++++++++++- templates/settings flyout.html | 5 ++-- 6 files changed, 106 insertions(+), 38 deletions(-) diff --git a/aiserver.py b/aiserver.py index 2ec6d817..82b8c9fd 100644 --- a/aiserver.py +++ b/aiserver.py @@ -1476,6 +1476,18 @@ def general_startup(override_args=None): global args global enable_whitelist global allowed_ips + import configparser + #Figure out what git we're on if that's available + config = configparser.ConfigParser() + if os.path.exists('.git/config'): + config.read('.git/config') + koboldai_vars.git_repository = config['remote "origin"']['url'] + for item in config.sections(): + if "branch" in item: + koboldai_vars.git_branch = item.replace("branch ", "").replace('"', '') + + logger.info("Running on Repo: {} Branch: {}".format(koboldai_vars.git_repository, koboldai_vars.git_branch)) + # Parsing Parameters parser = argparse.ArgumentParser(description="KoboldAI Server") parser.add_argument("--remote", action='store_true', help="Optimizes KoboldAI for Remote Play") @@ -1602,7 +1614,7 @@ def general_startup(override_args=None): koboldai_vars.quiet = True if args.nobreakmodel: - koboldai_vars.nobreakmodel = True; + koboldai_vars.nobreakmodel = True if args.remote: koboldai_vars.host = True; @@ -7455,17 +7467,6 @@ 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 os.path.exists(loadpath.replace(".json", "")): - loadpath = loadpath.replace(".json", "") - - if 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) - loadpath = os.path.join(loadpath, "story.json") - start_time = time.time() # Leave Edit/Memory mode before continuing exitModes() @@ -7473,6 +7474,17 @@ def loadRequest(loadpath, filename=None): # Read file contents into JSON object start_time = time.time() if(isinstance(loadpath, str)): + #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 os.path.exists(loadpath.replace(".json", "")): + loadpath = loadpath.replace(".json", "") + + if 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) + loadpath = os.path.join(loadpath, "story.json") + with open(loadpath, "r", encoding="utf-8") as file: js = json.load(file) from_file=loadpath @@ -8745,8 +8757,7 @@ def UI_2_back(data): def UI_2_redo(data): if koboldai_vars.aibusy: return - if len(koboldai_vars.actions.get_current_options()) == 1: - koboldai_vars.actions.use_option(0) + koboldai_vars.actions.go_forward() #==================================================================# diff --git a/koboldai_settings.py b/koboldai_settings.py index be86e302..bd633d83 100644 --- a/koboldai_settings.py +++ b/koboldai_settings.py @@ -1210,7 +1210,7 @@ class system_settings(settings): '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', 'git_repository', 'git_branch'] settings_name = "system" def __init__(self, socketio, koboldai_var): self._socketio = socketio @@ -1296,16 +1296,18 @@ class system_settings(settings): self.experimental_features = False #check if bitsandbytes is installed self.bit_8_available = False - if importlib.util.find_spec("bitsandbytes") is not None and sys.platform.startswith('linux'): #We can install bitsandbytes, but it doesn't work on windows, so limit it here - if torch.cuda.is_available(): - for device in range(torch.cuda.device_count()): - if torch.cuda.get_device_properties(device).major > 7: - self.bit_8_available = True - break - elif torch.cuda.get_device_properties(device).major == 7 and torch.cuda.get_device_properties(device).minor >= 2: - self.bit_8_available = True - break + if importlib.util.find_spec("bitsandbytes") is not None:# and sys.platform.startswith('linux'): #We can install bitsandbytes, but it doesn't work on windows, so limit it here + try: + import bitsandbytes + bits_and_bytes = True + except: + bits_and_bytes = False + pass + if torch.cuda.is_available() and bits_and_bytes: + self.bit_8_available = True self.seen_messages = [] + self.git_repository = "" + self.git_branch = "" @dataclass @@ -1757,6 +1759,13 @@ class KoboldStoryRegister(object): process_variable_changes(self._socketio, "story", 'actions', {"id": action_step, 'action': self.actions[action_step]}, None) self.set_game_saved() + def go_forward(self): + action_step = self.action_count+1 + if action_step in self.actions: + if len(self.get_current_options()) == 1: + logger.warning("Going forward with this text: {}".format(self.get_current_options()[0]["text"])) + self.use_option([x['text'] for x in self.actions[action_step]["Options"]].index(self.get_current_options()[0]["text"])) + def use_option(self, option_number, action_step=None): if action_step is None: action_step = self.action_count+1 @@ -1800,7 +1809,8 @@ class KoboldStoryRegister(object): old_text = self.actions[action_id]["Selected Text"] old_length = self.actions[action_id]["Selected Text Length"] if keep: - self.actions[action_id]["Options"].append({"text": self.actions[action_id]["Selected Text"], "Pinned": False, "Previous Selection": True, "Edited": False}) + if {"text": self.actions[action_id]["Selected Text"], "Pinned": False, "Previous Selection": True, "Edited": False} not in self.actions[action_id]["Options"]: + self.actions[action_id]["Options"].append({"text": self.actions[action_id]["Selected Text"], "Pinned": False, "Previous Selection": True, "Edited": False}) self.actions[action_id]["Selected Text"] = "" if "wi_highlighted_text" in self.actions[action_id]: del self.actions[action_id]["wi_highlighted_text"] @@ -1825,7 +1835,7 @@ class KoboldStoryRegister(object): def get_current_options(self): if self.action_count+1 in self.actions: - return self.actions[self.action_count+1]["Options"] + return [x for x in self.actions[self.action_count+1]["Options"] if x['Edited'] != True] else: return [] diff --git a/static/koboldai.js b/static/koboldai.js index cce66f80..58b453d5 100644 --- a/static/koboldai.js +++ b/static/koboldai.js @@ -344,7 +344,7 @@ function create_options(action) { seen_prev_selection = false; show_options = false; for (item of action.action.Options) { - if (!(item['Previous Selection'])) { + if (!(item['Previous Selection']) && !(item['Edited'])) { show_options = true; break; } else if (item['Previous Selection']) { @@ -3023,6 +3023,7 @@ function select_game_text(event) { let anchorNode = window.getSelection().anchorNode; let new_selected_game_chunk = null; + //grab the correct action we're trying to modify if (document.selection) { if (document.selection.createRange().parentElement().id == 'story_prompt') { new_selected_game_chunk = document.selection.createRange().parentElement(); @@ -3089,6 +3090,32 @@ function select_game_text(event) { } } +function capturegametextpaste(event) { + //Stop all paste stuff from happening in the browser + event.preventDefault(); + event.stopPropagation(); + + //get the pasted text + let pastedText = (event.clipboardData || window.clipboardData).getData("text"); + + + //Figure out where we pasted (the span element) + let anchorNode = window.getSelection().anchorNode; + if (anchorNode.nodeName == '#text') { + anchorNode = anchorNode.parentNode; + } + //Get the text that was there + var original_text = anchorNode.textContent + //Add the pasted text at the appropriate offset + original_text = [original_text.slice(0, getSelection().anchorOffset), pastedText, original_text.slice(getSelection().anchorOffset)].join(''); + + //put the text back + anchorNode.textContent = original_text; + + return false; + +} + function edit_game_text(id) { update_game_text(id) //OK, now we need to go backwards and forwards until we find something that didn't change @@ -3136,14 +3163,18 @@ function update_game_text(id) { let temp = null; let new_text = "" if (id == -1) { - temp = document.getElementById("story_prompt"); - new_text = temp.innerText; - sync_to_server(temp); - temp.original_text = new_text; - temp.classList.add("pulse"); + if (document.getElementById("story_prompt")) { + temp = document.getElementById("story_prompt"); + new_text = temp.innerText; + sync_to_server(temp); + temp.original_text = new_text; + temp.classList.add("pulse"); + } else { + socket.emit("var_change", {"ID": 'story_prompt', "value": ''}) + } } else { - temp = document.getElementById("Selected Text Chunk " + id); - if (temp) { + if (document.getElementById("Selected Text Chunk " + id)) { + temp = document.getElementById("Selected Text Chunk " + id); new_text = temp.innerText; socket.emit("Set Selected Text", {"id": id, "text": new_text}); temp.original_text = new_text; diff --git a/templates/index_new.html b/templates/index_new.html index 7a1abc37..8aadee5d 100644 --- a/templates/index_new.html +++ b/templates/index_new.html @@ -53,7 +53,7 @@
-
+
diff --git a/templates/popups.html b/templates/popups.html index 44cf7cb6..12c4c27a 100644 --- a/templates/popups.html +++ b/templates/popups.html @@ -71,7 +71,7 @@
Use GPU
- + + + +
\ No newline at end of file diff --git a/templates/settings flyout.html b/templates/settings flyout.html index aae2335e..756fe07d 100644 --- a/templates/settings flyout.html +++ b/templates/settings flyout.html @@ -488,7 +488,8 @@