Improvements to character_bias extension

This commit is contained in:
oobabooga 2024-01-04 20:48:26 -08:00
parent 248742df1c
commit 91c2b8e11c

View file

@ -18,7 +18,7 @@ with open(bias_file, "r") as f:
params = { params = {
"activate": True, "activate": True,
"bias string": " *I am so happy*", "bias string": " *I am so happy*",
"use custom string": False, "custom string": "",
} }
@ -44,7 +44,7 @@ def bot_prefix_modifier(string):
behavior. behavior.
""" """
if params['activate']: if params['activate']:
if params['use custom string']: if params['custom string'].strip() != '':
return f'{string} {params["custom string"].strip()} ' return f'{string} {params["custom string"].strip()} '
else: else:
return f'{string} {params["bias string"].strip()} ' return f'{string} {params["bias string"].strip()} '
@ -56,8 +56,7 @@ def ui():
# Gradio elements # Gradio elements
activate = gr.Checkbox(value=params['activate'], label='Activate character bias') activate = gr.Checkbox(value=params['activate'], label='Activate character bias')
dropdown_string = gr.Dropdown(choices=bias_options, value=params["bias string"], label='Character bias', info='To edit the options in this dropdown edit the "bias_options.txt" file') dropdown_string = gr.Dropdown(choices=bias_options, value=params["bias string"], label='Character bias', info='To edit the options in this dropdown edit the "bias_options.txt" file')
use_custom_string = gr.Checkbox(value=False, label='Use custom bias textbox instead of dropdown') custom_string = gr.Textbox(value=params['custom string'], placeholder="Enter custom bias string", label="Custom Character Bias", info='If not empty, will be used instead of the value above')
custom_string = gr.Textbox(value="", placeholder="Enter custom bias string", label="Custom Character Bias", info='To use this textbox activate the checkbox above')
# Event functions to update the parameters in the backend # Event functions to update the parameters in the backend
def update_bias_string(x): def update_bias_string(x):
@ -73,11 +72,3 @@ def ui():
dropdown_string.change(update_bias_string, dropdown_string, None) dropdown_string.change(update_bias_string, dropdown_string, None)
custom_string.change(update_custom_string, custom_string, None) custom_string.change(update_custom_string, custom_string, None)
activate.change(lambda x: params.update({"activate": x}), activate, None) activate.change(lambda x: params.update({"activate": x}), activate, None)
use_custom_string.change(lambda x: params.update({"use custom string": x}), use_custom_string, None)
# Group elements together depending on the selected option
def bias_string_group():
if use_custom_string.value:
return gr.Group([use_custom_string, custom_string])
else:
return dropdown_string