Remove duplicate code

This commit is contained in:
oobabooga 2023-05-10 01:34:04 -03:00
parent ba445cf59f
commit bdf1274b5d
34 changed files with 32 additions and 180 deletions

View file

@ -16,14 +16,7 @@ from modules.extensions import apply_extensions
from modules.html_generator import chat_html_wrapper, make_thumbnail
from modules.text_generation import (generate_reply, get_encoded_length,
get_max_prompt_length)
# Replace multiple string pairs in a string
def replace_all(text, dic):
for i, j in dic.items():
text = text.replace(i, j)
return text
from modules.utils import replace_all
def generate_chat_prompt(user_input, state, **kwargs):

View file

@ -71,32 +71,6 @@ settings = {
'prompts': {
'default': 'QA',
'.*(gpt4chan|gpt-4chan|4chan)': 'GPT-4chan',
'.*(oasst|stablelm-7b-sft-v7-epoch-3)': 'Open Assistant',
'.*(alpac|dolly)': "Alpaca",
'.*mpt-.*instruct': "Alpaca",
"(?!.*v0)(?!.*1.1)(?!.*1_1)(?!.*stable).*vicuna": "Vicuna v0",
".*vicuna.*v0": "Vicuna v0",
".*vicuna.*(1.1|1_1)": "Vicuna v1.1",
".*stable.*vicuna": "StableVicuna",
'.*metharme': 'Metharme',
".*guanaco": "Guanaco-Chat",
".*koala": "Koala",
".*stablelm-tuned": "StableLM",
".*wizardlm": "WizardLM",
".*galactica.*finetuned": "Galactica Finetuned",
".*galactica.*-v2": "Galactica v2",
"(?!.*finetuned)(?!.*-v2).*galactica": "Galactica",
".*baize": "Baize",
".*mpt-.*instruct": "Alpaca",
".*mpt-.*chat": "MPT-Chat",
"(?!.*-flan-)(?!.*-t5-).*lamini-": "Alpaca",
".*incite.*chat": "INCITE-Chat",
".*incite.*instruct": "INCITE-Instruct",
},
'lora_prompts': {
'default': 'QA',
'.*alpaca': "Alpaca",
'.*baize': "Baize",
}
}

View file

@ -9,6 +9,14 @@ def atoi(text):
return int(text) if text.isdigit() else text.lower()
# Replace multiple string pairs in a string
def replace_all(text, dic):
for i, j in dic.items():
text = text.replace(i, j)
return text
def natural_keys(text):
return [atoi(c) for c in re.split(r'(\d+)', text)]
@ -28,6 +36,7 @@ def get_available_prompts():
prompts = []
prompts += sorted(set((k.stem for k in Path('prompts').glob('[0-9]*.txt'))), key=natural_keys, reverse=True)
prompts += sorted(set((k.stem for k in Path('prompts').glob('*.txt'))), key=natural_keys)
prompts += ['Instruct-' + k for k in get_available_instruction_templates() if k != 'None']
prompts += ['None']
return prompts
@ -42,6 +51,7 @@ def get_available_instruction_templates():
paths = []
if os.path.exists(path):
paths = (x for x in Path(path).iterdir() if x.suffix in ('.json', '.yaml', '.yml'))
return ['None'] + sorted(set((k.stem for k in paths)), key=natural_keys)