mirror of
https://github.com/KoboldAI/KoboldAI-Client.git
synced 2025-02-23 06:57:44 +01:00
Merge branch 'united' into big-o
This resolves two merge conflicts that arose because this branch was a few commits behind.
This commit is contained in:
commit
d7605a717b
64
aiserver.py
64
aiserver.py
@ -106,6 +106,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)
|
||||
@ -532,7 +533,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"):
|
||||
@ -668,6 +669,10 @@ def get_message(msg):
|
||||
vars.worldinfo[msg['data']]["selective"] = True
|
||||
elif(msg['cmd'] == 'wiseloff'):
|
||||
vars.worldinfo[msg['data']]["selective"] = False
|
||||
elif(msg['cmd'] == 'wiconstanton'):
|
||||
vars.worldinfo[msg['data']]["constant"] = True
|
||||
elif(msg['cmd'] == 'wiconstantoff'):
|
||||
vars.worldinfo[msg['data']]["constant"] = False
|
||||
elif(msg['cmd'] == 'sendwilist'):
|
||||
commitwi(msg['data'])
|
||||
elif(msg['cmd'] == 'aidgimport'):
|
||||
@ -828,6 +833,7 @@ def actionsubmit(data, actionmode=0):
|
||||
return
|
||||
set_aibusy(1)
|
||||
|
||||
vars.recentback = False
|
||||
vars.actionmode = actionmode
|
||||
|
||||
# "Action" mode
|
||||
@ -881,13 +887,18 @@ def actionretry(data):
|
||||
return
|
||||
if(vars.aibusy):
|
||||
return
|
||||
set_aibusy(1)
|
||||
# Remove last action if possible and resubmit
|
||||
if(len(vars.actions) > 0):
|
||||
last_key = vars.actions.get_last_key()
|
||||
vars.actions.pop()
|
||||
remove_story_chunk(last_key + 1)
|
||||
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
|
||||
last_key = vars.actions.get_last_key()
|
||||
vars.actions.pop()
|
||||
remove_story_chunk(last_key + 1)
|
||||
vars.genseqs = []
|
||||
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,10 +907,15 @@ 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):
|
||||
last_key = vars.actions.get_last_key()
|
||||
vars.actions.pop()
|
||||
vars.recentback = True
|
||||
remove_story_chunk(last_key + 1)
|
||||
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
|
||||
@ -1515,7 +1531,7 @@ def togglewimode():
|
||||
#
|
||||
#==================================================================#
|
||||
def addwiitem():
|
||||
ob = {"key": "", "keysecondary": "", "content": "", "num": len(vars.worldinfo), "init": False, "selective": False}
|
||||
ob = {"key": "", "keysecondary": "", "content": "", "num": len(vars.worldinfo), "init": False, "selective": False, "constant": False}
|
||||
vars.worldinfo.append(ob);
|
||||
emit('from_server', {'cmd': 'addwiitem', 'data': ob}, broadcast=True)
|
||||
|
||||
@ -1570,6 +1586,7 @@ def commitwi(ar):
|
||||
vars.worldinfo[ob["num"]]["keysecondary"] = ob["keysecondary"]
|
||||
vars.worldinfo[ob["num"]]["content"] = ob["content"]
|
||||
vars.worldinfo[ob["num"]]["selective"] = ob["selective"]
|
||||
vars.worldinfo[ob["num"]]["constant"] = ob.get("constant", False)
|
||||
# Was this a deletion request? If so, remove the requested index
|
||||
if(vars.deletewi >= 0):
|
||||
del vars.worldinfo[vars.deletewi]
|
||||
@ -1628,6 +1645,10 @@ def checkworldinfo(txt):
|
||||
# Scan text for matches on WI keys
|
||||
wimem = ""
|
||||
for wi in vars.worldinfo:
|
||||
if(wi.get("constant", False)):
|
||||
wimem = wimem + wi["content"] + "\n"
|
||||
continue
|
||||
|
||||
if(wi["key"] != ""):
|
||||
# Split comma-separated keys
|
||||
keys = wi["key"].split(",")
|
||||
@ -1847,12 +1868,13 @@ def saveRequest(savpath):
|
||||
|
||||
# Extract only the important bits of WI
|
||||
for wi in vars.worldinfo:
|
||||
if(wi["key"] != ""):
|
||||
if(wi["constant"] or wi["key"] != ""):
|
||||
js["worldinfo"].append({
|
||||
"key": wi["key"],
|
||||
"keysecondary": wi["keysecondary"],
|
||||
"content": wi["content"],
|
||||
"selective": wi["selective"]
|
||||
"selective": wi["selective"],
|
||||
"constant": wi["constant"]
|
||||
})
|
||||
|
||||
# Write it
|
||||
@ -1917,7 +1939,8 @@ def loadRequest(loadpath):
|
||||
"content": wi["content"],
|
||||
"num": num,
|
||||
"init": True,
|
||||
"selective": wi.get("selective", False)
|
||||
"selective": wi.get("selective", False),
|
||||
"constant": wi.get("constant", False)
|
||||
})
|
||||
num += 1
|
||||
|
||||
@ -2035,7 +2058,8 @@ def importgame():
|
||||
"content": wi["entry"],
|
||||
"num": num,
|
||||
"init": True,
|
||||
"selective": wi.get("selective", False)
|
||||
"selective": wi.get("selective", False),
|
||||
"constant": wi.get("constant", False)
|
||||
})
|
||||
num += 1
|
||||
|
||||
@ -2081,7 +2105,8 @@ def importAidgRequest(id):
|
||||
"content": wi["entry"],
|
||||
"num": num,
|
||||
"init": True,
|
||||
"selective": wi.get("selective", False)
|
||||
"selective": wi.get("selective", False),
|
||||
"constant": wi.get("constant", False)
|
||||
})
|
||||
num += 1
|
||||
|
||||
@ -2114,7 +2139,8 @@ def wiimportrequest():
|
||||
"content": wi["entry"],
|
||||
"num": num,
|
||||
"init": True,
|
||||
"selective": wi.get("selective", False)
|
||||
"selective": wi.get("selective", False),
|
||||
"constant": wi.get("constant", False)
|
||||
})
|
||||
num += 1
|
||||
|
||||
@ -2163,13 +2189,17 @@ if __name__ == "__main__":
|
||||
loadsettings()
|
||||
|
||||
# Start Flask/SocketIO (Blocking, so this must be last method!)
|
||||
print("{0}Server started!\rYou may now connect with a browser at http://127.0.0.1:5000/{1}".format(colors.GREEN, colors.END))
|
||||
|
||||
#socketio.run(app, host='0.0.0.0', port=5000)
|
||||
if(vars.remote):
|
||||
from flask_cloudflared import start_cloudflared
|
||||
start_cloudflared(5000)
|
||||
from flask_cloudflared import _run_cloudflared
|
||||
cloudflare = _run_cloudflared(5000)
|
||||
with open('cloudflare.log', 'w') as cloudflarelog:
|
||||
cloudflarelog.write("KoboldAI has finished loading and is available in the following link : " + cloudflare)
|
||||
print(format(colors.GREEN) + "KoboldAI has finished loading and is available in the following link : " + cloudflare + format(colors.END))
|
||||
socketio.run(app, host='0.0.0.0', port=5000)
|
||||
else:
|
||||
import webbrowser
|
||||
webbrowser.open_new('http://localhost:5000')
|
||||
print("{0}Server started!\rYou may now connect with a browser at http://127.0.0.1:5000/{1}".format(colors.GREEN, colors.END))
|
||||
socketio.run(app)
|
||||
|
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")
|
||||
|
@ -1,4 +1,4 @@
|
||||
transformers == 4.5.1
|
||||
git+https://github.com/finetuneanon/transformers@gpt-neo-localattention3-rp-b
|
||||
tensorflow-gpu
|
||||
Flask == 1.1.2
|
||||
Flask-SocketIO == 5.0.1
|
||||
|
@ -189,13 +189,14 @@ function addWiLine(ob) {
|
||||
<button type=\"button\" class=\"btn btn-success heighthalf hidden\" id=\"btn_widel"+ob.num+"\">✓</button>\
|
||||
<button type=\"button\" class=\"btn btn-danger heighthalf hidden\" id=\"btn_wican"+ob.num+"\">⮌</button>\
|
||||
</div>\
|
||||
<div class=\"wikey\">\
|
||||
<div class=\"icon-container wikey\">\
|
||||
<input class=\"form-control heightfull hidden\" type=\"text\" placeholder=\"Key(s)\" id=\"wikey"+ob.num+"\">\
|
||||
<input class=\"form-control heighthalf\" type=\"text\" placeholder=\"Primary Key(s)\" id=\"wikeyprimary"+ob.num+"\">\
|
||||
<input class=\"form-control heighthalf\" type=\"text\" placeholder=\"Secondary Key(s)\" id=\"wikeysecondary"+ob.num+"\">\
|
||||
<span class=\"constant-key-icon "+(ob.constant ? "constant-key-icon-enabled" : "")+" oi oi-pin\" id=\"constant-key-"+ob.num+"\" title=\"Toggle Constant Key mode (if enabled, this world info entry will always be included in memory)\" aria-hidden=\"true\"></span>\
|
||||
</div>\
|
||||
<div class=\"wientry\">\
|
||||
<textarea class=\"form-control\" id=\"wientry"+ob.num+"\" placeholder=\"What To Remember\">"+ob.content+"</textarea>\
|
||||
<textarea class=\"layer-bottom form-control\" id=\"wientry"+ob.num+"\" placeholder=\"What To Remember\">"+ob.content+"</textarea>\
|
||||
</div>\
|
||||
<div class=\"wiselective\">\
|
||||
<button type=\"button\" class=\"btn btn-success heightfull hidden\" id=\"btn_wiselon"+ob.num+"\">Enable Selective Mode</button>\
|
||||
@ -209,10 +210,11 @@ function addWiLine(ob) {
|
||||
<button type=\"button\" class=\"btn btn-success heighthalf hidden\" id=\"btn_widel"+ob.num+"\">✓</button>\
|
||||
<button type=\"button\" class=\"btn btn-danger heighthalf hidden\" id=\"btn_wican"+ob.num+"\">⮌</button>\
|
||||
</div>\
|
||||
<div class=\"wikey\">\
|
||||
<div class=\"icon-container wikey\">\
|
||||
<input class=\"form-control heightfull\" type=\"text\" placeholder=\"Key(s)\" id=\"wikey"+ob.num+"\">\
|
||||
<input class=\"form-control heighthalf hidden\" type=\"text\" placeholder=\"Primary Key(s)\" id=\"wikeyprimary"+ob.num+"\">\
|
||||
<input class=\"form-control heighthalf hidden\" type=\"text\" placeholder=\"Secondary Key(s)\" id=\"wikeysecondary"+ob.num+"\">\
|
||||
<span class=\"constant-key-icon "+(ob.constant ? "constant-key-icon-enabled" : "")+" oi oi-pin\" id=\"constant-key-"+ob.num+"\" title=\"Toggle Constant Key mode (if enabled, this world info entry will always be included in memory)\" aria-hidden=\"true\"></span>\
|
||||
</div>\
|
||||
<div class=\"wientry\">\
|
||||
<textarea class=\"form-control\" id=\"wientry"+ob.num+"\" placeholder=\"What To Remember\">"+ob.content+"</textarea>\
|
||||
@ -239,13 +241,14 @@ function addWiLine(ob) {
|
||||
<button type=\"button\" class=\"btn btn-success heighthalf hidden\" id=\"btn_widel"+ob.num+"\">✓</button>\
|
||||
<button type=\"button\" class=\"btn btn-danger heighthalf hidden\" id=\"btn_wican"+ob.num+"\">X</button>\
|
||||
</div>\
|
||||
<div class=\"wikey\">\
|
||||
<div class=\"icon-container wikey\">\
|
||||
<input class=\"form-control heightfull hidden\" type=\"text\" placeholder=\"Key(s)\" id=\"wikey"+ob.num+"\">\
|
||||
<input class=\"form-control heighthalf hidden\" type=\"text\" placeholder=\"Primary Key(s)\" id=\"wikeyprimary"+ob.num+"\">\
|
||||
<input class=\"form-control heighthalf hidden\" type=\"text\" placeholder=\"Secondary Key(s)\" id=\"wikeysecondary"+ob.num+"\">\
|
||||
<span class=\"constant-key-icon oi oi-pin hidden\" id=\"constant-key-"+ob.num+"\" title=\"Toggle Constant Key mode (if enabled, this world info entry will always be included in memory)\" aria-hidden=\"true\"></span>\
|
||||
</div>\
|
||||
<div class=\"wientry\">\
|
||||
<textarea class=\"form-control hidden\" id=\"wientry"+ob.num+"\" placeholder=\"What To Remember\"></textarea>\
|
||||
<textarea class=\"layer-bottom form-control hidden\" id=\"wientry"+ob.num+"\" placeholder=\"What To Remember\">"+ob.content+"</textarea>\
|
||||
</div>\
|
||||
<div class=\"wiselective\">\
|
||||
<button type=\"button\" class=\"btn btn-success heightfull hidden\" id=\"btn_wiselon"+ob.num+"\">Enable Selective Mode</button>\
|
||||
@ -258,6 +261,18 @@ function addWiLine(ob) {
|
||||
});
|
||||
}
|
||||
// Assign actions to other elements
|
||||
wientry_onfocus = function () {
|
||||
$("#constant-key-"+ob.num).addClass("constant-key-icon-clickthrough");
|
||||
}
|
||||
wientry_onfocusout = function () {
|
||||
$("#constant-key-"+ob.num).removeClass("constant-key-icon-clickthrough");
|
||||
}
|
||||
$("#wikey"+ob.num).on("focus", wientry_onfocus);
|
||||
$("#wikeyprimary"+ob.num).on("focus", wientry_onfocus);
|
||||
$("#wikeysecondary"+ob.num).on("focus", wientry_onfocus);
|
||||
$("#wikey"+ob.num).on("focusout", wientry_onfocusout);
|
||||
$("#wikeyprimary"+ob.num).on("focusout", wientry_onfocusout);
|
||||
$("#wikeysecondary"+ob.num).on("focusout", wientry_onfocusout);
|
||||
$("#btn_wican"+ob.num).on("click", function () {
|
||||
hideWiDeleteConfirm(ob.num);
|
||||
});
|
||||
@ -270,10 +285,20 @@ function addWiLine(ob) {
|
||||
$("#btn_wiseloff"+ob.num).on("click", function () {
|
||||
disableWiSelective(ob.num);
|
||||
});
|
||||
$("#constant-key-"+ob.num).on("click", function () {
|
||||
element = $("#constant-key-"+ob.num);
|
||||
if(element.hasClass("constant-key-icon-enabled")) {
|
||||
socket.send({'cmd': 'wiconstantoff', 'data': ob.num});
|
||||
element.removeClass("constant-key-icon-enabled")
|
||||
} else {
|
||||
socket.send({'cmd': 'wiconstanton', 'data': ob.num});
|
||||
element.addClass("constant-key-icon-enabled");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function expandWiLine(num) {
|
||||
show([$("#wikey"+num), $("#wientry"+num), $("#btn_wiselon"+num)]);
|
||||
show([$("#wikey"+num), $("#wientry"+num), $("#constant-key-"+num), $("#btn_wiselon"+num)]);
|
||||
$("#btn_wi"+num).html("X");
|
||||
$("#btn_wi"+num).off();
|
||||
// Tell server the WI entry was initialized
|
||||
@ -297,6 +322,7 @@ function enableWiSelective(num) {
|
||||
hide([$("#btn_wiselon"+num), $("#wikey"+num)]);
|
||||
// Tell server the WI entry is now selective
|
||||
socket.send({'cmd': 'wiselon', 'data': num});
|
||||
$("#wikeyprimary"+num).val($("#wikey"+num).val());
|
||||
show([$("#wikeyprimary"+num), $("#wikeysecondary"+num), $("#btn_wiseloff"+num)]);
|
||||
}
|
||||
|
||||
@ -304,6 +330,7 @@ function disableWiSelective(num) {
|
||||
hide([$("#btn_wiseloff"+num), $("#wikeyprimary"+num), $("#wikeysecondary"+num)]);
|
||||
// Tell server the WI entry is now non-selective
|
||||
socket.send({'cmd': 'wiseloff', 'data': num});
|
||||
$("#wikey"+num).val($("#wikeyprimary"+num).val());
|
||||
show([$("#btn_wiselon"+num), $("#wikey"+num)]);
|
||||
}
|
||||
|
||||
@ -436,11 +463,12 @@ function returnWiList(ar) {
|
||||
var list = [];
|
||||
var i;
|
||||
for(i=0; i<ar.length; i++) {
|
||||
var ob = {"key": "", "keysecondary": "", "content": "", "num": ar[i], "selective": false};
|
||||
var ob = {"key": "", "keysecondary": "", "content": "", "num": ar[i], "selective": false, "constant": false};
|
||||
ob.selective = $("#wikeyprimary"+ar[i]).css("display") != "none"
|
||||
ob.key = ob.selective ? $("#wikeyprimary"+ar[i]).val() : $("#wikey"+ar[i]).val();
|
||||
ob.keysecondary = $("#wikeysecondary"+ar[i]).val()
|
||||
ob.content = $("#wientry"+ar[i]).val();
|
||||
ob.constant = $("#constant-key-"+ar[i]).hasClass("constant-key-icon-enabled");
|
||||
list.push(ob);
|
||||
}
|
||||
socket.send({'cmd': 'sendwilist', 'data': list});
|
||||
@ -1102,11 +1130,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();
|
||||
});
|
||||
|
@ -507,6 +507,54 @@ chunk, chunk * {
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
.icon-container {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.constant-key-icon {
|
||||
position: absolute !important;
|
||||
top: 5px !important;
|
||||
right: 5px !important;
|
||||
z-index: 1;
|
||||
transform: rotate(20deg);
|
||||
-moz-transform: rotate(20deg);
|
||||
-webkit-transform: rotate(20deg);
|
||||
-ms-transform: rotate(20deg);
|
||||
-o-transform: rotate(20deg);
|
||||
opacity: 0%;
|
||||
}
|
||||
|
||||
*:hover > .constant-key-icon {
|
||||
opacity: 40%;
|
||||
}
|
||||
|
||||
.constant-key-icon:hover {
|
||||
opacity: 65%;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.constant-key-icon-enabled {
|
||||
color: #3bf723;
|
||||
opacity: 65%
|
||||
}
|
||||
|
||||
*:hover > .constant-key-icon-enabled {
|
||||
opacity: 65%;
|
||||
}
|
||||
|
||||
.constant-key-icon-enabled:hover {
|
||||
opacity: 100%
|
||||
}
|
||||
|
||||
.constant-key-icon-clickthrough {
|
||||
opacity: 0% !important;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.constant-key-icon-clickthrough.constant-key-icon-enabled {
|
||||
opacity: 35% !important;
|
||||
}
|
||||
|
||||
.loadlistheader {
|
||||
padding-left: 10px;
|
||||
display: grid;
|
||||
|
24
static/open-iconic-bootstrap.min.css
vendored
Normal file
24
static/open-iconic-bootstrap.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
BIN
static/open-iconic.woff
Normal file
BIN
static/open-iconic.woff
Normal file
Binary file not shown.
@ -13,6 +13,7 @@
|
||||
<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/open-iconic-bootstrap.min.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
|
Loading…
x
Reference in New Issue
Block a user