allowed embedded chat adapters

This commit is contained in:
Concedo 2024-07-17 18:08:43 +08:00
parent 5988243aee
commit eca7521c13
2 changed files with 52 additions and 10 deletions

View file

@ -16807,7 +16807,7 @@ Current version indicated by LITEVER below.
</span> </span>
<input class="form-control" type="text" id="custom_oai_endpoint" placeholder="OpenAI API URL" value=""> <input class="form-control" type="text" id="custom_oai_endpoint" placeholder="OpenAI API URL" value="">
<input class="form-control" type="password" id="custom_oai_key" placeholder="OpenAI API Key" value="" onfocus="focus_api_keys()" onblur="blur_api_keys()"><br> <input class="form-control" type="password" id="custom_oai_key" placeholder="OpenAI API Key (Required)" value="" onfocus="focus_api_keys()" onblur="blur_api_keys()"><br>
Model Choice:<br> Model Choice:<br>
<select style="padding:4px;display:inline;width:calc(100% - 220px)" class="form-control" id="custom_oai_model" onchange="oai_model_change(true)"> <select style="padding:4px;display:inline;width:calc(100% - 220px)" class="form-control" id="custom_oai_model" onchange="oai_model_change(true)">
<option value="gpt-3.5-turbo-instruct" selected="selected">gpt-3.5-turbo-instruct</option> <option value="gpt-3.5-turbo-instruct" selected="selected">gpt-3.5-turbo-instruct</option>
@ -16880,7 +16880,7 @@ Current version indicated by LITEVER below.
<span class="color_red">NOTICE: At this time, the official Claude API has CORS restrictions and must be accessed with a CORS proxy. Your connection WILL be proxied.</span><br><br> <span class="color_red">NOTICE: At this time, the official Claude API has CORS restrictions and must be accessed with a CORS proxy. Your connection WILL be proxied.</span><br><br>
<span class="color_green" style="font-weight: bold;">Please input Claude API URL and Key.</span><br><br> <span class="color_green" style="font-weight: bold;">Please input Claude API URL and Key.</span><br><br>
<input class="form-control" type="text" id="custom_claude_endpoint" placeholder="Claude API URL" value=""> <input class="form-control" type="text" id="custom_claude_endpoint" placeholder="Claude API URL" value="">
<input class="form-control" type="password" id="custom_claude_key" placeholder="Claude API Key" value="" onfocus="focus_api_keys()" onblur="blur_api_keys()"><br> <input class="form-control" type="password" id="custom_claude_key" placeholder="Claude API Key (Required)" value="" onfocus="focus_api_keys()" onblur="blur_api_keys()"><br>
Model Choice:<br> Model Choice:<br>
<select style="padding:4px;" class="form-control" id="custom_claude_model" onload="toggleclaudemodel()" onchange="toggleclaudemodel()"> <select style="padding:4px;" class="form-control" id="custom_claude_model" onload="toggleclaudemodel()" onchange="toggleclaudemodel()">
<option value="claude-v1">claude-v1</option> <option value="claude-v1">claude-v1</option>
@ -16918,7 +16918,7 @@ Current version indicated by LITEVER below.
<option value="text-bison-001">text-bison-001</option> <option value="text-bison-001">text-bison-001</option>
</select> </select>
<span class="color_green" style="font-weight: bold;">Please input Gemini or PaLM API Key.</span><br><br> <span class="color_green" style="font-weight: bold;">Please input Gemini or PaLM API Key.</span><br><br>
<input class="form-control" type="password" id="custom_palm_key" placeholder="PaLM/Gemini API Key" value="" onfocus="focus_api_keys()" onblur="blur_api_keys()"><br> <input class="form-control" type="password" id="custom_palm_key" placeholder="PaLM/Gemini API Key (Required)" value="" onfocus="focus_api_keys()" onblur="blur_api_keys()"><br>
<input class="form-control" type="text" id="gemini_system_instruction" placeholder="(Enter System Instruction)" value=""><br> <input class="form-control" type="text" id="gemini_system_instruction" placeholder="(Enter System Instruction)" value=""><br>
</div> </div>
<div id="coherecustom" class="aidgpopuplistheader anotelabel hidden"> <div id="coherecustom" class="aidgpopuplistheader anotelabel hidden">
@ -16930,7 +16930,7 @@ Current version indicated by LITEVER below.
<option value="command-r-plus">command-r-plus</option> <option value="command-r-plus">command-r-plus</option>
</select> </select>
<span class="color_green" style="font-weight: bold;">Please input Cohere API Key.</span><br><br> <span class="color_green" style="font-weight: bold;">Please input Cohere API Key.</span><br><br>
<input class="form-control" type="password" id="custom_cohere_key" placeholder="Cohere API Key" value="" onfocus="focus_api_keys()" onblur="blur_api_keys()"><br> <input class="form-control" type="password" id="custom_cohere_key" placeholder="Cohere API Key (Required)" value="" onfocus="focus_api_keys()" onblur="blur_api_keys()"><br>
<input type="checkbox" id="usecohereweb"> <input type="checkbox" id="usecohereweb">
<div class="box-label" id="usecohereweblabel">Use WebSearch</div> <div class="box-label" id="usecohereweblabel">Use WebSearch</div>
<input type="checkbox" id="useocoherepreamble" onchange="togglecoherepreamble()"> <input type="checkbox" id="useocoherepreamble" onchange="togglecoherepreamble()">

View file

@ -2088,6 +2088,8 @@ def show_gui():
whisper_model_var = ctk.StringVar() whisper_model_var = ctk.StringVar()
kcpp_jsonembed_var = ctk.IntVar(value=0)
def tabbuttonaction(name): def tabbuttonaction(name):
for t in tabcontent: for t in tabcontent:
if name == t: if name == t:
@ -2678,6 +2680,8 @@ def show_gui():
makelabel(extra_tab, "Unpack KoboldCpp to a local directory to modify its files.", 1, 0) makelabel(extra_tab, "Unpack KoboldCpp to a local directory to modify its files.", 1, 0)
makelabel(extra_tab, "You can also launch via koboldcpp.py for faster startup.", 2, 0) makelabel(extra_tab, "You can also launch via koboldcpp.py for faster startup.", 2, 0)
ctk.CTkButton(extra_tab , text = "Unpack KoboldCpp To Folder", command = unpack_to_dir ).grid(row=3,column=0, stick="w", padx= 8, pady=2) ctk.CTkButton(extra_tab , text = "Unpack KoboldCpp To Folder", command = unpack_to_dir ).grid(row=3,column=0, stick="w", padx= 8, pady=2)
makecheckbox(extra_tab, "Embed JSON files when saving KCPPS", kcpp_jsonembed_var, 5, tooltiptxt="Embeds any selected JSON files directly into kcpps setting files when saving.")
# launch # launch
def guilaunch(): def guilaunch():
@ -2760,10 +2764,24 @@ def show_gui():
args.ropeconfig = [float(customrope_scale.get()),float(customrope_base.get())] args.ropeconfig = [float(customrope_scale.get()),float(customrope_base.get())]
args.chatcompletionsadapter = None if chatcompletionsadapter_var.get() == "" else chatcompletionsadapter_var.get() args.chatcompletionsadapter = None if chatcompletionsadapter_var.get() == "" else chatcompletionsadapter_var.get()
try:
if kcpp_jsonembed_var.get()==1 and isinstance(args.chatcompletionsadapter, str) and args.chatcompletionsadapter!="" and os.path.exists(args.chatcompletionsadapter):
print(f"Embedding chat completions adapter...") # parse and save embedded preload story
with open(args.chatcompletionsadapter, 'r') as f:
args.chatcompletionsadapter = json.load(f)
except Exception as ex2:
pass
args.model_param = None if model_var.get() == "" else model_var.get() args.model_param = None if model_var.get() == "" else model_var.get()
args.lora = None if lora_var.get() == "" else ([lora_var.get()] if lora_base_var.get()=="" else [lora_var.get(), lora_base_var.get()]) args.lora = None if lora_var.get() == "" else ([lora_var.get()] if lora_base_var.get()=="" else [lora_var.get(), lora_base_var.get()])
args.preloadstory = None if preloadstory_var.get() == "" else preloadstory_var.get() args.preloadstory = None if preloadstory_var.get() == "" else preloadstory_var.get()
try:
if kcpp_jsonembed_var.get()==1 and isinstance(args.preloadstory, str) and args.preloadstory!="" and os.path.exists(args.preloadstory):
print(f"Embedding preload story...") # parse and save embedded preload story
with open(args.preloadstory, 'r') as f:
args.preloadstory = json.load(f)
except Exception as ex2:
pass
args.mmproj = None if mmproj_var.get() == "" else mmproj_var.get() args.mmproj = None if mmproj_var.get() == "" else mmproj_var.get()
args.ssl = None if (ssl_cert_var.get() == "" or ssl_key_var.get() == "") else ([ssl_cert_var.get(), ssl_key_var.get()]) args.ssl = None if (ssl_cert_var.get() == "" or ssl_key_var.get() == "") else ([ssl_cert_var.get(), ssl_key_var.get()])
@ -3503,18 +3521,32 @@ def main(launch_args,start_server=True):
#try to read story if provided #try to read story if provided
if args.preloadstory: if args.preloadstory:
global preloaded_story
canload = False
if isinstance(args.preloadstory, str) and os.path.exists(args.preloadstory): if isinstance(args.preloadstory, str) and os.path.exists(args.preloadstory):
print(f"Preloading saved story {args.preloadstory} into server...") print(f"Preloading saved story {args.preloadstory} into server...")
with open(args.preloadstory, mode='rb') as f: with open(args.preloadstory, mode='rb') as f:
global preloaded_story
preloaded_story = f.read() preloaded_story = f.read()
print("Saved story preloaded.") canload = True
elif isinstance(args.preloadstory, str):
print(f"Preloading saved story as JSON into server...")
try:
import ast
parsed = ast.literal_eval(args.preloadstory)
preloaded_story = json.dumps(parsed).encode()
canload = True
except Exception as ex:
print(ex)
if canload:
print("Saved story preloaded.")
else: else:
print(f"Warning: Saved story file {args.preloadstory} invalid or not found. No story will be preloaded into server.") print(f"Warning: Saved story file invalid or not found. No story will be preloaded into server.")
# try to read chat completions adapter # try to read chat completions adapter
if args.chatcompletionsadapter: if args.chatcompletionsadapter:
global chatcompl_adapter
ccadapter_path = None ccadapter_path = None
canload = False
adapt_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'kcpp_adapters') adapt_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'kcpp_adapters')
adapt_dir = adapt_dir if os.path.isdir(adapt_dir) else None adapt_dir = adapt_dir if os.path.isdir(adapt_dir) else None
if isinstance(args.chatcompletionsadapter, str) and os.path.exists(args.chatcompletionsadapter): if isinstance(args.chatcompletionsadapter, str) and os.path.exists(args.chatcompletionsadapter):
@ -3529,11 +3561,21 @@ def main(launch_args,start_server=True):
if ccadapter_path: if ccadapter_path:
print(f"Loading Chat Completions Adapter: {ccadapter_path}") print(f"Loading Chat Completions Adapter: {ccadapter_path}")
with open(ccadapter_path, 'r') as f: with open(ccadapter_path, 'r') as f:
global chatcompl_adapter
chatcompl_adapter = json.load(f) chatcompl_adapter = json.load(f)
print(f"Chat Completions Adapter Loaded") canload = True
else: else:
print(f"Warning: Chat Completions Adapter {args.chatcompletionsadapter} invalid or not found.") if isinstance(args.chatcompletionsadapter, str) and args.chatcompletionsadapter!="":
try:
import ast
parsed = ast.literal_eval(args.chatcompletionsadapter)
chatcompl_adapter = json.loads(json.dumps(parsed))
canload = True
except Exception as ex:
print(ex)
if canload:
print(f"Chat Completions Adapter Loaded")
else:
print(f"Warning: Chat Completions Adapter invalid or not found.")
if args.model_param and args.model_param!="": if args.model_param and args.model_param!="":
if args.model_param.endswith("?download=true"): if args.model_param.endswith("?download=true"):