Merge branch 'KoboldAI:main' into united

This commit is contained in:
henk717 2021-09-29 17:05:06 +02:00 committed by GitHub
commit dab58d8393
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 46 additions and 14 deletions

View File

@ -1,6 +1,6 @@
#==================================================================#
# KoboldAI
# Version: 1.16.1
# Version: 1.16.2
# By: KoboldAIDev and the KoboldAI Community
#==================================================================#
@ -936,7 +936,7 @@ def settingschanged():
#==================================================================#
# Take input text from SocketIO and decide what to do with it
#==================================================================#
def actionsubmit(data, actionmode=0):
def actionsubmit(data, actionmode=0, force_submit=False):
# Ignore new submissions if the AI is currently busy
if(vars.aibusy):
return
@ -950,6 +950,7 @@ def actionsubmit(data, actionmode=0):
if(actionmode == 1):
data = data.strip().lstrip('>')
data = re.sub(r'\n+', ' ', data)
if(len(data)):
data = f"\n\n> {data}\n"
# If we're not continuing, store a copy of the raw input
@ -957,6 +958,9 @@ def actionsubmit(data, actionmode=0):
vars.lastact = data
if(not vars.gamestarted):
if(not force_submit and len(data.strip()) == 0):
set_aibusy(0)
return
# Start the game
vars.gamestarted = True
# Save this first action as the prompt
@ -977,6 +981,9 @@ def actionsubmit(data, actionmode=0):
if(vars.actionmode == 0):
data = applyinputformatting(data)
# Store the result in the Action log
if(len(vars.prompt.strip()) == 0):
vars.prompt = data
else:
vars.actions.append(data)
update_story_chunk('last')
@ -1000,12 +1007,13 @@ def actionretry(data):
# Remove last action if possible and resubmit
if(vars.gamestarted if vars.useprompt else len(vars.actions) > 0):
set_aibusy(1)
if(not vars.recentback and not vars.recentedit and len(vars.actions) != 0 and len(vars.genseqs) == 0): # Don't pop if we're in the "Select sequence to keep" menu or if there are no non-prompt actions
if(not vars.recentback and len(vars.actions) != 0 and len(vars.genseqs) == 0): # Don't pop if we're in the "Select sequence to keep" menu or if there are no non-prompt actions
last_key = vars.actions.get_last_key()
vars.actions.pop()
remove_story_chunk(last_key + 1)
vars.genseqs = []
calcsubmit('')
emit('from_server', {'cmd': 'scrolldown', 'data': ''}, broadcast=True)
vars.recentback = False
vars.recentedit = False
elif(not vars.useprompt):
@ -1290,6 +1298,9 @@ def genresult(genout):
genout = applyoutputformatting(genout)
# Add formatted text to Actions array and refresh the game screen
if(len(vars.prompt.strip()) == 0):
vars.prompt = genout
else:
vars.actions.append(genout)
update_story_chunk('last')
emit('from_server', {'cmd': 'texteffect', 'data': vars.actions.get_last_key() if len(vars.actions) else 0}, broadcast=True)
@ -2108,7 +2119,18 @@ def loadRequest(loadpath):
del vars.actions
vars.actions = structures.KoboldStoryRegister()
for s in js["actions"]:
actions = collections.deque(js["actions"])
if(len(vars.prompt.strip()) == 0):
while(len(actions)):
action = actions.popleft()
if(len(action.strip()) != 0):
vars.prompt = action
break
else:
vars.gamestarted = False
if(vars.gamestarted):
for s in actions:
vars.actions.append(s)
# Try not to break older save files
@ -2383,7 +2405,7 @@ def newGameRequest():
def randomGameRequest(topic):
newGameRequest()
vars.memory = "You generate the following " + topic + " story concept :"
actionsubmit("")
actionsubmit("", force_submit=True)
vars.memory = ""
#==================================================================#

View File

@ -466,6 +466,7 @@ function enterWiMode() {
hide([button_actback, button_actmem, button_actretry, game_text]);
show([wi_menu]);
disableSendBtn();
$("#gamescreen").addClass("wigamescreen");
}
function exitWiMode() {
@ -474,7 +475,7 @@ function exitWiMode() {
hide([wi_menu]);
show([button_actback, button_actmem, button_actretry, game_text]);
enableSendBtn();
scrollToBottom();
$("#gamescreen").removeClass("wigamescreen");
}
function returnWiList(ar) {
@ -493,7 +494,11 @@ function returnWiList(ar) {
}
function dosubmit() {
var txt = input_text.val();
var txt = input_text.val().replace(/\u00a0/g, " ");
console.log(gamestarted)
if(!gamestarted && ((!adventure || !action_mode) && txt.trim().length == 0)) {
return;
}
socket.send({'cmd': 'submit', 'actionmode': adventure ? action_mode : 0, 'data': txt});
if(memorymode) {
memorytext = input_text.val();
@ -881,7 +886,7 @@ function syncAllModifiedChunks(including_selected_chunks=false) {
}
function restorePrompt() {
if(game_text[0].firstChild.nodeType === 3) {
if(game_text[0].firstChild && game_text[0].firstChild.nodeType === 3) {
saved_prompt = game_text[0].firstChild.textContent.replace(/\u00a0/g, " ");
unbindGametext();
game_text[0].innerText = "";

View File

@ -77,6 +77,11 @@ chunk.editing, chunk.editing * {
font-family: "Helvetica";
}
#gamescreen.wigamescreen {
padding: 10px;
overflow-y: scroll;
}
#gamescreen span {
align-self: flex-end;
}

View File

@ -6,14 +6,14 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="static/jquery-3.6.0.min.js"></script>
<script src="static/socket.io.min.js"></script>
<script src="static/application.js?ver=0.15.0g"></script>
<script src="static/application.js?ver=1.16.2a"></script>
<script src="static/bootstrap.min.js"></script>
<script src="static/bootstrap-toggle.min.js"></script>
<script src="static/rangy-core.min.js"></script>
<link rel="stylesheet" href="static/bootstrap.min.css">
<link rel="stylesheet" href="static/bootstrap-toggle.min.css">
<link rel="stylesheet" href="static/custom.css?ver=0.15.0g">
<link rel="stylesheet" href="static/custom.css?ver=1.16.2a">
<link rel="stylesheet" href="static/open-iconic-bootstrap.min.css">
</head>
<body>