From f1699ec496a248f379dd9bd5032dcb1f8e843945 Mon Sep 17 00:00:00 2001 From: somebody Date: Wed, 31 Aug 2022 16:54:23 -0500 Subject: [PATCH 01/22] Add tooltip to completion threshold --- templates/settings flyout.html | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/templates/settings flyout.html b/templates/settings flyout.html index 581a985a..a43c37fb 100644 --- a/templates/settings flyout.html +++ b/templates/settings flyout.html @@ -221,7 +221,10 @@
Phrase
Score
-
Completion Threshold
+
+ Completion Threshold + help_icon +
From 55441394a050eebb468246fee062f34aa27fc29e Mon Sep 17 00:00:00 2001 From: somebody Date: Wed, 31 Aug 2022 18:45:57 -0500 Subject: [PATCH 02/22] Fix alignments --- static/koboldai.css | 12 ++++++++++++ templates/popups.html | 2 +- templates/settings flyout.html | 8 ++++---- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/static/koboldai.css b/static/koboldai.css index e06ccdb7..1e063e05 100644 --- a/static/koboldai.css +++ b/static/koboldai.css @@ -485,6 +485,18 @@ input[type="range"]::-ms-fill-upper { height: 35px; } +.settings_button > .button_label { + position: relative; + bottom: 3px; + right: 4px; +} + +.settings_button > .material-icons-outlined { + position: relative; + top: 3px; + right: 2px; +} + .settings_button[story_gamesaved="true"] { filter: brightness(40%); } diff --git a/templates/popups.html b/templates/popups.html index b4efd736..166158bf 100644 --- a/templates/popups.html +++ b/templates/popups.html @@ -13,7 +13,7 @@ Drag file(s) above or click here to Upload File diff --git a/templates/settings flyout.html b/templates/settings flyout.html index 581a985a..92396296 100644 --- a/templates/settings flyout.html +++ b/templates/settings flyout.html @@ -50,7 +50,7 @@
@@ -72,15 +72,15 @@
From 6e0b26145e43b28b657f89cd194262ced24bc7db Mon Sep 17 00:00:00 2001 From: somebody Date: Wed, 31 Aug 2022 18:46:14 -0500 Subject: [PATCH 03/22] Make labels noselect --- templates/settings flyout.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/settings flyout.html b/templates/settings flyout.html index 92396296..de212075 100644 --- a/templates/settings flyout.html +++ b/templates/settings flyout.html @@ -45,7 +45,7 @@
- 1) Model: + 1) Model:
- 2) Story: + 2) Story:
From 1f6eefa6dfad5674c8dc2a934d98c28fe180078b Mon Sep 17 00:00:00 2001 From: ebolam Date: Thu, 1 Sep 2022 08:59:42 -0400 Subject: [PATCH 06/22] Fix for model loading error due to breakmodel file being partially empty --- aiserver.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/aiserver.py b/aiserver.py index 4dc0d170..e3627166 100644 --- a/aiserver.py +++ b/aiserver.py @@ -1352,6 +1352,8 @@ def get_model_info(model, directory=""): break_values = break_values.split(",") else: break_values = [layer_count] + if break_values == ['']: + break_values = [] break_values = [int(x) for x in break_values] break_values += [0] * (gpu_count - len(break_values)) emit('from_server', {'cmd': 'selected_model_info', 'key_value': key_value, 'key':key, From 60b49c7053139c6af4edc939a0c96d82bb2d7dee Mon Sep 17 00:00:00 2001 From: ebolam Date: Thu, 1 Sep 2022 09:05:06 -0400 Subject: [PATCH 07/22] Fix for visual bug on retry leaving options on the screen. --- static/koboldai.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/static/koboldai.js b/static/koboldai.js index f2c1f7df..eaa6f918 100644 --- a/static/koboldai.js +++ b/static/koboldai.js @@ -120,14 +120,11 @@ function create_options(data) { //Set all options before the next chunk to hidden var option_container = document.getElementById("Select Options"); var current_chunk = parseInt(document.getElementById("action_count").textContent)+1; - var children = option_container.children; - for (var i = 0; i < children.length; i++) { - var chunk = children[i]; - if (chunk.id == "Select Options Chunk " + current_chunk) { - chunk.classList.remove("hidden"); - } else { - chunk.classList.add("hidden"); - } + if (document.getElementById("Select Options Chunk " + current_chunk)) { + document.getElementById("Select Options Chunk " + current_chunk).classList.remove("hidden") + } + if (document.getElementById("Select Options Chunk " + (current_chunk-1))) { + document.getElementById("Select Options Chunk " + (current_chunk-1)).classList.add("hidden") } if (document.getElementById("Select Options Chunk "+data.value.id)) { @@ -410,6 +407,10 @@ function do_ai_busy(data) { if (data.value) { ai_busy_start = Date.now(); favicon.start_swap() + current_chunk = parseInt(document.getElementById("action_count").textContent)+1; + if (document.getElementById("Select Options Chunk " + current_chunk)) { + document.getElementById("Select Options Chunk " + current_chunk).classList.add("hidden") + } } else { runtime = Date.now() - ai_busy_start; if (document.getElementById("Execution Time")) { From 08fac1157a7965971059271d9bd432d85c4c4539 Mon Sep 17 00:00:00 2001 From: ebolam Date: Thu, 1 Sep 2022 09:27:55 -0400 Subject: [PATCH 08/22] Fix for token streaming not visually showing sentence trimming correctly --- aiserver.py | 2 +- koboldai_settings.py | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/aiserver.py b/aiserver.py index e3627166..783ea572 100644 --- a/aiserver.py +++ b/aiserver.py @@ -1828,7 +1828,7 @@ def patch_transformers(): #koboldai_vars.actions.stream_token(tokenizer_text, batch=batch) if koboldai_vars.output_streaming: - koboldai_vars.actions.stream_tokens([utils.decodenewlines(tokenizer.decode(x[-1])) for x in input_ids]) + koboldai_vars.actions.stream_tokens([utils.decodenewlines(tokenizer.decode(x[-1])) for x in input_ids], koboldai_vars.genamt) #if len(input_ids) > 1: # koboldai_vars.actions.clear_unused_options() # koboldai_vars.actions.append_options([utils.decodenewlines(tokenizer.decode(x[-1])) for x in input_ids]) diff --git a/koboldai_settings.py b/koboldai_settings.py index afa749b5..535e54a8 100644 --- a/koboldai_settings.py +++ b/koboldai_settings.py @@ -1053,7 +1053,7 @@ class KoboldStoryRegister(object): process_variable_changes(self.socketio, "story", 'actions', {"id": key, 'action': self.actions[key]}, None) ignore = self.koboldai_vars.calc_ai_text() - def stream_tokens(self, text_list): + def stream_tokens(self, text_list, max_tokens): if len(text_list) > 1: if self.action_count+1 in self.actions: for i in range(len(text_list)): @@ -1070,8 +1070,11 @@ class KoboldStoryRegister(object): for i in range(len(text_list)): self.actions[self.action_count+1]['Options'].append({"text": text_list[i], "Pinned": False, "Previous Selection": False, "Edited": False, "Probabilities": [], "stream_id": i}) - process_variable_changes(self.socketio, "actions", "Options", {"id": self.action_count+1, "options": self.actions[self.action_count+1]["Options"]}, {"id": self.action_count+1, "options": None}) - process_variable_changes(self.socketio, "story", 'actions', {"id": self.action_count+1, 'action': self.actions[self.action_count+1]}, None) + #We need to see if this is the last token being streamed. If so due to the rely it will come in AFTER the actual trimmed final text overwriting it in the UI + if self.tokenizer is not None: + if len(self.tokenizer.encode(self.actions[self.action_count+1]["Options"][0]['text'])) != max_tokens: + #process_variable_changes(self.socketio, "actions", "Options", {"id": self.action_count+1, "options": self.actions[self.action_count+1]["Options"]}, {"id": self.action_count+1, "options": None}) + process_variable_changes(self.socketio, "story", 'actions', {"id": self.action_count+1, 'action': self.actions[self.action_count+1]}, None) else: #We're streaming single options so our output is our selected if self.tokenizer is not None: From 716494e2d301e12db82823089b582d476a2dc099 Mon Sep 17 00:00:00 2001 From: LightSaveUs <108632621+LightSaveUs@users.noreply.github.com> Date: Thu, 1 Sep 2022 16:47:22 +0300 Subject: [PATCH 09/22] Buttons position adjustment --- static/koboldai.css | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/static/koboldai.css b/static/koboldai.css index cae46227..17373dd8 100644 --- a/static/koboldai.css +++ b/static/koboldai.css @@ -494,16 +494,17 @@ input[type="range"]::-ms-fill-upper { .settings_button > .material-icons-outlined { position: relative; - top: 3px; + top: 1px; right: 2px; } .Model_Info .settings_button { - + transform: translateY(7%); + margin: -5px; } #import_story_button { - + transform: translateY(22%); } .settings_button[story_gamesaved="true"] { From 22b9b5781effda8d256abaca91a6610423daaa07 Mon Sep 17 00:00:00 2001 From: ebolam Date: Thu, 1 Sep 2022 10:00:43 -0400 Subject: [PATCH 10/22] Fix for multiple prompts when using token streaming and random prompt. Disabled token streaming when that happens --- aiserver.py | 4 ++-- koboldai_settings.py | 36 ++++++++++++++++++++---------------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/aiserver.py b/aiserver.py index 783ea572..39b21440 100644 --- a/aiserver.py +++ b/aiserver.py @@ -1828,7 +1828,7 @@ def patch_transformers(): #koboldai_vars.actions.stream_token(tokenizer_text, batch=batch) if koboldai_vars.output_streaming: - koboldai_vars.actions.stream_tokens([utils.decodenewlines(tokenizer.decode(x[-1])) for x in input_ids], koboldai_vars.genamt) + koboldai_vars.actions.stream_tokens([utils.decodenewlines(tokenizer.decode(x[-1])) for x in input_ids]) #if len(input_ids) > 1: # koboldai_vars.actions.clear_unused_options() # koboldai_vars.actions.append_options([utils.decodenewlines(tokenizer.decode(x[-1])) for x in input_ids]) @@ -3743,7 +3743,7 @@ def get_message(msg): f.write(str(msg['gpu_layers']) + '\n' + str(msg['disk_layers'])) f.close() koboldai_vars.colaburl = msg['url'] + "/request" - vars.model = vars.model_selected + koboldai_vars.model = koboldai_vars.model_selected load_model(use_gpu=msg['use_gpu'], gpu_layers=msg['gpu_layers'], disk_layers=msg['disk_layers'], online_model=msg['online_model']) elif(msg['cmd'] == 'show_model'): print("Model Name: {}".format(getmodelname())) diff --git a/koboldai_settings.py b/koboldai_settings.py index 535e54a8..d79d04b2 100644 --- a/koboldai_settings.py +++ b/koboldai_settings.py @@ -763,7 +763,7 @@ class KoboldStoryRegister(object): self.append(item) def reset(self, sequence=[]): - self.__init__(self.socketio, self.story_settings, sequence=sequence, tokenizer=self.tokenizer) + self.__init__(self.socketio, self.story_settings, self.koboldai_vars, sequence=sequence, tokenizer=self.tokenizer) def __str__(self): return "".join([x['Selected Text'] for ignore, x in sorted(self.actions.items())]) @@ -1053,7 +1053,7 @@ class KoboldStoryRegister(object): process_variable_changes(self.socketio, "story", 'actions', {"id": key, 'action': self.actions[key]}, None) ignore = self.koboldai_vars.calc_ai_text() - def stream_tokens(self, text_list, max_tokens): + def stream_tokens(self, text_list): if len(text_list) > 1: if self.action_count+1 in self.actions: for i in range(len(text_list)): @@ -1069,26 +1069,30 @@ class KoboldStoryRegister(object): self.actions[self.action_count+1] = {"Selected Text": "", "Selected Text Length": 0, "Options": []} for i in range(len(text_list)): self.actions[self.action_count+1]['Options'].append({"text": text_list[i], "Pinned": False, "Previous Selection": False, "Edited": False, "Probabilities": [], "stream_id": i}) - + #We need to see if this is the last token being streamed. If so due to the rely it will come in AFTER the actual trimmed final text overwriting it in the UI if self.tokenizer is not None: - if len(self.tokenizer.encode(self.actions[self.action_count+1]["Options"][0]['text'])) != max_tokens: + if len(self.tokenizer.encode(self.actions[self.action_count+1]["Options"][0]['text'])) != self.koboldai_vars.genamt: #process_variable_changes(self.socketio, "actions", "Options", {"id": self.action_count+1, "options": self.actions[self.action_count+1]["Options"]}, {"id": self.action_count+1, "options": None}) process_variable_changes(self.socketio, "story", 'actions', {"id": self.action_count+1, 'action': self.actions[self.action_count+1]}, None) else: #We're streaming single options so our output is our selected - if self.tokenizer is not None: - selected_text_length = len(self.tokenizer.encode(text_list[0])) - else: - selected_text_length = 0 - if self.action_count+1 in self.actions: - self.actions[self.action_count+1]['Selected Text'] = "{}{}".format(self.actions[self.action_count+1]['Selected Text'], text_list[0]) - else: - self.actions[self.action_count+1] = {"Selected Text": text_list[0], "Selected Text Length": selected_text_length, "Options": []} - - process_variable_changes(self.socketio, "actions", "Selected Text", {"id": self.action_count+1, "text": self.actions[self.action_count+1]['Selected Text']}, None) - process_variable_changes(self.socketio, "actions", 'Selected Text Length', {"id": self.action_count+1, 'length': self.actions[self.action_count+1]['Selected Text Length']}, {"id": self.action_count, 'length': 0}) - process_variable_changes(self.socketio, "story", 'actions', {"id": self.action_count+1, 'action': self.actions[self.action_count+1]}, None) + #First we need to see if this is actually the prompt. If so we'll just not do streaming: + if self.story_settings.prompt != "": + if self.action_count+1 in self.actions: + self.actions[self.action_count+1]['Selected Text'] = "{}{}".format(self.actions[self.action_count+1]['Selected Text'], text_list[0]) + else: + self.actions[self.action_count+1] = {"Selected Text": text_list[0], "Selected Text Length": selected_text_length, "Options": []} + + if self.tokenizer is not None: + selected_text_length = len(self.tokenizer.encode(self.actions[self.action_count+1]['Selected Text'])) + else: + selected_text_length = 0 + + if self.tokenizer is not None: + if len(self.tokenizer.encode(self.actions[self.action_count+1]['Selected Text'])) != self.koboldai_vars.genamt: + #process_variable_changes(self.socketio, "actions", "Options", {"id": self.action_count+1, "options": self.actions[self.action_count+1]["Options"]}, {"id": self.action_count+1, "options": None}) + process_variable_changes(self.socketio, "story", 'actions', {"id": self.action_count+1, 'action': self.actions[self.action_count+1]}, None) def set_probabilites(self, probabilities, action_id=None): if action_id is None: From 8c594e69b3321b309d0f80f5ff270bfe368c69d2 Mon Sep 17 00:00:00 2001 From: ebolam Date: Thu, 1 Sep 2022 10:08:10 -0400 Subject: [PATCH 11/22] Pin coloring --- static/koboldai.css | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/static/koboldai.css b/static/koboldai.css index 17373dd8..2994be3b 100644 --- a/static/koboldai.css +++ b/static/koboldai.css @@ -350,6 +350,10 @@ input[type="range"]::-ms-fill-upper { display: inline-block; transition: left 0.5s; cursor: pointer; + filter: brightness(85%); +} +.pinned .menu_pin { + filter: brightness(200%); } } @@ -815,6 +819,10 @@ input[type="range"]::-ms-fill-upper { display: inline-block; transition: left 0.5s; cursor: pointer; + filter: brightness(85%); +} +.pinned .story_menu_pin { + filter: brightness(200%); } } From f0682ea9969d81a74165f6942ec9fb73e319aed4 Mon Sep 17 00:00:00 2001 From: ebolam Date: Thu, 1 Sep 2022 18:54:17 -0400 Subject: [PATCH 12/22] removed _actions references --- aiserver.py | 60 ++++++++++++++++---------------------------- bridge.lua | 8 +++--- koboldai_settings.py | 6 ++++- 3 files changed, 31 insertions(+), 43 deletions(-) diff --git a/aiserver.py b/aiserver.py index 39b21440..012ef46e 100644 --- a/aiserver.py +++ b/aiserver.py @@ -1878,7 +1878,7 @@ def patch_transformers(): tail = input_ids[..., -koboldai_vars.generated_tkns:] for i, t in enumerate(tail): decoded = utils.decodenewlines(tokenizer.decode(t)) - _, found = checkworldinfo(decoded, force_use_txt=True, actions=koboldai_vars._actions) + _, found = checkworldinfo(decoded, force_use_txt=True, actions=koboldai_vars.actions) found -= self.excluded_world_info[i] if(len(found) != 0): self.regeneration_required = True @@ -2527,7 +2527,7 @@ def load_model(use_gpu=True, gpu_layers=None, disk_layers=None, initial_load=Fal for i, t in enumerate(generated): decoded = utils.decodenewlines(tokenizer.decode(past[i])) + utils.decodenewlines(tokenizer.decode(t[tpu_mtj_backend.params["seq"] : tpu_mtj_backend.params["seq"] + n_generated])) - _, found = checkworldinfo(decoded, force_use_txt=True, actions=koboldai_vars._actions) + _, found = checkworldinfo(decoded, force_use_txt=True, actions=koboldai_vars.actions) found -= excluded_world_info[i] if(len(found) != 0): regeneration_required = True @@ -2543,7 +2543,7 @@ def load_model(use_gpu=True, gpu_layers=None, disk_layers=None, initial_load=Fal koboldai_vars.compiling = False def tpumtjgenerate_settings_callback() -> dict: - sampler_order = vars.sampler_order[:] + sampler_order = koboldai_vars.sampler_order[:] if len(sampler_order) < 7: # Add repetition penalty at beginning if it's not present sampler_order = [6] + sampler_order return { @@ -2896,7 +2896,7 @@ def lua_compute_context(submission, entries, folders, kwargs): assert type(submission) is str if(kwargs is None): kwargs = koboldai_vars.lua_state.table() - actions = koboldai_vars._actions if koboldai_vars.lua_koboldbridge.userstate == "genmod" else koboldai_vars.actions + actions = koboldai_vars.actions allowed_entries = None allowed_folders = None if(entries is not None): @@ -3222,13 +3222,9 @@ def lua_set_chunk(k, v): if(len(v) == 0): print(colors.GREEN + f"{lua_log_format_name(koboldai_vars.lua_koboldbridge.logging_name)} deleted story chunk {k}" + colors.END) chunk = int(k) - if(koboldai_vars.lua_koboldbridge.userstate == "genmod"): - del koboldai_vars._actions[chunk-1] + koboldai_vars.actions.delete_action(chunk-1) koboldai_vars.lua_deleted.add(chunk) - if(not hasattr(koboldai_vars, "_actions") or koboldai_vars._actions is not koboldai_vars.actions): - #Instead of deleting we'll blank out the text. This way our actions and actions_metadata stay in sync and we can restore the chunk on an undo - koboldai_vars.actions[chunk-1] = "" - send_debug() + send_debug() else: if(k == 0): print(colors.GREEN + f"{lua_log_format_name(koboldai_vars.lua_koboldbridge.logging_name)} edited prompt chunk" + colors.END) @@ -3241,8 +3237,6 @@ def lua_set_chunk(k, v): koboldai_vars.lua_edited.add(chunk) koboldai_vars.prompt = v else: - if(koboldai_vars.lua_koboldbridge.userstate == "genmod"): - koboldai_vars._actions[chunk-1] = v koboldai_vars.lua_edited.add(chunk) koboldai_vars.actions[chunk-1] = v send_debug() @@ -4215,10 +4209,7 @@ def apiactionsubmit_tpumtjgenerate(txt, minimum, maximum): if not koboldai_vars.quiet: print("{0}Min:{1}, Max:{2}, Txt:{3}{4}".format(colors.YELLOW, minimum, maximum, utils.decodenewlines(tokenizer.decode(txt)), colors.END)) - koboldai_vars._actions = koboldai_vars.actions koboldai_vars._prompt = koboldai_vars.prompt - if(koboldai_vars.dynamicscan): - koboldai_vars._actions = koboldai_vars._actions.copy() # Submit input text to generator soft_tokens = tpumtjgetsofttokens() @@ -4624,10 +4615,7 @@ def _generate(txt, minimum, maximum, found_entries): model.kai_scanner_excluded_world_info = found_entries - koboldai_vars._actions = koboldai_vars.actions koboldai_vars._prompt = koboldai_vars.prompt - if(koboldai_vars.dynamicscan): - koboldai_vars._actions = [x for x in koboldai_vars.actions] with torch.no_grad(): already_generated = 0 @@ -4659,13 +4647,13 @@ def _generate(txt, minimum, maximum, found_entries): encoded = [] for i in range(koboldai_vars.numseqs): txt = utils.decodenewlines(tokenizer.decode(genout[i, -already_generated:])) - winfo, mem, anotetxt, _found_entries = calcsubmitbudgetheader(txt, force_use_txt=True, actions=koboldai_vars._actions) + winfo, mem, anotetxt, _found_entries = calcsubmitbudgetheader(txt, force_use_txt=True, actions=koboldai_vars.actions) found_entries[i].update(_found_entries) if koboldai_vars.alt_gen: txt, _, _ = koboldai_vars.calc_ai_text(submitted_text=txt) print("Using Alt Gen: {}".format(tokenizer.decode(txt))) else: - txt, _, _ = calcsubmitbudget(len(koboldai_vars._actions), winfo, mem, anotetxt, koboldai_vars._actions, submission=txt) + txt, _, _ = calcsubmitbudget(len(koboldai_vars.actions), winfo, mem, anotetxt, koboldai_vars.actions, submission=txt) encoded.append(torch.tensor(txt, dtype=torch.long, device=genout.device)) max_length = len(max(encoded, key=len)) encoded = torch.stack(tuple(torch.nn.functional.pad(e, (max_length - len(e), 0), value=model.config.pad_token_id or model.config.eos_token_id) for e in encoded)) @@ -5020,10 +5008,7 @@ def tpumtjgenerate(txt, minimum, maximum, found_entries=None): if not koboldai_vars.quiet: print("{0}Min:{1}, Max:{2}, Txt:{3}{4}".format(colors.YELLOW, minimum, maximum, utils.decodenewlines(tokenizer.decode(txt)), colors.END)) - koboldai_vars._actions = koboldai_vars.actions koboldai_vars._prompt = koboldai_vars.prompt - if(koboldai_vars.dynamicscan): - koboldai_vars._actions = koboldai_vars._actions.copy() # Submit input text to generator try: @@ -5062,13 +5047,13 @@ def tpumtjgenerate(txt, minimum, maximum, found_entries=None): encoded = [] for i in range(koboldai_vars.numseqs): txt = utils.decodenewlines(tokenizer.decode(past[i])) - winfo, mem, anotetxt, _found_entries = calcsubmitbudgetheader(txt, force_use_txt=True, actions=koboldai_vars._actions) + winfo, mem, anotetxt, _found_entries = calcsubmitbudgetheader(txt, force_use_txt=True, actions=koboldai_vars.actions) found_entries[i].update(_found_entries) if koboldai_vars.alt_gen: txt, _, _ = koboldai_vars.calc_ai_text(submitted_text=txt) print("Using Alt Gen: {}".format(tokenizer.decode(txt))) else: - txt, _, _ = calcsubmitbudget(len(koboldai_vars._actions), winfo, mem, anotetxt, koboldai_vars._actions, submission=txt) + txt, _, _ = calcsubmitbudget(len(koboldai_vars.actions), winfo, mem, anotetxt, koboldai_vars.actions, submission=txt) encoded.append(np.array(txt, dtype=np.uint32)) max_length = len(max(encoded, key=len)) encoded = np.stack(tuple(np.pad(e, (max_length - len(e), 0), constant_values=tpu_mtj_backend.pad_token_id) for e in encoded)) @@ -5662,15 +5647,14 @@ def checkworldinfo(txt, allowed_entries=None, allowed_folders=None, force_use_tx depth += 1 if(ln > 0): - chunks = collections.deque() - i = 0 - for key in reversed(actions): - chunk = actions[key] - chunks.appendleft(chunk) - i += 1 - if(i == depth): - break - + chunks = actions[-depth:] + #i = 0 + #for key in reversed(actions): + # chunk = actions[key] + # chunks.appendleft(chunk) + # i += 1 + # if(i == depth): + # break if(ln >= depth): txt = "".join(chunks) elif(ln > 0): @@ -8099,18 +8083,18 @@ def put_model(body: ModelSelectionSchema): {api_validation_error_response} {api_server_busy_response} """ - if vars.aibusy or vars.genseqs: + if koboldai_vars.aibusy or koboldai_vars.genseqs: abort(Response(json.dumps({"detail": { "msg": "Server is busy; please try again later.", "type": "service_unavailable", }}), mimetype="application/json", status=503)) set_aibusy(1) - old_model = vars.model - vars.model = body.model.strip() + old_model = koboldai_vars.model + koboldai_vars.model = body.model.strip() try: load_model(use_breakmodel_args=True, breakmodel_args_default_to_cpu=True) except Exception as e: - vars.model = old_model + koboldai_vars.model = old_model raise e set_aibusy(0) return {} diff --git a/bridge.lua b/bridge.lua index 014426a8..9173302a 100644 --- a/bridge.lua +++ b/bridge.lua @@ -730,7 +730,7 @@ return function(_python, _bridged) return prompt end end - local actions = koboldbridge.userstate == "genmod" and bridged.koboldai_vars._actions or bridged.koboldai_vars.actions + local actions = koboldbridge.userstate == "genmod" and bridged.koboldai_vars.actions return _python.as_attrgetter(actions).get(math.tointeger(rawget(t, "_num")) - 1) end end @@ -752,7 +752,7 @@ return function(_python, _bridged) error("Attempted to set the prompt chunk's content to the empty string; this is not allowed") return end - local actions = koboldbridge.userstate == "genmod" and bridged.koboldai_vars._actions or bridged.koboldai_vars.actions + local actions = koboldbridge.userstate == "genmod" and bridged.koboldai_vars.actions if _k ~= 0 and _python.as_attrgetter(actions).get(_k-1) == nil then return end @@ -777,7 +777,7 @@ return function(_python, _bridged) ---@return fun(): KoboldStoryChunk, table, nil function KoboldStory:forward_iter() - local actions = koboldbridge.userstate == "genmod" and bridged.koboldai_vars._actions or bridged.koboldai_vars.actions + local actions = koboldbridge.userstate == "genmod" and bridged.koboldai_vars.actions local nxt, iterator = _python.iter(actions) local run_once = false local function f() @@ -805,7 +805,7 @@ return function(_python, _bridged) ---@return fun(): KoboldStoryChunk, table, nil function KoboldStory:reverse_iter() - local actions = koboldbridge.userstate == "genmod" and bridged.koboldai_vars._actions or bridged.koboldai_vars.actions + local actions = koboldbridge.userstate == "genmod" and bridged.koboldai_vars.actions local nxt, iterator = _python.iter(_python.builtins.reversed(actions)) local last_run = false local function f() diff --git a/koboldai_settings.py b/koboldai_settings.py index d79d04b2..38310b7c 100644 --- a/koboldai_settings.py +++ b/koboldai_settings.py @@ -783,7 +783,11 @@ class KoboldStoryRegister(object): raise StopIteration def __getitem__(self, i): - return self.actions[i]["Selected Text"] + if isinstance(i, slice): + temp = [self.actions[x]["Selected Text"] for x in list(self.actions)[i]] + return temp + else: + return self.actions[i]["Selected Text"] def __setitem__(self, i, text): if i in self.actions: From 6fc7112c5d7ca225276f6c9ab166d230b1a6144c Mon Sep 17 00:00:00 2001 From: ebolam Date: Fri, 2 Sep 2022 07:47:20 -0400 Subject: [PATCH 13/22] Streaming Token Bug Fix --- koboldai_settings.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/koboldai_settings.py b/koboldai_settings.py index 38310b7c..520e9294 100644 --- a/koboldai_settings.py +++ b/koboldai_settings.py @@ -1084,14 +1084,20 @@ class KoboldStoryRegister(object): #First we need to see if this is actually the prompt. If so we'll just not do streaming: if self.story_settings.prompt != "": if self.action_count+1 in self.actions: + if self.tokenizer is not None: + selected_text_length = len(self.tokenizer.encode(self.actions[self.action_count+1]['Selected Text'])) + else: + selected_text_length = 0 self.actions[self.action_count+1]['Selected Text'] = "{}{}".format(self.actions[self.action_count+1]['Selected Text'], text_list[0]) + self.actions[self.action_count+1]['Selected Text Length'] = selected_text_length else: + if self.tokenizer is not None: + selected_text_length = len(self.tokenizer.encode(text_list[0])) + else: + selected_text_length = 0 self.actions[self.action_count+1] = {"Selected Text": text_list[0], "Selected Text Length": selected_text_length, "Options": []} - if self.tokenizer is not None: - selected_text_length = len(self.tokenizer.encode(self.actions[self.action_count+1]['Selected Text'])) - else: - selected_text_length = 0 + if self.tokenizer is not None: if len(self.tokenizer.encode(self.actions[self.action_count+1]['Selected Text'])) != self.koboldai_vars.genamt: From eb740e382bc0447050348ac7c55f43b0346eca6f Mon Sep 17 00:00:00 2001 From: ebolam Date: Fri, 2 Sep 2022 07:50:32 -0400 Subject: [PATCH 14/22] Fix for file highlighting on load file dialog --- static/koboldai.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/static/koboldai.js b/static/koboldai.js index eaa6f918..249ede42 100644 --- a/static/koboldai.js +++ b/static/koboldai.js @@ -818,7 +818,7 @@ function popup_items(data) { for (item of popup_list) { item.classList.remove("selected"); } - this.classList.add("selected"); + this.parentElement.classList.add("selected"); }; tr.append(td); } From 95c8e5914f57a4e87e212c8d3cc95079399d632f Mon Sep 17 00:00:00 2001 From: somebody Date: Fri, 2 Sep 2022 07:41:22 -0500 Subject: [PATCH 15/22] Add "hide text hightlighting" tweak --- templates/settings flyout.html | 4 ++++ themes/tweaks/hide-max-length.css | 4 ++++ 2 files changed, 8 insertions(+) create mode 100644 themes/tweaks/hide-max-length.css diff --git a/templates/settings flyout.html b/templates/settings flyout.html index 5e122d88..44df9b5a 100644 --- a/templates/settings flyout.html +++ b/templates/settings flyout.html @@ -347,6 +347,10 @@ Hide token bar
+
+ Hide text highlighting + +
@@ -51,7 +51,7 @@
Use GPU
- + @@ -85,22 +85,6 @@ - -