Skip to content

Commit 3912482

Browse files
committed
wip multiplayer
1 parent e7897f3 commit 3912482

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

koboldcpp.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
runmode_untouched = True
6565
modelfile_extracted_meta = None
6666
importvars_in_progress = False
67+
has_multiplayer = False
6768
preloaded_story = None
6869
chatcompl_adapter = None
6970
embedded_kailite = None
@@ -1792,7 +1793,7 @@ def noscript_webui(self):
17921793

17931794
def do_GET(self):
17941795
global embedded_kailite, embedded_kcpp_docs, embedded_kcpp_sdui
1795-
global maxctx, maxhordelen, friendlymodelname, KcppVersion, totalgens, preloaded_story, exitcounter, currentusergenkey, friendlysdmodelname, fullsdmodelpath, mmprojpath, password, fullwhispermodelpath
1796+
global has_multiplayer, maxctx, maxhordelen, friendlymodelname, KcppVersion, totalgens, preloaded_story, exitcounter, currentusergenkey, friendlysdmodelname, fullsdmodelpath, mmprojpath, password, fullwhispermodelpath
17961797
self.path = self.path.rstrip('/')
17971798
response_body = None
17981799
content_type = 'application/json'
@@ -1849,7 +1850,7 @@ def do_GET(self):
18491850
has_vision = (mmprojpath!="")
18501851
has_password = (password!="")
18511852
has_whisper = (fullwhispermodelpath!="")
1852-
response_body = (json.dumps({"result":"KoboldCpp","version":KcppVersion, "protected":has_password ,"txt2img":has_txt2img,"vision":has_vision,"transcribe":has_whisper}).encode())
1853+
response_body = (json.dumps({"result":"KoboldCpp","version":KcppVersion, "protected":has_password ,"txt2img":has_txt2img,"vision":has_vision,"transcribe":has_whisper,"multiplayer":has_multiplayer}).encode())
18531854

18541855
elif self.path.endswith(('/api/extra/perf')):
18551856
global last_req_time, start_time
@@ -2516,6 +2517,7 @@ def hide_tooltip(event):
25162517
port_var = ctk.StringVar(value=defaultport)
25172518
host_var = ctk.StringVar(value="")
25182519
multiuser_var = ctk.IntVar(value=1)
2520+
multiplayer_var = ctk.IntVar(value=has_multiplayer)
25192521
horde_name_var = ctk.StringVar(value="koboldcpp")
25202522
horde_gen_var = ctk.StringVar(value=maxhordelen)
25212523
horde_context_var = ctk.StringVar(value=maxhordectx)
@@ -3017,10 +3019,11 @@ def pickpremadetemplate():
30173019
makecheckbox(network_tab, "Remote Tunnel", remotetunnel, 3, 1,tooltiptxt="Creates a trycloudflare tunnel.\nAllows you to access koboldcpp from other devices over an internet URL.")
30183020
makecheckbox(network_tab, "Quiet Mode", quietmode, 4,tooltiptxt="Prevents all generation related terminal output from being displayed.")
30193021
makecheckbox(network_tab, "NoCertify Mode (Insecure)", nocertifymode, 4, 1,tooltiptxt="Allows insecure SSL connections. Use this if you have cert errors and need to bypass certificate restrictions.")
3022+
makecheckbox(network_tab, "Shared Multiplayer", multiplayer_var, 5,tooltiptxt="Hosts a shared multiplayer session that others can join.")
30203023

3021-
makefileentry(network_tab, "SSL Cert:", "Select SSL cert.pem file",ssl_cert_var, 5, width=200 ,filetypes=[("Unencrypted Certificate PEM", "*.pem")], singlerow=True, singlecol=False,tooltiptxt="Select your unencrypted .pem SSL certificate file for https.\nCan be generated with OpenSSL.")
3022-
makefileentry(network_tab, "SSL Key:", "Select SSL key.pem file", ssl_key_var, 7, width=200, filetypes=[("Unencrypted Key PEM", "*.pem")], singlerow=True, singlecol=False, tooltiptxt="Select your unencrypted .pem SSL key file for https.\nCan be generated with OpenSSL.")
3023-
makelabelentry(network_tab, "Password: ", password_var, 8, 200,tooltip="Enter a password required to use this instance.\nThis key will be required for all text endpoints.\nImage endpoints are not secured.")
3024+
makefileentry(network_tab, "SSL Cert:", "Select SSL cert.pem file",ssl_cert_var, 7, width=200 ,filetypes=[("Unencrypted Certificate PEM", "*.pem")], singlerow=True, singlecol=False,tooltiptxt="Select your unencrypted .pem SSL certificate file for https.\nCan be generated with OpenSSL.")
3025+
makefileentry(network_tab, "SSL Key:", "Select SSL key.pem file", ssl_key_var, 9, width=200, filetypes=[("Unencrypted Key PEM", "*.pem")], singlerow=True, singlecol=False, tooltiptxt="Select your unencrypted .pem SSL key file for https.\nCan be generated with OpenSSL.")
3026+
makelabelentry(network_tab, "Password: ", password_var, 10, 200,tooltip="Enter a password required to use this instance.\nThis key will be required for all text endpoints.\nImage endpoints are not secured.")
30243027

30253028
# Horde Tab
30263029
horde_tab = tabcontent["Horde Worker"]
@@ -3254,6 +3257,7 @@ def export_vars():
32543257
args.port_param = defaultport if port_var.get()=="" else int(port_var.get())
32553258
args.host = host_var.get()
32563259
args.multiuser = multiuser_var.get()
3260+
args.multiplayer = (multiplayer_var.get()==1)
32573261

32583262
if usehorde_var.get() != 0:
32593263
args.hordemodelname = horde_name_var.get()
@@ -3420,6 +3424,7 @@ def import_vars(dict):
34203424
port_var.set(dict["port_param"] if ("port_param" in dict and dict["port_param"]) else defaultport)
34213425
host_var.set(dict["host"] if ("host" in dict and dict["host"]) else "")
34223426
multiuser_var.set(dict["multiuser"] if ("multiuser" in dict) else 1)
3427+
multiplayer_var.set(dict["multiplayer"] if ("multiplayer" in dict) else 0)
34233428

34243429
horde_name_var.set(dict["hordemodelname"] if ("hordemodelname" in dict and dict["hordemodelname"]) else "koboldcpp")
34253430
horde_context_var.set(dict["hordemaxctx"] if ("hordemaxctx" in dict and dict["hordemaxctx"]) else maxhordectx)
@@ -4206,7 +4211,7 @@ def main(launch_args,start_server=True):
42064211
friendlymodelname = "koboldcpp/" + sanitize_string(newmdldisplayname)
42074212

42084213
# horde worker settings
4209-
global maxhordelen, maxhordectx, showdebug
4214+
global maxhordelen, maxhordectx, showdebug, has_multiplayer
42104215
if args.hordemodelname and args.hordemodelname!="":
42114216
friendlymodelname = args.hordemodelname
42124217
if args.debugmode == 1:
@@ -4224,6 +4229,9 @@ def main(launch_args,start_server=True):
42244229
if args.debugmode != 1:
42254230
showdebug = False
42264231

4232+
if args.multiplayer:
4233+
has_multiplayer = True
4234+
42274235
if args.highpriority:
42284236
print("Setting process to Higher Priority - Use Caution")
42294237
try:
@@ -4667,6 +4675,7 @@ def range_checker(arg: str):
46674675
advparser.add_argument("--prompt", metavar=('[prompt]'), help="Passing a prompt string triggers a direct inference, loading the model, outputs the response to stdout and exits. Can be used alone or with benchmark.", type=str, default="")
46684676
advparser.add_argument("--promptlimit", help="Sets the maximum number of generated tokens, usable only with --prompt or --benchmark",metavar=('[token limit]'), type=int, default=100)
46694677
advparser.add_argument("--multiuser", help="Runs in multiuser mode, which queues incoming requests instead of blocking them.", metavar=('limit'), nargs='?', const=1, type=int, default=1)
4678+
advparser.add_argument("--multiplayer", help="Hosts a shared multiplayer session that others can join.", action='store_true')
46704679
advparser.add_argument("--remotetunnel", help="Uses Cloudflare to create a remote tunnel, allowing you to access koboldcpp remotely over the internet even behind a firewall.", action='store_true')
46714680
advparser.add_argument("--highpriority", help="Experimental flag. If set, increases the process CPU priority, potentially speeding up generation. Use caution.", action='store_true')
46724681
advparser.add_argument("--foreground", help="Windows only. Sends the terminal to the foreground every time a new prompt is generated. This helps avoid some idle slowdown issues.", action='store_true')

0 commit comments

Comments
 (0)