mirror of
https://github.com/LostRuins/koboldcpp.git
synced 2026-09-18 16:55:14 +02:00
linting
This commit is contained in:
+23
-23
@@ -2365,7 +2365,7 @@ def is_ipv6_supported():
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
def format_jinja(messages, tools):
|
||||
def format_jinja(messages, tools):
|
||||
try:
|
||||
def strftime_now(format='%Y-%m-%d %H:%M:%S'):
|
||||
return datetime.now().strftime(format)
|
||||
@@ -2389,7 +2389,7 @@ def format_jinja(messages, tools):
|
||||
|
||||
def remove_outer_tags(inputstr):
|
||||
try:
|
||||
stripped = inputstr.strip()
|
||||
stripped = inputstr.strip()
|
||||
match = re.match(r'^<([^\s<>]+)>(.*?)</\1>\s*$', stripped, re.DOTALL) # Try angle brackets first
|
||||
if match:
|
||||
return match.group(2).strip()
|
||||
@@ -2399,10 +2399,10 @@ def remove_outer_tags(inputstr):
|
||||
return stripped # If no match, return original string
|
||||
except Exception:
|
||||
return stripped
|
||||
|
||||
def normalize_tool_call(obj): # Normalize various tool call formats to OpenAI format
|
||||
|
||||
def normalize_tool_call(obj): # Normalize various tool call formats to OpenAI format
|
||||
if "type" in obj and "function" in obj: # Already in OpenAI format
|
||||
return obj
|
||||
return obj
|
||||
if "name" in obj and ("arguments" in obj or "parameters" in obj):
|
||||
args = obj.get("arguments", obj.get("parameters", {}))
|
||||
return {
|
||||
@@ -2422,13 +2422,13 @@ def normalize_tool_call(obj): # Normalize various tool call formats to OpenAI fo
|
||||
"arguments": func.get("arguments", func.get("parameters", {}))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return obj
|
||||
|
||||
# Used to parse json for openai tool calls
|
||||
def extract_json_from_string(input_string):
|
||||
parsed_json = None
|
||||
input_string = remove_outer_tags(input_string) #if we detected wrapper tags, remove them
|
||||
input_string = remove_outer_tags(input_string) #if we detected wrapper tags, remove them
|
||||
|
||||
try: # First check if model exported perfect json
|
||||
parsed_json = json.loads(input_string)
|
||||
@@ -2740,8 +2740,8 @@ ws ::= | " " | "\n" [ \t]{0,20}
|
||||
attachedaudid = 0
|
||||
jinja_output = None
|
||||
jinjatools = genparams.get('tools', [])
|
||||
if use_jinja and cached_chat_template:
|
||||
jinja_output = format_jinja(messages_array,jinjatools)
|
||||
if use_jinja and cached_chat_template:
|
||||
jinja_output = format_jinja(messages_array,jinjatools)
|
||||
if jinja_output:
|
||||
messages_string = jinja_output
|
||||
if jinjatools and len(jinjatools)>0:
|
||||
@@ -2825,7 +2825,7 @@ ws ::= | " " | "\n" [ \t]{0,20}
|
||||
elif message['role'] == "tool":
|
||||
messages_string += tools_message_end
|
||||
messages_string += assistant_message_gen
|
||||
|
||||
|
||||
genparams["prompt"] = messages_string
|
||||
if len(images_added)>0:
|
||||
genparams["images"] = images_added
|
||||
@@ -3499,7 +3499,7 @@ Change Mode<br>
|
||||
response_body = embedded_kailite
|
||||
else:
|
||||
response_body = (f"Embedded KoboldAI Lite is not found.<br>You will have to connect via the main KoboldAI client, or <a href='https://lite.koboldai.net?local=1&port={self.port}'>use this URL</a> to connect.").encode()
|
||||
|
||||
|
||||
|
||||
elif self.path in ["/noscript", "/noscript?"] or self.path.startswith(('/noscript?','noscript?')): #it's possible for the root url to have ?params without /
|
||||
self.noscript_webui()
|
||||
@@ -3702,7 +3702,7 @@ Change Mode<br>
|
||||
elif self.path.endswith(('/.well-known/serviceinfo')):
|
||||
response_body = (json.dumps({"version":"0.2","software":{"name":"KoboldCpp","version":KcppVersion,"repository":"https://github.com/LostRuins/koboldcpp","homepage":"https://github.com/LostRuins/koboldcpp","logo":"https://raw.githubusercontent.com/LostRuins/koboldcpp/refs/heads/concedo/niko.ico"},"api":{"koboldai":{"name":"KoboldAI API","rel_url":"/api","documentation":"https://lite.koboldai.net/koboldcpp_api","version":KcppVersion},"openai":{"name":"OpenAI API","rel_url ":"/v1","documentation":"https://openai.com/documentation/api","version":KcppVersion}}}).encode())
|
||||
|
||||
elif self.path=="/props":
|
||||
elif self.path=="/props":
|
||||
response_body = (json.dumps({
|
||||
"chat_template": cached_chat_template,
|
||||
"id": 0,
|
||||
@@ -3734,16 +3734,16 @@ Change Mode<br>
|
||||
response_body = embedded_kcpp_docs
|
||||
else:
|
||||
response_body = ("KoboldCpp API is running!\n\nAPI usage reference can be found at the wiki: https://github.com/LostRuins/koboldcpp/wiki").encode()
|
||||
|
||||
|
||||
elif self.path=="/lcpp":
|
||||
content_type = 'text/html'
|
||||
# IMPORTANT: svelte needs a patch to accept this as a non-redirect path. Search for `r.pathname === e + "/index.html"` and add desired path there.
|
||||
if supports_gzip and embedded_lcpp_ui_gz is not None:
|
||||
response_body = embedded_lcpp_ui_gz
|
||||
content_encoding = 'gzip'
|
||||
content_encoding = 'gzip'
|
||||
else:
|
||||
response_body = ("Llama.cpp UI is not available. Please use the KoboldAI Lite UI instead.").encode()
|
||||
|
||||
|
||||
elif self.path.startswith(("/sdui")):
|
||||
content_type = 'text/html'
|
||||
if supports_gzip and embedded_kcpp_sdui_gz is not None:
|
||||
@@ -3752,7 +3752,7 @@ Change Mode<br>
|
||||
elif embedded_kcpp_sdui is not None:
|
||||
response_body = embedded_kcpp_sdui
|
||||
else:
|
||||
response_body = ("KoboldCpp API is running, but KCPP SDUI is not loaded").encode()
|
||||
response_body = ("KoboldCpp API is running, but KCPP SDUI is not loaded").encode()
|
||||
|
||||
elif self.path=="/v1":
|
||||
content_type = 'text/html'
|
||||
@@ -4389,14 +4389,14 @@ Change Mode<br>
|
||||
try:
|
||||
toolsdata_res = gendat['choices'][0]['message']['tool_calls']
|
||||
if toolsdata_res and len(toolsdata_res)>0:
|
||||
toolsdata_res[0]["index"] = 0 # need to add an index for OWUI
|
||||
toolsdata_res[0]["index"] = 0 # need to add an index for OWUI
|
||||
except Exception:
|
||||
toolsdata_res = []
|
||||
try:
|
||||
content_text = gendat['choices'][0]['message'].get('content', None)
|
||||
except Exception:
|
||||
content_text = None
|
||||
|
||||
|
||||
# Send role chunk first
|
||||
chunk_role = json.dumps({
|
||||
"id": "koboldcpp",
|
||||
@@ -5722,13 +5722,13 @@ def show_gui():
|
||||
quantkv_var.trace_add("write", toggleflashattn)
|
||||
makecheckbox(tokens_tab, "No BOS Token", nobostoken_var, 43, tooltiptxt="Prevents BOS token from being added at the start of any prompt. Usually NOT recommended for most models.")
|
||||
makecheckbox(tokens_tab, "Enable Guidance", enableguidance_var, 43,padx=(200 if corrupt_scaler else 140), tooltiptxt="Enables the use of Classifier-Free-Guidance, which allows the use of negative prompts. Has performance and memory impact.")
|
||||
def togglejinja(a,b,c):
|
||||
def togglejinja(a,b,c):
|
||||
if jinja_var.get()==1:
|
||||
jinjatoolsbox.grid()
|
||||
else:
|
||||
jinja_tools_var.set(0)
|
||||
jinjatoolsbox.grid_remove()
|
||||
changed_gpulayers_estimate()
|
||||
changed_gpulayers_estimate()
|
||||
makecheckbox(tokens_tab, "Use Jinja", jinja_var, row=45, command=togglejinja, tooltiptxt="Enables using jinja chat template formatting for chat completions endpoint. Other endpoints are unaffected.")
|
||||
jinjatoolsbox = makecheckbox(tokens_tab, "Jinja for Tools", jinja_tools_var, row=45 ,padx=(200 if corrupt_scaler else 140), tooltiptxt="Allows jinja even with tool calls. If unchecked, jinja will be disabled when tools are used.")
|
||||
jinja_var.trace_add("write", togglejinja)
|
||||
@@ -5736,7 +5736,7 @@ def show_gui():
|
||||
makelabelentry(tokens_tab, "MoE CPU Layers:", moecpu_var, row=55, padx=(490 if corrupt_scaler else 320), singleline=True, tooltip="Force Mixture of Experts (MoE) weights of the first N layers to the CPU.\nSetting it higher than GPU layers has no effect.", labelpadx=(300 if corrupt_scaler else 210))
|
||||
makelabelentry(tokens_tab, "Override KV:", override_kv_var, row=57, padx=(220 if corrupt_scaler else 120), singleline=True, width=150, tooltip="Override metadata value by key. Separate multiple values with commas. Format is name=type:value. Types: int, float, bool, str")
|
||||
makelabelentry(tokens_tab, "Override Tensors:", override_tensors_var, row=59, padx=(220 if corrupt_scaler else 120), singleline=True, width=150, tooltip="Override selected backend for specific tensors matching tensor_name_regex_pattern=buffer_type, same as in llama.cpp.")
|
||||
|
||||
|
||||
# Model Tab
|
||||
model_tab = tabcontent["Loaded Files"]
|
||||
|
||||
@@ -7397,7 +7397,7 @@ def kcpp_main_process(launch_args, g_memory=None, gui_launcher=False):
|
||||
if isinstance(args.chatcompletionsadapter, str) and os.path.exists(args.chatcompletionsadapter):
|
||||
ccadapter_path = os.path.abspath(args.chatcompletionsadapter)
|
||||
elif isinstance(args.chatcompletionsadapter, str) and adapt_dir:
|
||||
filename = args.chatcompletionsadapter
|
||||
filename = args.chatcompletionsadapter
|
||||
if not filename.endswith(".json"):
|
||||
filename += ".json"
|
||||
#strip to just the filename
|
||||
@@ -7717,7 +7717,7 @@ def kcpp_main_process(launch_args, g_memory=None, gui_launcher=False):
|
||||
if not loadok:
|
||||
exitcounter = 999
|
||||
exit_with_error(3,"Could not load text model: " + modelname)
|
||||
|
||||
|
||||
# The chat completions adapter is a list that needs derivation from chat templates
|
||||
# Try to derive chat completions adapter from chat template, now that we have the model loaded
|
||||
if not args.nomodel and args.model_param:
|
||||
|
||||
Reference in New Issue
Block a user