From 0f9968ef642bd6f174f731c3cd508b27bdab4cbb Mon Sep 17 00:00:00 2001 From: Concedo <39025047+LostRuins@users.noreply.github.com> Date: Thu, 29 Aug 2024 10:37:43 +0800 Subject: [PATCH] fixed some incorrect protocol prefix for localhost --- koboldcpp.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/koboldcpp.py b/koboldcpp.py index f6a4528b7..dde6519be 100644 --- a/koboldcpp.py +++ b/koboldcpp.py @@ -1612,7 +1612,7 @@ class ServerRequestHandler(http.server.SimpleHTTPRequestHandler): return True def noscript_webui(self): - global modelbusy + global modelbusy, sslvalid import html import urllib.parse as urlparse parsed_url = urlparse.urlparse(self.path) @@ -1636,9 +1636,10 @@ class ServerRequestHandler(http.server.SimpleHTTPRequestHandler): else: if max_length>512: max_length = 512 - epurl = f"http://localhost:{args.port}" + httpsaffix = ("https" if sslvalid else "http") + epurl = f"{httpsaffix}://localhost:{args.port}" if args.host!="": - epurl = f"http://{args.host}:{args.port}" + epurl = f"{httpsaffix}://{args.host}:{args.port}" gen_payload = {"prompt": prompt,"max_length": max_length,"temperature": temperature,"prompt": prompt,"top_k": top_k,"top_p": top_p,"rep_pen": rep_pen,"ban_eos_token":ban_eos_token} respjson = make_url_request(f'{epurl}/api/v1/generate', gen_payload) reply = html.escape(respjson["results"][0]["text"]) @@ -3376,10 +3377,11 @@ def make_url_request(url, data, method='POST', headers={}): def run_horde_worker(args, api_key, worker_name): from datetime import datetime import random - global friendlymodelname, maxhordectx, maxhordelen, exitcounter, punishcounter, modelbusy, session_starttime - epurl = f"http://localhost:{args.port}" + global friendlymodelname, maxhordectx, maxhordelen, exitcounter, punishcounter, modelbusy, session_starttime, sslvalid + httpsaffix = ("https" if sslvalid else "http") + epurl = f"{httpsaffix}://localhost:{args.port}" if args.host!="": - epurl = f"http://{args.host}:{args.port}" + epurl = f"{httpsaffix}://{args.host}:{args.port}" def submit_completed_generation(url, jobid, sessionstart, submit_dict): global exitcounter, punishcounter, session_kudos_earned, session_jobs, rewardcounter @@ -3578,7 +3580,8 @@ def setuptunnel(has_sd): # It should work out of the box on both linux and windows try: import subprocess, re - + global sslvalid + httpsaffix = ("https" if sslvalid else "http") def run_tunnel(): tunnelproc = None tunneloutput = "" @@ -3586,13 +3589,13 @@ def setuptunnel(has_sd): time.sleep(0.2) if os.name == 'nt': print("Starting Cloudflare Tunnel for Windows, please wait...", flush=True) - tunnelproc = subprocess.Popen(f"cloudflared.exe tunnel --url localhost:{args.port}", text=True, encoding='utf-8', shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE) + tunnelproc = subprocess.Popen(f"cloudflared.exe tunnel --url {httpsaffix}://localhost:{args.port}", text=True, encoding='utf-8', shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE) elif sys.platform=="darwin": print("Starting Cloudflare Tunnel for MacOS, please wait...", flush=True) - tunnelproc = subprocess.Popen(f"./cloudflared tunnel --url http://localhost:{args.port}", text=True, encoding='utf-8', shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE) + tunnelproc = subprocess.Popen(f"./cloudflared tunnel --url {httpsaffix}://localhost:{args.port}", text=True, encoding='utf-8', shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE) else: print("Starting Cloudflare Tunnel for Linux, please wait...", flush=True) - tunnelproc = subprocess.Popen(f"./cloudflared-linux-amd64 tunnel --url http://localhost:{args.port}", text=True, encoding='utf-8', shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE) + tunnelproc = subprocess.Popen(f"./cloudflared-linux-amd64 tunnel --url {httpsaffix}://localhost:{args.port}", text=True, encoding='utf-8', shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE) time.sleep(10) def tunnel_reader(): nonlocal tunnelproc,tunneloutput,tunnelrawlog