mirror of
https://github.com/oobabooga/text-generation-webui.git
synced 2024-10-01 01:26:03 -04:00
Move characters/instruction-following to instruction-templates
This commit is contained in:
parent
65aa11890f
commit
c237ce607e
@ -165,7 +165,7 @@ def messages_to_prompt(body: dict, req_params: dict, max_tokens):
|
|||||||
# Instruct models can be much better
|
# Instruct models can be much better
|
||||||
if shared.settings['instruction_template']:
|
if shared.settings['instruction_template']:
|
||||||
try:
|
try:
|
||||||
instruct = yaml.safe_load(open(f"characters/instruction-following/{shared.settings['instruction_template']}.yaml", 'r'))
|
instruct = yaml.safe_load(open(f"instruction-templates/{shared.settings['instruction_template']}.yaml", 'r'))
|
||||||
|
|
||||||
template = instruct['turn_template']
|
template = instruct['turn_template']
|
||||||
system_message_template = "{message}"
|
system_message_template = "{message}"
|
||||||
@ -193,7 +193,7 @@ def messages_to_prompt(body: dict, req_params: dict, max_tokens):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
req_params['stopping_strings'].extend(['\nUser:', 'User:']) # XXX User: prompt here also
|
req_params['stopping_strings'].extend(['\nUser:', 'User:']) # XXX User: prompt here also
|
||||||
|
|
||||||
print(f"Exception: When loading characters/instruction-following/{shared.settings['instruction_template']}.yaml: {repr(e)}")
|
print(f"Exception: When loading instruction-templates/{shared.settings['instruction_template']}.yaml: {repr(e)}")
|
||||||
print("Warning: Loaded default instruction-following template for model.")
|
print("Warning: Loaded default instruction-following template for model.")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
@ -31,7 +31,7 @@ def edits(instruction: str, input: str, temperature=1.0, top_p=1.0) -> dict:
|
|||||||
stopping_strings.extend(['\n###'])
|
stopping_strings.extend(['\n###'])
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
instruct = yaml.safe_load(open(f"characters/instruction-following/{shared.settings['instruction_template']}.yaml", 'r'))
|
instruct = yaml.safe_load(open(f"instruction-templates/{shared.settings['instruction_template']}.yaml", 'r'))
|
||||||
|
|
||||||
template = instruct['turn_template']
|
template = instruct['turn_template']
|
||||||
template = template\
|
template = template\
|
||||||
@ -45,7 +45,7 @@ def edits(instruction: str, input: str, temperature=1.0, top_p=1.0) -> dict:
|
|||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
instruction_template = default_template
|
instruction_template = default_template
|
||||||
print(f"Exception: When loading characters/instruction-following/{shared.settings['instruction_template']}.yaml: {repr(e)}")
|
print(f"Exception: When loading instruction-templates/{shared.settings['instruction_template']}.yaml: {repr(e)}")
|
||||||
print("Warning: Loaded default instruction-following template (Alpaca) for model.")
|
print("Warning: Loaded default instruction-following template (Alpaca) for model.")
|
||||||
else:
|
else:
|
||||||
stopping_strings.extend(['\n###'])
|
stopping_strings.extend(['\n###'])
|
||||||
|
@ -475,7 +475,7 @@ def load_character(character, name1, name2, instruct=False):
|
|||||||
Path("cache/pfp_character.png").unlink()
|
Path("cache/pfp_character.png").unlink()
|
||||||
|
|
||||||
if character not in ['None', '', None]:
|
if character not in ['None', '', None]:
|
||||||
folder = 'characters' if not instruct else 'characters/instruction-following'
|
folder = 'characters' if not instruct else 'instruction-templates'
|
||||||
picture = generate_pfp_cache(character)
|
picture = generate_pfp_cache(character)
|
||||||
filepath = None
|
filepath = None
|
||||||
for extension in ["yml", "yaml", "json"]:
|
for extension in ["yml", "yaml", "json"]:
|
||||||
|
@ -12,7 +12,7 @@ def load_prompt(fname):
|
|||||||
return ''
|
return ''
|
||||||
elif fname.startswith('Instruct-'):
|
elif fname.startswith('Instruct-'):
|
||||||
fname = re.sub('^Instruct-', '', fname)
|
fname = re.sub('^Instruct-', '', fname)
|
||||||
file_path = Path(f'characters/instruction-following/{fname}.yaml')
|
file_path = Path(f'instruction-templates/{fname}.yaml')
|
||||||
if not file_path.exists():
|
if not file_path.exists():
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
@ -232,13 +232,13 @@ def create_event_handlers():
|
|||||||
|
|
||||||
shared.gradio['save_template'].click(
|
shared.gradio['save_template'].click(
|
||||||
lambda: 'My Template.yaml', None, gradio('save_filename')).then(
|
lambda: 'My Template.yaml', None, gradio('save_filename')).then(
|
||||||
lambda: 'characters/instruction-following/', None, gradio('save_root')).then(
|
lambda: 'instruction-templates/', None, gradio('save_root')).then(
|
||||||
chat.generate_instruction_template_yaml, gradio('name1_instruct', 'name2_instruct', 'context_instruct', 'turn_template'), gradio('save_contents')).then(
|
chat.generate_instruction_template_yaml, gradio('name1_instruct', 'name2_instruct', 'context_instruct', 'turn_template'), gradio('save_contents')).then(
|
||||||
lambda: gr.update(visible=True), None, gradio('file_saver'))
|
lambda: gr.update(visible=True), None, gradio('file_saver'))
|
||||||
|
|
||||||
shared.gradio['delete_template'].click(
|
shared.gradio['delete_template'].click(
|
||||||
lambda x: f'{x}.yaml', gradio('instruction_template'), gradio('delete_filename')).then(
|
lambda x: f'{x}.yaml', gradio('instruction_template'), gradio('delete_filename')).then(
|
||||||
lambda: 'characters/instruction-following/', None, gradio('delete_root')).then(
|
lambda: 'instruction-templates/', None, gradio('delete_root')).then(
|
||||||
lambda: gr.update(visible=True), None, gradio('file_deleter'))
|
lambda: gr.update(visible=True), None, gradio('file_deleter'))
|
||||||
|
|
||||||
shared.gradio['save_chat_history'].click(
|
shared.gradio['save_chat_history'].click(
|
||||||
|
@ -90,11 +90,11 @@ def get_available_prompts():
|
|||||||
|
|
||||||
def get_available_characters():
|
def get_available_characters():
|
||||||
paths = (x for x in Path('characters').iterdir() if x.suffix in ('.json', '.yaml', '.yml'))
|
paths = (x for x in Path('characters').iterdir() if x.suffix in ('.json', '.yaml', '.yml'))
|
||||||
return ['None'] + sorted(set((k.stem for k in paths if k.stem != "instruction-following")), key=natural_keys)
|
return ['None'] + sorted(set((k.stem for k in paths)), key=natural_keys)
|
||||||
|
|
||||||
|
|
||||||
def get_available_instruction_templates():
|
def get_available_instruction_templates():
|
||||||
path = "characters/instruction-following"
|
path = "instruction-templates"
|
||||||
paths = []
|
paths = []
|
||||||
if os.path.exists(path):
|
if os.path.exists(path):
|
||||||
paths = (x for x in Path(path).iterdir() if x.suffix in ('.json', '.yaml', '.yml'))
|
paths = (x for x in Path(path).iterdir() if x.suffix in ('.json', '.yaml', '.yml'))
|
||||||
|
Loading…
Reference in New Issue
Block a user