mirror of
https://github.com/KoboldAI/KoboldAI-Client.git
synced 2025-02-17 12:10:49 +01:00
commit
bbd5bd0cd7
22
aiserver.py
22
aiserver.py
@ -102,6 +102,7 @@ class vars:
|
||||
svowname = "" # Filename that was flagged for overwrite confirm
|
||||
saveow = False # Whether or not overwrite confirm has been displayed
|
||||
genseqs = [] # Temporary storage for generated sequences
|
||||
recentback = False # Whether Back button was recently used without Submitting or Retrying after
|
||||
useprompt = True # Whether to send the full prompt with every submit action
|
||||
breakmodel = False # For GPU users, whether to use both system RAM and VRAM to conserve VRAM while offering speedup compared to CPU-only
|
||||
bmsupported = False # Whether the breakmodel option is supported (GPT-Neo/GPT-J only, currently)
|
||||
@ -528,7 +529,7 @@ def do_connect():
|
||||
#==================================================================#
|
||||
@socketio.on('message')
|
||||
def get_message(msg):
|
||||
print("{0}Data recieved:{1}{2}".format(colors.GREEN, msg, colors.END))
|
||||
print("{0}Data received:{1}{2}".format(colors.GREEN, msg, colors.END))
|
||||
# Submit action
|
||||
if(msg['cmd'] == 'submit'):
|
||||
if(vars.mode == "play"):
|
||||
@ -829,6 +830,7 @@ def actionsubmit(data, actionmode=0):
|
||||
return
|
||||
set_aibusy(1)
|
||||
|
||||
vars.recentback = False
|
||||
vars.actionmode = actionmode
|
||||
|
||||
# "Action" mode
|
||||
@ -882,12 +884,17 @@ def actionretry(data):
|
||||
return
|
||||
if(vars.aibusy):
|
||||
return
|
||||
set_aibusy(1)
|
||||
# Remove last action if possible and resubmit
|
||||
if(len(vars.actions) > 0):
|
||||
vars.actions.pop()
|
||||
if(vars.gamestarted if vars.useprompt else len(vars.actions) > 0):
|
||||
set_aibusy(1)
|
||||
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
|
||||
vars.actions.pop()
|
||||
vars.genseqs = []
|
||||
refresh_story()
|
||||
calcsubmit('')
|
||||
vars.recentback = False
|
||||
elif(not vars.useprompt):
|
||||
emit('from_server', {'cmd': 'errmsg', 'data': "Please enable \"Always Add Prompt\" to retry with your prompt."})
|
||||
|
||||
#==================================================================#
|
||||
#
|
||||
@ -896,9 +903,14 @@ def actionback():
|
||||
if(vars.aibusy):
|
||||
return
|
||||
# Remove last index of actions and refresh game screen
|
||||
if(len(vars.actions) > 0):
|
||||
if(len(vars.genseqs) == 0 and len(vars.actions) > 0):
|
||||
vars.actions.pop()
|
||||
vars.recentback = True
|
||||
refresh_story()
|
||||
elif(len(vars.genseqs) == 0):
|
||||
emit('from_server', {'cmd': 'errmsg', 'data': "Cannot delete the prompt."})
|
||||
else:
|
||||
vars.genseqs = []
|
||||
|
||||
#==================================================================#
|
||||
# Take submitted text and build the text to be given to generator
|
||||
|
19
fileops.py
19
fileops.py
@ -59,14 +59,23 @@ def getdirpath(dir, title):
|
||||
#==================================================================#
|
||||
def getstoryfiles():
|
||||
list = []
|
||||
for file in listdir(getcwd()+"/stories"):
|
||||
for file in listdir(path.dirname(path.realpath(__file__))+"/stories"):
|
||||
if file.endswith(".json"):
|
||||
ob = {}
|
||||
ob["name"] = file.replace(".json", "")
|
||||
f = open(getcwd()+"/stories/"+file, "r")
|
||||
js = json.load(f)
|
||||
f = open(path.dirname(path.realpath(__file__))+"/stories/"+file, "r")
|
||||
try:
|
||||
js = json.load(f)
|
||||
except:
|
||||
print(f"Browser loading error: {file} is malformed or not a JSON file.")
|
||||
f.close()
|
||||
continue
|
||||
f.close()
|
||||
ob["actions"] = len(js["actions"])
|
||||
try:
|
||||
ob["actions"] = len(js["actions"])
|
||||
except TypeError:
|
||||
print(f"Browser loading error: {file} has incorrect format.")
|
||||
continue
|
||||
list.append(ob)
|
||||
return list
|
||||
|
||||
@ -74,4 +83,4 @@ def getstoryfiles():
|
||||
# Returns True if json file exists with requested save name
|
||||
#==================================================================#
|
||||
def saveexists(name):
|
||||
return path.exists(getcwd()+"/stories/"+name+".json")
|
||||
return path.exists(path.dirname(path.realpath(__file__))+"/stories/"+name+".json")
|
||||
|
@ -1107,11 +1107,13 @@ $(document).ready(function(){
|
||||
});
|
||||
|
||||
button_actretry.on("click", function(ev) {
|
||||
hideMessage();
|
||||
socket.send({'cmd': 'retry', 'data': ''});
|
||||
hidegenseqs();
|
||||
});
|
||||
|
||||
button_actback.on("click", function(ev) {
|
||||
hideMessage();
|
||||
socket.send({'cmd': 'back', 'data': ''});
|
||||
hidegenseqs();
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user