Bug fix for loading model after loading a model duplicating the settings menu until the website is refreshed

Fixed escaping warnings
Added back/redo unit test
This commit is contained in:
ebolam 2022-06-10 14:47:52 -04:00
parent c432051fe3
commit cfd1147d5a
3 changed files with 65 additions and 9 deletions

View File

@ -281,7 +281,7 @@ class vars:
colaburl = "" # Ngrok url for Google Colab mode
apikey = "" # API key to use for InferKit API calls
oaiapikey = "" # API key to use for OpenAI API calls
savedir = getcwd()+"\stories"
savedir = getcwd()+"\\stories"
hascuda = False # Whether torch has detected CUDA on the system
usegpu = False # Whether to launch pipeline with GPU support
custmodpth = "" # Filesystem location of custom model to run
@ -1072,6 +1072,10 @@ def get_model_info(model, directory=""):
else:
break_values = [layer_count]
break_values += [0] * (gpu_count - len(break_values))
#print("Model_info: {}".format({'cmd': 'selected_model_info', 'key_value': key_value, 'key':key,
# 'gpu':gpu, 'layer_count':layer_count, 'breakmodel':breakmodel,
# 'break_values': break_values, 'gpu_count': gpu_count,
# 'url': url, 'gpu_names': gpu_names}))
emit('from_server', {'cmd': 'selected_model_info', 'key_value': key_value, 'key':key,
'gpu':gpu, 'layer_count':layer_count, 'breakmodel':breakmodel,
'break_values': break_values, 'gpu_count': gpu_count,
@ -3160,7 +3164,7 @@ def sendUSStatItems():
# KoboldAI Markup Formatting (Mixture of Markdown and sanitized html)
#==================================================================#
def kml(txt):
txt = txt.replace('\>', '>')
txt = txt.replace('>', '>')
txt = bleach.clean(markdown.markdown(txt), tags = ['p', 'em', 'strong', 'code', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'li', 'ul', 'b', 'i', 'a', 'span', 'button'], styles = ['color', 'font-weight'], attributes=['id', 'class', 'style', 'href'])
return txt
@ -3184,6 +3188,7 @@ def setStartState():
#==================================================================#
def sendsettings():
# Send settings for selected AI type
emit('from_server', {'cmd': 'reset_menus'})
if(vars.model != "InferKit"):
for set in gensettings.gensettingstf:
emit('from_server', {'cmd': 'addsetting', 'data': set})
@ -5195,6 +5200,7 @@ def loadRequest(loadpath, filename=None):
vars.lastact = ""
vars.submission = ""
vars.lastctx = ""
vars.genseqs = []
del vars.actions
vars.actions = structures.KoboldStoryRegister()
@ -5456,7 +5462,7 @@ def importgame():
vars.importjs = {}
# Reset current save
vars.savedir = getcwd()+"\stories"
vars.savedir = getcwd()+"\\stories"
# Refresh game screen
vars.laststory = None
@ -5538,7 +5544,7 @@ def importAidgRequest(id):
vars.worldinfo_i = [wi for wi in vars.worldinfo if wi["init"]]
# Reset current save
vars.savedir = getcwd()+"\stories"
vars.savedir = getcwd()+"\\stories"
# Refresh game screen
vars.laststory = None
@ -5631,7 +5637,7 @@ def newGameRequest():
vars.lastctx = ""
# Reset current save
vars.savedir = getcwd()+"\stories"
vars.savedir = getcwd()+"\\stories"
# Refresh game screen
vars.laststory = None
@ -5769,7 +5775,7 @@ if __name__ == "__main__":
while attempts < 10:
try:
cloudflare = str(localtunnel.stdout.readline())
cloudflare = (re.search("(?P<url>https?:\/\/[^\s]+loca.lt)", cloudflare).group("url"))
cloudflare = (re.search("(?P<url>https?://[^s]+loca.lt)", cloudflare).group("url"))
break
except:
attempts += 1

View File

@ -151,6 +151,12 @@ function getThrottle(ms) {
}
}
function reset_menus() {
settings_menu.html("");
format_menu.html("");
wi_menu.html("");
}
function addSetting(ob) {
// Add setting block to Settings Menu
if(ob.uitype == "slider"){
@ -2031,9 +2037,7 @@ $(document).ready(function(){
connect_status.removeClass("color_orange");
connect_status.addClass("color_green");
// Reset Menus
settings_menu.html("");
format_menu.html("");
wi_menu.html("");
reset_menus();
// Set up "Allow Editing"
$('body').on('input', autofocus);
$('#allowediting').prop('checked', allowedit).prop('disabled', false).change().off('change').on('change', function () {
@ -2292,6 +2296,8 @@ $(document).ready(function(){
} else if(msg.cmd == "setanotetemplate") {
// Set contents of Author's Note Template field
$("#anotetemplate").val(msg.data);
} else if(msg.cmd == "reset_menus") {
reset_menus();
} else if(msg.cmd == "addsetting") {
// Add setting controls
addSetting(msg.data);

View File

@ -170,3 +170,47 @@ def test_load_model_from_command_line(client_data, model, expected_load_options)
generate_story_data(client_data)
def test_back_redo(client_data):
(client, app, socketio_client) = client_data
#Make sure we have known story in the ui
test_load_story_from_web_ui(client_data)
#Clear out any old messages
response = socketio_client.get_received()
#run a back action
socketio_client.emit('message',{'cmd': 'back', 'data': ''})
response = socketio_client.get_received()[0]['args'][0]
assert response == {'cmd': 'removechunk', 'data': 3}
#Run a redo action
socketio_client.emit('message',{'cmd': 'redo', 'data': ''})
response = socketio_client.get_received()[0]['args'][0]
assert response == {'cmd': 'updatechunk', 'data': {'index': 3, 'html': '<chunk n="3" id="n3" tabindex="-1"> where to find the chicken and then how to make off with it.<br/><br/>A soft thud caused Niko to quickly lift his head. Standing behind the stall where the butcher had been cutting his chicken,</chunk>'}}
#Go all the way back, then all the way forward
socketio_client.emit('message',{'cmd': 'back', 'data': ''})
response = socketio_client.get_received()[0]['args'][0]
assert response == {'cmd': 'removechunk', 'data': 3}
socketio_client.emit('message',{'cmd': 'back', 'data': ''})
response = socketio_client.get_received()[0]['args'][0]
assert response == {'cmd': 'removechunk', 'data': 2}
socketio_client.emit('message',{'cmd': 'back', 'data': ''})
response = socketio_client.get_received()[0]['args'][0]
assert response == {'cmd': 'removechunk', 'data': 1}
socketio_client.emit('message',{'cmd': 'back', 'data': ''})
response = socketio_client.get_received()[0]['args'][0]
assert response == {'cmd': 'errmsg', 'data': 'Cannot delete the prompt.'}
socketio_client.emit('message',{'cmd': 'redo', 'data': ''})
socketio_client.emit('message',{'cmd': 'redo', 'data': ''})
socketio_client.emit('message',{'cmd': 'redo', 'data': ''})
response = socketio_client.get_received()
assert response == [{'name': 'from_server', 'args': [{'cmd': 'updatescreen', 'gamestarted': True, 'data': '<chunk n="0" id="n0" tabindex="-1">Niko the kobold stalked carefully down the alley, his small scaly figure obscured by a dusky cloak that fluttered lightly in the cold winter breeze. Holding up his tail to keep it from dragging in the dirty snow that covered the cobblestone, he waited patiently for the butcher to turn his attention from his stall so that he could pilfer his next meal: a tender-looking</chunk><chunk n="1" id="n1" tabindex="-1"> chicken. He crouched just slightly as he neared the stall to ensure that no one was watching, not that anyone would be dumb enough to hassle a small kobold. What else was there for a lowly kobold to</chunk>'}], 'namespace': '/'}, {'name': 'from_server', 'args': [{'cmd': 'texteffect', 'data': 1}], 'namespace': '/'}, {'name': 'from_server', 'args': [{'cmd': 'updatechunk', 'data': {'index': 2, 'html': '<chunk n="2" id="n2" tabindex="-1"> do in a city? All that Niko needed to know was</chunk>'}}], 'namespace': '/'}, {'name': 'from_server', 'args': [{'cmd': 'texteffect', 'data': 2}], 'namespace': '/'}, {'name': 'from_server', 'args': [{'cmd': 'updatechunk', 'data': {'index': 3, 'html': '<chunk n="3" id="n3" tabindex="-1"> where to find the chicken and then how to make off with it.<br/><br/>A soft thud caused Niko to quickly lift his head. Standing behind the stall where the butcher had been cutting his chicken,</chunk>'}}], 'namespace': '/'}, {'name': 'from_server', 'args': [{'cmd': 'texteffect', 'data': 3}], 'namespace': '/'}]