From 0a91ea27b35e385f679b9e61239e7d9e3ca80cca Mon Sep 17 00:00:00 2001 From: Gnome Ann <> Date: Wed, 3 Nov 2021 12:18:48 -0400 Subject: [PATCH] Make the dynamic world info scan toggleable --- aiserver.py | 15 ++++++++++++++- gensettings.py | 11 +++++++++++ static/application.js | 3 +++ templates/index.html | 2 +- 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/aiserver.py b/aiserver.py index 864feae5..aae02857 100644 --- a/aiserver.py +++ b/aiserver.py @@ -124,6 +124,7 @@ class vars: 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) actionmode = 1 adventure = False + dynamicscan = False remote = False #==================================================================# @@ -564,8 +565,10 @@ if(not vars.model in ["InferKit", "Colab", "OAI", "ReadOnly"]): ) -> bool: assert input_ids.ndim == 2 #assert input_ids.shape[:-1] == self.head_length.shape - tail = input_ids[..., self.head_length:] self.any_new_entries = False + if(not vars.dynamicscan): + return False + tail = input_ids[..., self.head_length:] for t in tail: decoded = tokenizer.decode(t) _, found = checkworldinfo(decoded, force_use_txt=True) @@ -943,6 +946,10 @@ def get_message(msg): vars.adventure = msg['data'] settingschanged() refresh_settings() + elif(msg['cmd'] == 'setdynamicscan'): + vars.dynamicscan = msg['data'] + settingschanged() + refresh_settings() elif(not vars.remote and msg['cmd'] == 'importwi'): wiimportrequest() @@ -1000,6 +1007,7 @@ def savesettings(): js["widepth"] = vars.widepth js["useprompt"] = vars.useprompt js["adventure"] = vars.adventure + js["dynamicscan"] = vars.dynamicscan # Write it if not os.path.exists('settings'): @@ -1050,6 +1058,8 @@ def loadsettings(): vars.useprompt = js["useprompt"] if("adventure" in js): vars.adventure = js["adventure"] + if("dynamicscan" in js): + vars.dynamicscan = js["dynamicscan"] file.close() @@ -1074,6 +1084,8 @@ def loadmodelsettings(): vars.rep_pen = js["rep_pen"] if("adventure" in js): vars.adventure = js["adventure"] + if("dynamicscan" in js): + vars.dynamicscan = js["dynamicscan"] if("formatoptns" in js): vars.formatoptns = js["formatoptns"] model_config.close() @@ -1735,6 +1747,7 @@ def refresh_settings(): emit('from_server', {'cmd': 'updatewidepth', 'data': vars.widepth}, broadcast=True) emit('from_server', {'cmd': 'updateuseprompt', 'data': vars.useprompt}, broadcast=True) emit('from_server', {'cmd': 'updateadventure', 'data': vars.adventure}, broadcast=True) + emit('from_server', {'cmd': 'updatedynamicscan', 'data': vars.dynamicscan}, broadcast=True) emit('from_server', {'cmd': 'updatefrmttriminc', 'data': vars.formatoptns["frmttriminc"]}, broadcast=True) emit('from_server', {'cmd': 'updatefrmtrmblln', 'data': vars.formatoptns["frmtrmblln"]}, broadcast=True) diff --git a/gensettings.py b/gensettings.py index b35b6a21..c567c94c 100644 --- a/gensettings.py +++ b/gensettings.py @@ -118,6 +118,17 @@ gensettingstf = [{ "step": 1, "default": 0, "tooltip": "Turn this on if you are playing a Choose your Adventure model." + }, + { + "uitype": "toggle", + "unit": "bool", + "label": "Dynamic WI Scan", + "id": "setdynamicscan", + "min": 0, + "max": 1, + "step": 1, + "default": 0, + "tooltip": "Scan the AI's output for world info keys as it's generating the output. Turning this on will set Gens Per Action to 1, as these two features are not currently compatible with each other." }] gensettingsik =[{ diff --git a/static/application.js b/static/application.js index 7d9dc191..cf7e3a48 100644 --- a/static/application.js +++ b/static/application.js @@ -1592,6 +1592,9 @@ $(document).ready(function(){ $("#setadventure").prop('checked', msg.data).change(); // Update adventure state setadventure(msg.data); + } else if(msg.cmd == "updatedynamicscan") { + // Update toggle state + $("#setdynamicscan").prop('checked', msg.data).change(); } else if(msg.cmd == "runs_remotely") { hide([button_loadfrfile, button_savetofile, button_import, button_importwi]); } diff --git a/templates/index.html b/templates/index.html index 17d39019..cfbb4524 100644 --- a/templates/index.html +++ b/templates/index.html @@ -6,7 +6,7 @@ - +