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

@ -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)