Skip to content

Commit c751152

Browse files
committed
noscript mode is done
1 parent 12002d8 commit c751152

File tree

2 files changed

+86
-53
lines changed

2 files changed

+86
-53
lines changed

Diff for: gpttype_adapter.cpp

+13-13
Original file line numberDiff line numberDiff line change
@@ -950,20 +950,20 @@ ModelLoadResult gpttype_load_model(const load_model_inputs inputs, FileFormat in
950950
llamamodel->hparams.rope_freq_scale_train!=1.0f ||
951951
llamamodel->hparams.rope_scaling_type_train==2)
952952
{
953-
float ropemultiplier = 1.0f;
954-
if(llamamodel->hparams.rope_scaling_type_train!=2 &&
955-
llamamodel->hparams.n_ctx_train > 2048 && clamped_max_context_length > llamamodel->hparams.n_ctx_train &&
956-
llamamodel->hparams.rope_freq_scale_train==1.0f)
957-
{
958-
ropemultiplier = (float)llamamodel->hparams.n_ctx_train / (float)clamped_max_context_length;
959-
llama_ctx_params.rope_freq_base = rope_freq_base = llamamodel->hparams.rope_freq_base_train;
960-
llama_ctx_params.rope_freq_scale = rope_freq_scale = ropemultiplier * llamamodel->hparams.rope_freq_scale_train;
961-
printf("Automatic RoPE Scaling: Using (scale:%.3f, base:%.1f).\n", rope_freq_scale, rope_freq_base);
962-
}
963-
else
964-
{
953+
// float ropemultiplier = 1.0f;
954+
// if(llamamodel->hparams.rope_scaling_type_train!=2 &&
955+
// llamamodel->hparams.n_ctx_train > 2048 && clamped_max_context_length > llamamodel->hparams.n_ctx_train &&
956+
// llamamodel->hparams.rope_freq_scale_train==1.0f)
957+
// {
958+
// ropemultiplier = (float)llamamodel->hparams.n_ctx_train / (float)clamped_max_context_length;
959+
// llama_ctx_params.rope_freq_base = rope_freq_base = llamamodel->hparams.rope_freq_base_train;
960+
// llama_ctx_params.rope_freq_scale = rope_freq_scale = ropemultiplier * llamamodel->hparams.rope_freq_scale_train;
961+
// printf("Automatic RoPE Scaling: Using (scale:%.3f, base:%.1f).\n", rope_freq_scale, rope_freq_base);
962+
// }
963+
// else
964+
// {
965965
printf("Automatic RoPE Scaling: Using model internal value.\n");
966-
}
966+
// }
967967
}
968968
else
969969
{

Diff for: koboldcpp.py

+73-40
Original file line numberDiff line numberDiff line change
@@ -630,52 +630,85 @@ async def handle_request(self, genparams, api_format, stream_flag):
630630
except Exception as e:
631631
print(e)
632632

633-
def noscript_webui(self, path):
633+
def noscript_webui(self):
634634
global modelbusy
635+
import html
635636
import urllib.parse as urlparse
636-
parsed_url = urlparse.urlparse(path)
637+
parsed_url = urlparse.urlparse(self.path)
637638
parsed_dict = urlparse.parse_qs(parsed_url.query)
638-
status = "Error"
639639
reply = ""
640+
status = parsed_dict['status'][0] if 'status' in parsed_dict else "Ready To Generate"
640641
prompt = parsed_dict['prompt'][0] if 'prompt' in parsed_dict else ""
641-
max_length = parsed_dict['max_length'][0] if 'max_length' in parsed_dict else 100
642-
temperature = parsed_dict['temperature'][0] if 'temperature' in parsed_dict else 0.7
643-
top_k = parsed_dict['top_k'][0] if 'top_k' in parsed_dict else 100
644-
top_p = parsed_dict['top_p'][0] if 'top_p' in parsed_dict else 0.9
645-
rep_pen = parsed_dict['rep_pen'][0] if 'rep_pen' in parsed_dict else 1.1
642+
max_length = int(parsed_dict['max_length'][0]) if 'max_length' in parsed_dict else 100
643+
temperature = float(parsed_dict['temperature'][0]) if 'temperature' in parsed_dict else 0.7
644+
top_k = int(parsed_dict['top_k'][0]) if 'top_k' in parsed_dict else 100
645+
top_p = float(parsed_dict['top_p'][0]) if 'top_p' in parsed_dict else 0.9
646+
rep_pen = float(parsed_dict['rep_pen'][0]) if 'rep_pen' in parsed_dict else 1.1
647+
use_default_badwordsids = int(parsed_dict['use_default_badwordsids'][0]) if 'use_default_badwordsids' in parsed_dict else 0
646648
gencommand = (parsed_dict['generate'][0] if 'generate' in parsed_dict else "")=="Generate"
647649

648-
if prompt=="" or not gencommand or max_length<=0:
649-
status = "Ready To Generate"
650-
elif modelbusy.locked():
651-
status = "Model is busy, try again later."
650+
if gencommand:
651+
if prompt=="" or max_length<=0:
652+
status = "Need a valid prompt and length to generate."
653+
if modelbusy.locked():
654+
status = "Model is currently busy, try again later."
655+
else:
656+
epurl = f"http://localhost:{args.port}"
657+
if args.host!="":
658+
epurl = f"http://{args.host}:{args.port}"
659+
gen_payload = {"prompt": prompt,"max_length": max_length,"temperature": temperature,"prompt": prompt,"top_k": top_k,"top_p": top_p,"rep_pen": rep_pen,"use_default_badwordsids":use_default_badwordsids}
660+
respjson = make_url_request(f'{epurl}/api/v1/generate', gen_payload)
661+
reply = html.escape(respjson["results"][0]["text"])
662+
status = "Generation Completed"
663+
664+
if "generate" in parsed_dict:
665+
del parsed_dict["generate"]
666+
parsed_dict["prompt"] = prompt + reply
667+
parsed_dict["status"] = status
668+
updated_query_string = urlparse.urlencode(parsed_dict, doseq=True)
669+
updated_path = parsed_url._replace(query=updated_query_string).geturl()
670+
self.path = updated_path
671+
self.send_response(302)
672+
self.send_header("location", self.path)
673+
self.end_headers(content_type='text/html')
674+
return
652675
else:
653-
epurl = f"http://localhost:{args.port}"
654-
if args.host!="":
655-
epurl = f"http://{args.host}:{args.port}"
656-
gen_payload = {"prompt": prompt,"max_length": max_length,"temperature": temperature,"prompt": prompt,"top_k": top_k,"top_p": top_p,"rep_pen": rep_pen}
657-
respjson = make_url_request(f'{epurl}/api/v1/generate', gen_payload)
658-
reply = respjson["results"][0]["text"]
659-
status = "Generation Completed"
660-
661-
finalhtml = f'''
662-
<!DOCTYPE html>
663-
<html><head><title>KoboldCpp NoScript Mode</title></head><body>
664-
<h2>KoboldCpp NoScript Mode</h2>
665-
<p>KoboldCpp can be used without Javascript enabled, however this is not recommended.
666-
<br>If you have Javascript, please use <a href="/">Kobold Lite WebUI</a> instead.</p><hr/>
667-
<form action="/noscript">
668-
Enter Prompt:<br>
669-
<textarea name="prompt" cols="60" rows="7" placeholder="Enter Prompt Here">{prompt + reply}</textarea>
670-
<hr/>
671-
{status}<br>
672-
<hr/>
673-
<input type="submit" name="generate" value="Generate">
674-
</form>
675-
</body>
676-
</html>
677-
'''
678-
return finalhtml
676+
if modelbusy.locked():
677+
status = "Model is currently busy."
678+
679+
finalhtml = f'''<!doctype html>
680+
<html lang="en"><head>
681+
<meta charset="utf-8">
682+
<meta name="viewport" content="width=device-width, initial-scale=1">
683+
<title>KoboldCpp NoScript Mode</title></head><body>
684+
<h2>KoboldCpp NoScript Mode</h2>
685+
<div>
686+
<p>KoboldCpp can be used without Javascript enabled, however this is not recommended.
687+
<br>If you have Javascript, please use <a href="/">Kobold Lite WebUI</a> instead.</p><hr>
688+
<form action="/noscript">
689+
Enter Prompt:<br>
690+
<textarea name="prompt" cols="60" rows="8" wrap="soft" placeholder="Enter Prompt Here">{prompt}</textarea>
691+
<hr>
692+
{status}<br>
693+
<hr>
694+
<label>Gen. Amount</label> <input type="text" size="4" value="{max_length}" name="max_length"><br>
695+
<label>Temperature</label> <input type="text" size="4" value="{temperature}" name="temperature"><br>
696+
<label>Top-K</label> <input type="text" size="4" value="{top_k}" name="top_k"><br>
697+
<label>Top-P</label> <input type="text" size="4" value="{top_p}" name="top_p"><br>
698+
<label>Rep. Pen</label> <input type="text" size="4" value="{rep_pen}" name="rep_pen"><br>
699+
<label>Ignore EOS</label> <input type="checkbox" name="use_default_badwordsids" value="1" {"checked" if use_default_badwordsids else ""}><br>
700+
<input type="submit" name="generate" value="Generate"> (Please be patient)
701+
</form>
702+
<form action="/noscript">
703+
<input type="submit" value="Reset">
704+
</form>
705+
</div>
706+
</body></html>'''
707+
finalhtml = finalhtml.encode('utf-8')
708+
self.send_response(200)
709+
self.send_header('content-length', str(len(finalhtml)))
710+
self.end_headers(content_type='text/html')
711+
self.wfile.write(finalhtml)
679712

680713
def do_GET(self):
681714
global maxctx, maxhordelen, friendlymodelname, KcppVersion, totalgens, preloaded_story
@@ -691,8 +724,8 @@ def do_GET(self):
691724
response_body = self.embedded_kailite
692725

693726
elif self.path in ["/noscript", "/noscript?"] or self.path.startswith(('/noscript?','noscript?')): #it's possible for the root url to have ?params without /
694-
content_type = 'text/html'
695-
response_body = (self.noscript_webui(self.path)).encode('utf-8')
727+
self.noscript_webui()
728+
return
696729

697730
elif self.path.endswith(('/api/v1/model', '/api/latest/model')):
698731
response_body = (json.dumps({'result': friendlymodelname }).encode())

0 commit comments

Comments
 (0)