Allow pressing send button again to stop generation

This commit is contained in:
Gnome Ann 2022-01-10 16:36:15 -05:00
parent c84d864021
commit f718fdf65e
4 changed files with 40 additions and 16 deletions

View File

@ -127,6 +127,7 @@ class vars:
lua_edited = set() # Set of chunk numbers that were edited from a Lua generation modifier
lua_deleted = set() # Set of chunk numbers that were deleted from a Lua generation modifier
generated_tkns = 0 # If using a backend that supports Lua generation modifiers, how many tokens have already been generated, otherwise 0
abort = False # Whether or not generation was aborted by clicking on the submit button during generation
spfilename = "" # Filename of soft prompt to load, or an empty string if not using a soft prompt
userscripts = [] # List of userscripts to load
last_userscripts = [] # List of previous userscript filenames from the previous time userscripts were send via usstatitems
@ -820,7 +821,7 @@ if(not vars.model in ["InferKit", "Colab", "OAI", "ReadOnly", "TPUMeshTransforme
vars.generated_tkns += 1
if(vars.lua_koboldbridge.generated_cols and vars.generated_tkns != vars.lua_koboldbridge.generated_cols):
raise RuntimeError(f"Inconsistency detected between KoboldAI Python and Lua backends ({vars.generated_tkns} != {vars.lua_koboldbridge.generated_cols})")
if(vars.generated_tkns >= vars.genamt):
if(vars.abort or vars.generated_tkns >= vars.genamt):
self.regeneration_required = False
self.halt = False
return True
@ -1707,6 +1708,10 @@ def get_message(msg):
# Submit action
if(msg['cmd'] == 'submit'):
if(vars.mode == "play"):
if(vars.aibusy and msg.get('allowabort', False)):
vars.abort = True
return
vars.abort = False
vars.lua_koboldbridge.feedback = None
if(vars.chatmode):
if(type(msg['chatname']) is not str):
@ -1722,6 +1727,10 @@ def get_message(msg):
memsubmit(msg['data'])
# Retry Action
elif(msg['cmd'] == 'retry'):
if(vars.aibusy and msg.get('allowabort', False)):
vars.abort = True
return
vars.abort = False
if(vars.chatmode):
if(type(msg['chatname']) is not str):
raise ValueError("Chatname must be a string")
@ -2236,7 +2245,7 @@ def actionsubmit(data, actionmode=0, force_submit=False, force_prompt_gen=False,
# Clear the startup text from game screen
emit('from_server', {'cmd': 'updatescreen', 'gamestarted': False, 'data': 'Please wait, generating story...'}, broadcast=True)
calcsubmit(data) # Run the first action through the generator
if(vars.lua_koboldbridge.restart_sequence is not None and len(vars.genseqs) == 0):
if(not vars.abort and vars.lua_koboldbridge.restart_sequence is not None and len(vars.genseqs) == 0):
data = ""
force_submit = True
disable_recentrng = True
@ -2245,7 +2254,7 @@ def actionsubmit(data, actionmode=0, force_submit=False, force_prompt_gen=False,
break
else:
# Save this first action as the prompt
vars.prompt = data
vars.prompt = data if len(data) > 0 else '"'
for i in range(vars.numseqs):
vars.lua_koboldbridge.outputs[i+1] = ""
execute_outmod()
@ -2259,13 +2268,13 @@ def actionsubmit(data, actionmode=0, force_submit=False, force_prompt_gen=False,
refresh_story()
if(len(vars.actions) > 0):
emit('from_server', {'cmd': 'texteffect', 'data': vars.actions.get_last_key() + 1}, broadcast=True)
if(vars.lua_koboldbridge.restart_sequence is not None):
if(not vars.abort and vars.lua_koboldbridge.restart_sequence is not None):
data = ""
force_submit = True
disable_recentrng = True
continue
else:
if(vars.lua_koboldbridge.restart_sequence is not None and vars.lua_koboldbridge.restart_sequence > 0):
if(not vars.abort and vars.lua_koboldbridge.restart_sequence is not None and vars.lua_koboldbridge.restart_sequence > 0):
genresult(genout[vars.lua_koboldbridge.restart_sequence-1]["generated_text"], flash=False)
refresh_story()
data = ""
@ -2296,7 +2305,7 @@ def actionsubmit(data, actionmode=0, force_submit=False, force_prompt_gen=False,
if(not vars.noai and vars.lua_koboldbridge.generating):
# Off to the tokenizer!
calcsubmit(data)
if(vars.lua_koboldbridge.restart_sequence is not None and len(vars.genseqs) == 0):
if(not vars.abort and vars.lua_koboldbridge.restart_sequence is not None and len(vars.genseqs) == 0):
data = ""
force_submit = True
disable_recentrng = True
@ -2314,13 +2323,13 @@ def actionsubmit(data, actionmode=0, force_submit=False, force_prompt_gen=False,
assert type(genout[-1]["generated_text"]) is str
if(len(genout) == 1):
genresult(genout[0]["generated_text"])
if(vars.lua_koboldbridge.restart_sequence is not None):
if(not vars.abort and vars.lua_koboldbridge.restart_sequence is not None):
data = ""
force_submit = True
disable_recentrng = True
continue
else:
if(vars.lua_koboldbridge.restart_sequence is not None and vars.lua_koboldbridge.restart_sequence > 0):
if(not vars.abort and vars.lua_koboldbridge.restart_sequence is not None and vars.lua_koboldbridge.restart_sequence > 0):
genresult(genout[vars.lua_koboldbridge.restart_sequence-1]["generated_text"])
data = ""
force_submit = True

View File

@ -92,6 +92,7 @@ var sman_allow_delete = false;
var sman_allow_rename = false;
var allowsp = false;
var remote = false;
var gamestate = "";
// This is true iff [we're in macOS and the browser is Safari] or [we're in iOS]
var using_webkit_patch = true;
@ -648,12 +649,14 @@ function disableButtons(refs) {
}
function enableSendBtn() {
enableButtons([button_send])
button_send.removeClass("wait");
button_send.addClass("btn-primary");
button_send.html("Submit");
}
function disableSendBtn() {
disableButtons([button_send])
button_send.removeClass("btn-primary");
button_send.addClass("wait");
button_send.html("");
}
@ -794,15 +797,15 @@ function formatChunkInnerText(chunk) {
return text;
}
function dosubmit() {
function dosubmit(disallow_abort) {
var txt = input_text.val().replace(/\u00a0/g, " ");
if(!memorymode && !gamestarted && ((!adventure || !action_mode) && txt.trim().length == 0)) {
if(gamestate !== "wait" && !memorymode && !gamestarted && ((!adventure || !action_mode) && txt.trim().length == 0)) {
return;
}
input_text.val("");
hideMessage();
hidegenseqs();
socket.send({'cmd': 'submit', 'actionmode': adventure ? action_mode : 0, 'chatname': chatmode ? chat_name.val() : undefined, 'data': txt});
socket.send({'cmd': 'submit', 'allowabort': !disallow_abort, 'actionmode': adventure ? action_mode : 0, 'chatname': chatmode ? chat_name.val() : undefined, 'data': txt});
if(memorymode) {
memorytext = input_text.val();
}
@ -1889,12 +1892,15 @@ $(document).ready(function(){
enableSendBtn();
enableButtons([button_actmem, button_actwi, button_actback, button_actretry]);
hideWaitAnimation();
gamestate = "ready";
} else if(msg.data == "wait") {
gamestate = "wait";
disableSendBtn();
disableButtons([button_actmem, button_actwi, button_actback, button_actretry]);
showWaitAnimation();
} else if(msg.data == "start") {
setStartState();
gamestate = "ready";
}
} else if(msg.cmd == "allowsp") {
allowsp = !!msg.data;
@ -2495,7 +2501,7 @@ $(document).ready(function(){
input_text.keydown(function (ev) {
if (ev.which == 13 && !shift_down) {
do_clear_ent = true;
dosubmit();
dosubmit(true);
} else if(ev.which == 16) {
shift_down = true;
}

View File

@ -206,7 +206,16 @@ body.connected #formatmenu, #formatmenu.always-available {
height: 100%;
}
#btnsend.wait {
background-color: #6c6c6e;
}
#btnsend.wait:hover {
background-color: #98989a;
}
#waitanim {
pointer-events: none;
position:absolute;
top:18px;
left:5px;

View File

@ -9,7 +9,7 @@
<link rel="stylesheet" href="static/bootstrap.min.css">
<link rel="stylesheet" href="static/bootstrap-toggle.min.css">
<link rel="stylesheet" href="static/open-iconic-bootstrap.min.css">
<link rel="stylesheet" href="static/custom.css?ver=1.16.4m">
<link rel="stylesheet" href="static/custom.css?ver=1.16.4n">
<script src="static/jquery-3.6.0.min.js"></script>
<script src="static/jquery-ui.sortable.min.js"></script>
@ -17,7 +17,7 @@
<script src="static/bootstrap.min.js"></script>
<script src="static/bootstrap-toggle.min.js"></script>
<script src="static/rangy-core.min.js"></script>
<script src="static/application.js?ver=1.16.4v"></script>
<script src="static/application.js?ver=1.16.4w"></script>
</head>
<body>
<input type="file" id="remote-save-select" accept="application/json" style="display:none">