From 6da94e358cbe515115500cb0afae2fd864612e22 Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Sat, 28 Jan 2023 23:00:51 -0300 Subject: [PATCH] Add support for extensions parameters Still experimental --- extensions/example/script.py | 8 ++++++-- server.py | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/extensions/example/script.py b/extensions/example/script.py index 4314af2d..71c7e4ee 100644 --- a/extensions/example/script.py +++ b/extensions/example/script.py @@ -1,14 +1,18 @@ +params = { + "input suffix": " *I say as I make a funny face*", +} + def input_modifier(string): """ This function is applied to your text inputs before they are fed into the model. """ - return string.replace(' ', '#') + return string + params["input suffix"] def output_modifier(string): """ This function is applied to the model outputs. """ - return string.replace(' ', '_') + return string diff --git a/server.py b/server.py index 327a1ea2..056e5f90 100644 --- a/server.py +++ b/server.py @@ -606,6 +606,29 @@ if args.chat or args.cai_chat: with gr.Tab('Upload TavernAI Character Card'): upload_img_tavern = gr.File(type='binary') + if args.extensions is not None: + extensions_ui_elements = [] + gr.Markdown('## Extensions parameters') + for ext in sorted(extension_state, key=lambda x : extension_state[x][1]): + if extension_state[ext][0] == True: + params = eval(f"extensions.{ext}.script.params") + for param in params: + if type(params[param] == str): + extensions_ui_elements.append(gr.Textbox(value=params[param], label=param)) + + def update_extensions_parameters(*kwargs): + i = 0 + for ext in sorted(extension_state, key=lambda x : extension_state[x][1]): + if extension_state[ext][0] == True: + params = eval(f"extensions.{ext}.script.params") + for param in params: + if len(kwargs) >= i+1: + params[param] = eval(f"kwargs[{i}]") + i += 1 + + btn_extensions = gr.Button("Apply") + btn_extensions.click(update_extensions_parameters, [*extensions_ui_elements], []) + input_params = [textbox, length_slider, preset_menu, model_menu, name1, name2, context, check, history_size_slider] if args.cai_chat: gen_event = btn.click(cai_chatbot_wrapper, input_params, display1, show_progress=args.no_stream, api_name="textgen")