Merge pull request #122 from VE-FORBRYDERNE/settings

This commit is contained in:
henk717
2022-04-27 00:49:01 +02:00
committed by GitHub
4 changed files with 94 additions and 43 deletions

View File

@@ -780,6 +780,7 @@ parser.add_argument("--remote", action='store_true', help="Optimizes KoboldAI fo
parser.add_argument("--ngrok", action='store_true', help="Optimizes KoboldAI for Remote Play using Ngrok") parser.add_argument("--ngrok", action='store_true', help="Optimizes KoboldAI for Remote Play using Ngrok")
parser.add_argument("--localtunnel", action='store_true', help="Optimizes KoboldAI for Remote Play using Localtunnel") parser.add_argument("--localtunnel", action='store_true', help="Optimizes KoboldAI for Remote Play using Localtunnel")
parser.add_argument("--host", action='store_true', help="Optimizes KoboldAI for Remote Play without using a proxy service") parser.add_argument("--host", action='store_true', help="Optimizes KoboldAI for Remote Play without using a proxy service")
parser.add_argument("--port", type=int, help="Specify the port on which the application will be joinable")
parser.add_argument("--model", help="Specify the Model Type to skip the Menu") parser.add_argument("--model", help="Specify the Model Type to skip the Menu")
parser.add_argument("--path", help="Specify the Path for local models (For model NeoCustom or GPT2Custom)") parser.add_argument("--path", help="Specify the Path for local models (For model NeoCustom or GPT2Custom)")
parser.add_argument("--cpu", action='store_true', help="By default unattended launches are on the GPU use this option to force CPU usage.") parser.add_argument("--cpu", action='store_true', help="By default unattended launches are on the GPU use this option to force CPU usage.")
@@ -5325,15 +5326,16 @@ def send_debug():
#==================================================================# #==================================================================#
print("", end="", flush=True) print("", end="", flush=True)
if __name__ == "__main__": if __name__ == "__main__":
port = args.port if "port" in args and args.port is not None else 5000
print("{0}\nStarting webserver...{1}".format(colors.GREEN, colors.END), flush=True) print("{0}\nStarting webserver...{1}".format(colors.GREEN, colors.END), flush=True)
# Start Flask/SocketIO (Blocking, so this must be last method!) # Start Flask/SocketIO (Blocking, so this must be last method!)
#socketio.run(app, host='0.0.0.0', port=5000) #socketio.run(app, host='0.0.0.0', port=port)
if(vars.host): if(vars.host):
if(args.localtunnel): if(args.localtunnel):
import subprocess, shutil import subprocess, shutil
localtunnel = subprocess.Popen([shutil.which('lt'), '-p', '5000', 'http'], stdout=subprocess.PIPE) localtunnel = subprocess.Popen([shutil.which('lt'), '-p', str(port), 'http'], stdout=subprocess.PIPE)
attempts = 0 attempts = 0
while attempts < 10: while attempts < 10:
try: try:
@@ -5347,30 +5349,32 @@ if __name__ == "__main__":
if attempts == 10: if attempts == 10:
print("LocalTunnel could not be created, falling back to cloudflare...") print("LocalTunnel could not be created, falling back to cloudflare...")
from flask_cloudflared import _run_cloudflared from flask_cloudflared import _run_cloudflared
cloudflare = _run_cloudflared(5000) cloudflare = _run_cloudflared(port)
elif(args.ngrok): elif(args.ngrok):
from flask_ngrok import _run_ngrok from flask_ngrok import _run_ngrok
cloudflare = _run_ngrok() cloudflare = _run_ngrok()
elif(args.remote): elif(args.remote):
from flask_cloudflared import _run_cloudflared from flask_cloudflared import _run_cloudflared
cloudflare = _run_cloudflared(5000) cloudflare = _run_cloudflared(port)
if(args.localtunnel or args.ngrok or args.remote): if(args.localtunnel or args.ngrok or args.remote):
with open('cloudflare.log', 'w') as cloudflarelog: with open('cloudflare.log', 'w') as cloudflarelog:
cloudflarelog.write("KoboldAI has finished loading and is available at the following link : " + cloudflare) cloudflarelog.write("KoboldAI has finished loading and is available at the following link : " + cloudflare)
print(format(colors.GREEN) + "KoboldAI has finished loading and is available at the following link : " + cloudflare + format(colors.END)) print(format(colors.GREEN) + "KoboldAI has finished loading and is available at the following link : " + cloudflare + format(colors.END))
else: else:
print("{0}Webserver has started, you can now connect to this machine at port 5000{1}".format(colors.GREEN, colors.END)) print("{0}Webserver has started, you can now connect to this machine at port {1}{2}"
.format(colors.GREEN, port, colors.END))
vars.serverstarted = True vars.serverstarted = True
socketio.run(app, host='0.0.0.0', port=5000) socketio.run(app, host='0.0.0.0', port=port)
else: else:
import webbrowser import webbrowser
webbrowser.open_new('http://localhost:5000') webbrowser.open_new('http://localhost:{0}'.format(port))
print("{0}Server started!\nYou may now connect with a browser at http://127.0.0.1:5000/{1}".format(colors.GREEN, colors.END)) print("{0}Server started!\nYou may now connect with a browser at http://127.0.0.1:{1}/{2}"
.format(colors.GREEN, port, colors.END))
vars.serverstarted = True vars.serverstarted = True
if args.unblock: if args.unblock:
socketio.run(app, port=5000, host='0.0.0.0') socketio.run(app, port=port, host='0.0.0.0')
else: else:
socketio.run(app, port=5000) socketio.run(app, port=port)
else: else:
print("{0}\nServer started in WSGI mode!{1}".format(colors.GREEN, colors.END), flush=True) print("{0}\nServer started in WSGI mode!{1}".format(colors.GREEN, colors.END), flush=True)

View File

@@ -118,10 +118,33 @@ var adventure = false;
// Chatmode // Chatmode
var chatmode = false; var chatmode = false;
var sliders_throttle = getThrottle(200);
//=================================================================// //=================================================================//
// METHODS // METHODS
//=================================================================// //=================================================================//
/**
* Returns a function that will automatically wait for X ms before executing the callback
* The timer is reset each time the returned function is called
* Useful for methods where something is overridden too fast
* @param ms milliseconds to wait before executing the callback
* @return {(function(*): void)|*} function that takes the ms to wait and a callback to execute after the timer
*/
function getThrottle(ms) {
var timer = {};
return function (id, callback) {
if (timer[id]) {
clearTimeout(timer[id]);
}
timer[id] = setTimeout(function () {
callback();
delete timer[id];
}, ms);
}
}
function addSetting(ob) { function addSetting(ob) {
// Add setting block to Settings Menu // Add setting block to Settings Menu
if(ob.uitype == "slider"){ if(ob.uitype == "slider"){
@@ -130,9 +153,7 @@ function addSetting(ob) {
<div class=\"justifyleft\">\ <div class=\"justifyleft\">\
"+ob.label+" <span class=\"helpicon\">?<span class=\"helptext\">"+ob.tooltip+"</span></span>\ "+ob.label+" <span class=\"helpicon\">?<span class=\"helptext\">"+ob.tooltip+"</span></span>\
</div>\ </div>\
<div class=\"justifyright\" id=\""+ob.id+"cur\">\ <input inputmode=\""+(ob.unit === "float" ? "decimal" : "numeric")+"\" class=\"justifyright flex-push-right\" id=\""+ob.id+"cur\" value=\""+ob.default+"\">\
"+ob.default+"\
</div>\
</div>\ </div>\
<div>\ <div>\
<input type=\"range\" class=\"form-range airange\" min=\""+ob.min+"\" max=\""+ob.max+"\" step=\""+ob.step+"\" id=\""+ob.id+"\">\ <input type=\"range\" class=\"form-range airange\" min=\""+ob.min+"\" max=\""+ob.max+"\" step=\""+ob.step+"\" id=\""+ob.id+"\">\
@@ -152,8 +173,23 @@ function addSetting(ob) {
window["setting_"+ob.id] = refin; // Is this still needed? window["setting_"+ob.id] = refin; // Is this still needed?
window["label_"+ob.id] = reflb; // Is this still needed? window["label_"+ob.id] = reflb; // Is this still needed?
// Add event function to input // Add event function to input
refin.on("input", function () { var send = function () {
socket.send({'cmd': $(this).attr('id'), 'data': $(this).val()}); var that = refin;
sliders_throttle(ob.id, function () {
socket.send({'cmd': $(that).attr('id'), 'data': $(that).val()});
refin.val(parseFloat($(that).val()));
reflb.html($(that).val());
});
}
refin.on("input", send);
reflb.on("change", function (event) {
var value = (ob.unit === "float" ? parseFloat : parseInt)(event.target.value);
if(Number.isNaN(value) || value > ob.max || value < ob.min) {
event.target.value = refin.val();
return;
}
refin.val(value);
send();
}); });
} else if(ob.uitype == "toggle"){ } else if(ob.uitype == "toggle"){
settings_menu.append("<div class=\"settingitem\">\ settings_menu.append("<div class=\"settingitem\">\
@@ -2026,80 +2062,80 @@ $(document).ready(function(){
} else if(msg.cmd == "updatetemp") { } else if(msg.cmd == "updatetemp") {
// Send current temp value to input // Send current temp value to input
$("#settemp").val(parseFloat(msg.data)); $("#settemp").val(parseFloat(msg.data));
$("#settempcur").html(msg.data); $("#settempcur").val(msg.data);
} else if(msg.cmd == "updatetopp") { } else if(msg.cmd == "updatetopp") {
// Send current top p value to input // Send current top p value to input
$("#settopp").val(parseFloat(msg.data)); $("#settopp").val(parseFloat(msg.data));
$("#settoppcur").html(msg.data); $("#settoppcur").val(msg.data);
} else if(msg.cmd == "updatetopk") { } else if(msg.cmd == "updatetopk") {
// Send current top k value to input // Send current top k value to input
$("#settopk").val(parseFloat(msg.data)); $("#settopk").val(parseFloat(msg.data));
$("#settopkcur").html(msg.data); $("#settopkcur").val(msg.data);
} else if(msg.cmd == "updatetfs") { } else if(msg.cmd == "updatetfs") {
// Send current tfs value to input // Send current tfs value to input
$("#settfs").val(parseFloat(msg.data)); $("#settfs").val(parseFloat(msg.data));
$("#settfscur").html(msg.data); $("#settfscur").val(msg.data);
} else if(msg.cmd == "updatetypical") { } else if(msg.cmd == "updatetypical") {
// Send current typical value to input // Send current typical value to input
$("#settypical").val(parseFloat(msg.data)); $("#settypical").val(parseFloat(msg.data));
$("#settypicalcur").html(msg.data); $("#settypicalcur").val(msg.data);
} else if(msg.cmd == "updatereppen") { } else if(msg.cmd == "updatereppen") {
// Send current rep pen value to input // Send current rep pen value to input
$("#setreppen").val(parseFloat(msg.data)); $("#setreppen").val(parseFloat(msg.data));
$("#setreppencur").html(msg.data); $("#setreppencur").val(msg.data);
} else if(msg.cmd == "updatereppenslope") { } else if(msg.cmd == "updatereppenslope") {
// Send current rep pen value to input // Send current rep pen value to input
$("#setreppenslope").val(parseFloat(msg.data)); $("#setreppenslope").val(parseFloat(msg.data));
$("#setreppenslopecur").html(msg.data); $("#setreppenslopecur").val(msg.data);
} else if(msg.cmd == "updatereppenrange") { } else if(msg.cmd == "updatereppenrange") {
// Send current rep pen value to input // Send current rep pen value to input
$("#setreppenrange").val(parseFloat(msg.data)); $("#setreppenrange").val(parseFloat(msg.data));
$("#setreppenrangecur").html(msg.data); $("#setreppenrangecur").val(msg.data);
} else if(msg.cmd == "updateoutlen") { } else if(msg.cmd == "updateoutlen") {
// Send current output amt value to input // Send current output amt value to input
$("#setoutput").val(parseInt(msg.data)); $("#setoutput").val(parseInt(msg.data));
$("#setoutputcur").html(msg.data); $("#setoutputcur").val(msg.data);
} else if(msg.cmd == "updatetknmax") { } else if(msg.cmd == "updatetknmax") {
// Send current max tokens value to input // Send current max tokens value to input
$("#settknmax").val(parseInt(msg.data)); $("#settknmax").val(parseInt(msg.data));
$("#settknmaxcur").html(msg.data); $("#settknmaxcur").val(msg.data);
} else if(msg.cmd == "updateikgen") { } else if(msg.cmd == "updateikgen") {
// Send current max tokens value to input // Send current max tokens value to input
$("#setikgen").val(parseInt(msg.data)); $("#setikgen").val(parseInt(msg.data));
$("#setikgencur").html(msg.data); $("#setikgencur").val(msg.data);
} else if(msg.cmd == "setlabeltemp") { } else if(msg.cmd == "setlabeltemp") {
// Update setting label with value from server // Update setting label with value from server
$("#settempcur").html(msg.data); $("#settempcur").val(msg.data);
} else if(msg.cmd == "setlabeltopp") { } else if(msg.cmd == "setlabeltopp") {
// Update setting label with value from server // Update setting label with value from server
$("#settoppcur").html(msg.data); $("#settoppcur").val(msg.data);
} else if(msg.cmd == "setlabeltopk") { } else if(msg.cmd == "setlabeltopk") {
// Update setting label with value from server // Update setting label with value from server
$("#settopkcur").html(msg.data); $("#settopkcur").val(msg.data);
} else if(msg.cmd == "setlabeltfs") { } else if(msg.cmd == "setlabeltfs") {
// Update setting label with value from server // Update setting label with value from server
$("#settfscur").html(msg.data); $("#settfscur").val(msg.data);
} else if(msg.cmd == "setlabeltypical") { } else if(msg.cmd == "setlabeltypical") {
// Update setting label with value from server // Update setting label with value from server
$("#settypicalcur").html(msg.data); $("#settypicalcur").val(msg.data);
} else if(msg.cmd == "setlabelreppen") { } else if(msg.cmd == "setlabelreppen") {
// Update setting label with value from server // Update setting label with value from server
$("#setreppencur").html(msg.data); $("#setreppencur").val(msg.data);
} else if(msg.cmd == "setlabelreppenslope") { } else if(msg.cmd == "setlabelreppenslope") {
// Update setting label with value from server // Update setting label with value from server
$("#setreppenslopecur").html(msg.data); $("#setreppenslopecur").val(msg.data);
} else if(msg.cmd == "setlabelreppenrange") { } else if(msg.cmd == "setlabelreppenrange") {
// Update setting label with value from server // Update setting label with value from server
$("#setreppenrangecur").html(msg.data); $("#setreppenrangecur").val(msg.data);
} else if(msg.cmd == "setlabeloutput") { } else if(msg.cmd == "setlabeloutput") {
// Update setting label with value from server // Update setting label with value from server
$("#setoutputcur").html(msg.data); $("#setoutputcur").val(msg.data);
} else if(msg.cmd == "setlabeltknmax") { } else if(msg.cmd == "setlabeltknmax") {
// Update setting label with value from server // Update setting label with value from server
$("#settknmaxcur").html(msg.data); $("#settknmaxcur").val(msg.data);
} else if(msg.cmd == "setlabelikgen") { } else if(msg.cmd == "setlabelikgen") {
// Update setting label with value from server // Update setting label with value from server
$("#setikgencur").html(msg.data); $("#setikgencur").val(msg.data);
} else if(msg.cmd == "updateanotedepth") { } else if(msg.cmd == "updateanotedepth") {
// Send current Author's Note depth value to input // Send current Author's Note depth value to input
anote_slider.val(parseInt(msg.data)); anote_slider.val(parseInt(msg.data));

View File

@@ -22,6 +22,17 @@ chunk.editing, chunk.editing * {
font-style: normal !important; font-style: normal !important;
} }
.settinglabel input {
width: 5ch;
background-color: inherit;
border: none;
outline: none;
}
.settinglabel input:focus {
color: #cdf;
}
#gametext, chunk, chunk * { #gametext, chunk, chunk * {
outline: 0px solid transparent; outline: 0px solid transparent;
} }
@@ -1273,8 +1284,8 @@ body.connected .popupfooter, .popupfooter.always-available {
.settinglabel { .settinglabel {
color: #ffffff; color: #ffffff;
display: grid; display: flex;
grid-template-columns: 80% 20%; flex-flow: wrap;
} }
.settingminmax { .settingminmax {

View File

@@ -9,7 +9,7 @@
<link rel="stylesheet" href="static/bootstrap.min.css"> <link rel="stylesheet" href="static/bootstrap.min.css">
<link rel="stylesheet" href="static/bootstrap-toggle.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/open-iconic-bootstrap.min.css">
<link rel="stylesheet" href="static/custom.css?ver=1.17"> <link rel="stylesheet" href="static/custom.css?ver=1.17a">
<script src="static/jquery-3.6.0.min.js"></script> <script src="static/jquery-3.6.0.min.js"></script>
<script src="static/jquery-ui.sortable.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.min.js"></script>
<script src="static/bootstrap-toggle.min.js"></script> <script src="static/bootstrap-toggle.min.js"></script>
<script src="static/rangy-core.min.js"></script> <script src="static/rangy-core.min.js"></script>
<script src="static/application.js?ver=1.17b"></script> <script src="static/application.js?ver=1.17d"></script>
</head> </head>
<body> <body>
<input type="file" id="remote-save-select" accept="application/json" style="display:none"> <input type="file" id="remote-save-select" accept="application/json" style="display:none">