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("--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("--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("--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.")
@@ -5319,21 +5320,22 @@ def send_debug():
pass
emit('from_server', {'cmd': 'debug_info', 'data': debug_info}, broadcast=True)
#==================================================================#
# Final startup commands to launch Flask app
#==================================================================#
print("", end="", flush=True)
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)
# 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(args.localtunnel):
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
while attempts < 10:
try:
@@ -5347,30 +5349,32 @@ if __name__ == "__main__":
if attempts == 10:
print("LocalTunnel could not be created, falling back to cloudflare...")
from flask_cloudflared import _run_cloudflared
cloudflare = _run_cloudflared(5000)
cloudflare = _run_cloudflared(port)
elif(args.ngrok):
from flask_ngrok import _run_ngrok
cloudflare = _run_ngrok()
elif(args.remote):
from flask_cloudflared import _run_cloudflared
cloudflare = _run_cloudflared(5000)
cloudflare = _run_cloudflared(port)
if(args.localtunnel or args.ngrok or args.remote):
with open('cloudflare.log', 'w') as cloudflarelog:
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))
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
socketio.run(app, host='0.0.0.0', port=5000)
socketio.run(app, host='0.0.0.0', port=port)
else:
import webbrowser
webbrowser.open_new('http://localhost:5000')
print("{0}Server started!\nYou may now connect with a browser at http://127.0.0.1:5000/{1}".format(colors.GREEN, colors.END))
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:{1}/{2}"
.format(colors.GREEN, port, colors.END))
vars.serverstarted = True
if args.unblock:
socketio.run(app, port=5000, host='0.0.0.0')
socketio.run(app, port=port, host='0.0.0.0')
else:
socketio.run(app, port=5000)
socketio.run(app, port=port)
else:
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
var chatmode = false;
var sliders_throttle = getThrottle(200);
//=================================================================//
// 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) {
// Add setting block to Settings Menu
if(ob.uitype == "slider"){
@@ -130,9 +153,7 @@ function addSetting(ob) {
<div class=\"justifyleft\">\
"+ob.label+" <span class=\"helpicon\">?<span class=\"helptext\">"+ob.tooltip+"</span></span>\
</div>\
<div class=\"justifyright\" id=\""+ob.id+"cur\">\
"+ob.default+"\
</div>\
<input inputmode=\""+(ob.unit === "float" ? "decimal" : "numeric")+"\" class=\"justifyright flex-push-right\" id=\""+ob.id+"cur\" value=\""+ob.default+"\">\
</div>\
<div>\
<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["label_"+ob.id] = reflb; // Is this still needed?
// Add event function to input
refin.on("input", function () {
socket.send({'cmd': $(this).attr('id'), 'data': $(this).val()});
var send = function () {
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"){
settings_menu.append("<div class=\"settingitem\">\
@@ -2026,80 +2062,80 @@ $(document).ready(function(){
} else if(msg.cmd == "updatetemp") {
// Send current temp value to input
$("#settemp").val(parseFloat(msg.data));
$("#settempcur").html(msg.data);
$("#settempcur").val(msg.data);
} else if(msg.cmd == "updatetopp") {
// Send current top p value to input
$("#settopp").val(parseFloat(msg.data));
$("#settoppcur").html(msg.data);
$("#settoppcur").val(msg.data);
} else if(msg.cmd == "updatetopk") {
// Send current top k value to input
$("#settopk").val(parseFloat(msg.data));
$("#settopkcur").html(msg.data);
$("#settopkcur").val(msg.data);
} else if(msg.cmd == "updatetfs") {
// Send current tfs value to input
$("#settfs").val(parseFloat(msg.data));
$("#settfscur").html(msg.data);
$("#settfscur").val(msg.data);
} else if(msg.cmd == "updatetypical") {
// Send current typical value to input
$("#settypical").val(parseFloat(msg.data));
$("#settypicalcur").html(msg.data);
$("#settypicalcur").val(msg.data);
} else if(msg.cmd == "updatereppen") {
// Send current rep pen value to input
$("#setreppen").val(parseFloat(msg.data));
$("#setreppencur").html(msg.data);
$("#setreppencur").val(msg.data);
} else if(msg.cmd == "updatereppenslope") {
// Send current rep pen value to input
$("#setreppenslope").val(parseFloat(msg.data));
$("#setreppenslopecur").html(msg.data);
$("#setreppenslopecur").val(msg.data);
} else if(msg.cmd == "updatereppenrange") {
// Send current rep pen value to input
$("#setreppenrange").val(parseFloat(msg.data));
$("#setreppenrangecur").html(msg.data);
$("#setreppenrangecur").val(msg.data);
} else if(msg.cmd == "updateoutlen") {
// Send current output amt value to input
$("#setoutput").val(parseInt(msg.data));
$("#setoutputcur").html(msg.data);
$("#setoutputcur").val(msg.data);
} else if(msg.cmd == "updatetknmax") {
// Send current max tokens value to input
$("#settknmax").val(parseInt(msg.data));
$("#settknmaxcur").html(msg.data);
$("#settknmaxcur").val(msg.data);
} else if(msg.cmd == "updateikgen") {
// Send current max tokens value to input
$("#setikgen").val(parseInt(msg.data));
$("#setikgencur").html(msg.data);
$("#setikgencur").val(msg.data);
} else if(msg.cmd == "setlabeltemp") {
// Update setting label with value from server
$("#settempcur").html(msg.data);
$("#settempcur").val(msg.data);
} else if(msg.cmd == "setlabeltopp") {
// Update setting label with value from server
$("#settoppcur").html(msg.data);
$("#settoppcur").val(msg.data);
} else if(msg.cmd == "setlabeltopk") {
// Update setting label with value from server
$("#settopkcur").html(msg.data);
$("#settopkcur").val(msg.data);
} else if(msg.cmd == "setlabeltfs") {
// Update setting label with value from server
$("#settfscur").html(msg.data);
$("#settfscur").val(msg.data);
} else if(msg.cmd == "setlabeltypical") {
// Update setting label with value from server
$("#settypicalcur").html(msg.data);
$("#settypicalcur").val(msg.data);
} else if(msg.cmd == "setlabelreppen") {
// Update setting label with value from server
$("#setreppencur").html(msg.data);
$("#setreppencur").val(msg.data);
} else if(msg.cmd == "setlabelreppenslope") {
// Update setting label with value from server
$("#setreppenslopecur").html(msg.data);
$("#setreppenslopecur").val(msg.data);
} else if(msg.cmd == "setlabelreppenrange") {
// Update setting label with value from server
$("#setreppenrangecur").html(msg.data);
$("#setreppenrangecur").val(msg.data);
} else if(msg.cmd == "setlabeloutput") {
// Update setting label with value from server
$("#setoutputcur").html(msg.data);
$("#setoutputcur").val(msg.data);
} else if(msg.cmd == "setlabeltknmax") {
// Update setting label with value from server
$("#settknmaxcur").html(msg.data);
$("#settknmaxcur").val(msg.data);
} else if(msg.cmd == "setlabelikgen") {
// Update setting label with value from server
$("#setikgencur").html(msg.data);
$("#setikgencur").val(msg.data);
} else if(msg.cmd == "updateanotedepth") {
// Send current Author's Note depth value to input
anote_slider.val(parseInt(msg.data));

View File

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

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.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-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.17b"></script>
<script src="static/application.js?ver=1.17d"></script>
</head>
<body>
<input type="file" id="remote-save-select" accept="application/json" style="display:none">