mirror of
https://github.com/KoboldAI/KoboldAI-Client.git
synced 2025-06-05 21:59:24 +02:00
renamed vars to koboldai_vars
This commit is contained in:
38
utils.py
38
utils.py
@@ -21,7 +21,7 @@ try:
|
||||
except ImportError:
|
||||
HAS_ACCELERATE = False
|
||||
|
||||
vars = None
|
||||
koboldai_vars = None
|
||||
num_shards: Optional[int] = None
|
||||
current_shard = 0
|
||||
from_pretrained_model_name = ""
|
||||
@@ -93,8 +93,8 @@ def replaceblanklines(txt):
|
||||
#==================================================================#
|
||||
#
|
||||
#==================================================================#
|
||||
def removespecialchars(txt, vars=None):
|
||||
if vars is None or vars.actionmode == 0:
|
||||
def removespecialchars(txt, koboldai_vars=None):
|
||||
if koboldai_vars is None or koboldai_vars.actionmode == 0:
|
||||
txt = re.sub(r"[#/@%<>{}+=~|\^]", "", txt)
|
||||
else:
|
||||
txt = re.sub(r"[#/@%{}+=~|\^]", "", txt)
|
||||
@@ -103,38 +103,38 @@ def removespecialchars(txt, vars=None):
|
||||
#==================================================================#
|
||||
# If the next action follows a sentence closure, add a space
|
||||
#==================================================================#
|
||||
def addsentencespacing(txt, vars):
|
||||
def addsentencespacing(txt, koboldai_vars):
|
||||
# Don't add sentence spacing if submission is empty or starts with whitespace
|
||||
if(len(txt) == 0 or len(txt) != len(txt.lstrip())):
|
||||
return txt
|
||||
# Get last character of last action
|
||||
if(len(vars.actions) > 0):
|
||||
if(len(vars.actions[vars.actions.get_last_key()]) > 0):
|
||||
action = vars.actions[vars.actions.get_last_key()]
|
||||
if(len(koboldai_vars.actions) > 0):
|
||||
if(len(koboldai_vars.actions[koboldai_vars.actions.get_last_key()]) > 0):
|
||||
action = koboldai_vars.actions[koboldai_vars.actions.get_last_key()]
|
||||
lastchar = action[-1] if len(action) else ""
|
||||
else:
|
||||
# Last action is blank, this should never happen, but
|
||||
# since it did let's bail out.
|
||||
return txt
|
||||
else:
|
||||
action = vars.prompt
|
||||
action = koboldai_vars.prompt
|
||||
lastchar = action[-1] if len(action) else ""
|
||||
if(lastchar != " "):
|
||||
txt = " " + txt
|
||||
return txt
|
||||
|
||||
def singlelineprocessing(txt, vars):
|
||||
txt = vars.regex_sl.sub('', txt)
|
||||
if(len(vars.actions) > 0):
|
||||
if(len(vars.actions[vars.actions.get_last_key()]) > 0):
|
||||
action = vars.actions[vars.actions.get_last_key()]
|
||||
def singlelineprocessing(txt, koboldai_vars):
|
||||
txt = koboldai_vars.regex_sl.sub('', txt)
|
||||
if(len(koboldai_vars.actions) > 0):
|
||||
if(len(koboldai_vars.actions[koboldai_vars.actions.get_last_key()]) > 0):
|
||||
action = koboldai_vars.actions[koboldai_vars.actions.get_last_key()]
|
||||
lastchar = action[-1] if len(action) else ""
|
||||
else:
|
||||
# Last action is blank, this should never happen, but
|
||||
# since it did let's bail out.
|
||||
return txt
|
||||
else:
|
||||
action = vars.prompt
|
||||
action = koboldai_vars.prompt
|
||||
lastchar = action[-1] if len(action) else ""
|
||||
if(lastchar != "\n"):
|
||||
txt = txt + "\n"
|
||||
@@ -152,14 +152,14 @@ def cleanfilename(filename):
|
||||
# Newline substitution for fairseq models
|
||||
#==================================================================#
|
||||
def encodenewlines(txt):
|
||||
if(vars.newlinemode == "s"):
|
||||
if(koboldai_vars.newlinemode == "s"):
|
||||
return txt.replace('\n', "</s>")
|
||||
return txt
|
||||
|
||||
def decodenewlines(txt):
|
||||
if(vars.newlinemode == "s"):
|
||||
if(koboldai_vars.newlinemode == "s"):
|
||||
return txt.replace("</s>", '\n')
|
||||
if(vars.newlinemode == "ns"):
|
||||
if(koboldai_vars.newlinemode == "ns"):
|
||||
return txt.replace("</s>", '')
|
||||
return txt
|
||||
|
||||
@@ -265,9 +265,9 @@ def aria2_hook(pretrained_model_name_or_path: str, force_download=False, cache_d
|
||||
with tempfile.NamedTemporaryFile("w+b", delete=False) as f:
|
||||
f.write(aria2_config)
|
||||
f.flush()
|
||||
p = subprocess.Popen(["aria2c", "-x", "10", "-s", "10", "-j", "10", "--enable-rpc=true", f"--rpc-secret={secret}", "--rpc-listen-port", str(vars.aria2_port), "--disable-ipv6", "--file-allocation=trunc", "--allow-overwrite", "--auto-file-renaming=false", "-d", _cache_dir, "-i", f.name, "-U", transformers.file_utils.http_user_agent(user_agent)] + (["-c"] if not force_download else []) + ([f"--header='Authorization: Bearer {token}'"] if use_auth_token else []), stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
p = subprocess.Popen(["aria2c", "-x", "10", "-s", "10", "-j", "10", "--enable-rpc=true", f"--rpc-secret={secret}", "--rpc-listen-port", str(koboldai_vars.aria2_port), "--disable-ipv6", "--file-allocation=trunc", "--allow-overwrite", "--auto-file-renaming=false", "-d", _cache_dir, "-i", f.name, "-U", transformers.file_utils.http_user_agent(user_agent)] + (["-c"] if not force_download else []) + ([f"--header='Authorization: Bearer {token}'"] if use_auth_token else []), stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
while p.poll() is None:
|
||||
r = s.post(f"http://localhost:{vars.aria2_port}/jsonrpc", json={"jsonrpc": "2.0", "id": "kai", "method": "aria2.tellActive", "params": [f"token:{secret}"]}).json()["result"]
|
||||
r = s.post(f"http://localhost:{koboldai_vars.aria2_port}/jsonrpc", json={"jsonrpc": "2.0", "id": "kai", "method": "aria2.tellActive", "params": [f"token:{secret}"]}).json()["result"]
|
||||
if not r:
|
||||
s.close()
|
||||
if bar is not None:
|
||||
|
Reference in New Issue
Block a user