Skip to content

Commit

Permalink
fixed some incorrect protocol prefix for localhost
Browse files Browse the repository at this point in the history
  • Loading branch information
LostRuins committed Aug 29, 2024
1 parent 5f360f6 commit 0f9968e
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions koboldcpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1612,7 +1612,7 @@ def secure_endpoint(self): #returns false if auth fails. caller should exit
return True

def noscript_webui(self):
global modelbusy
global modelbusy, sslvalid
import html
import urllib.parse as urlparse
parsed_url = urlparse.urlparse(self.path)
Expand All @@ -1636,9 +1636,10 @@ def noscript_webui(self):
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"])
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -3578,21 +3580,22 @@ 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 = ""
tunnelrawlog = ""
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
Expand Down

0 comments on commit 0f9968e

Please sign in to comment.