mirror of
https://github.com/oobabooga/text-generation-webui.git
synced 2026-04-04 22:27:29 +00:00
Restructure the repository (#6904)
This commit is contained in:
parent
d4017fbb6d
commit
d9de14d1f7
116 changed files with 254 additions and 261 deletions
|
|
@ -525,9 +525,9 @@ def start_new_chat(state):
|
|||
|
||||
def get_history_file_path(unique_id, character, mode):
|
||||
if mode == 'instruct':
|
||||
p = Path(f'logs/instruct/{unique_id}.json')
|
||||
p = Path(f'user_data/logs/instruct/{unique_id}.json')
|
||||
else:
|
||||
p = Path(f'logs/chat/{character}/{unique_id}.json')
|
||||
p = Path(f'user_data/logs/chat/{character}/{unique_id}.json')
|
||||
|
||||
return p
|
||||
|
||||
|
|
@ -563,13 +563,13 @@ def rename_history(old_id, new_id, character, mode):
|
|||
|
||||
def get_paths(state):
|
||||
if state['mode'] == 'instruct':
|
||||
return Path('logs/instruct').glob('*.json')
|
||||
return Path('user_data/logs/instruct').glob('*.json')
|
||||
else:
|
||||
character = state['character_menu']
|
||||
|
||||
# Handle obsolete filenames and paths
|
||||
old_p = Path(f'logs/{character}_persistent.json')
|
||||
new_p = Path(f'logs/persistent_{character}.json')
|
||||
old_p = Path(f'user_data/logs/{character}_persistent.json')
|
||||
new_p = Path(f'user_data/logs/persistent_{character}.json')
|
||||
if old_p.exists():
|
||||
logger.warning(f"Renaming \"{old_p}\" to \"{new_p}\"")
|
||||
old_p.rename(new_p)
|
||||
|
|
@ -581,7 +581,7 @@ def get_paths(state):
|
|||
p.parent.mkdir(exist_ok=True)
|
||||
new_p.rename(p)
|
||||
|
||||
return Path(f'logs/chat/{character}').glob('*.json')
|
||||
return Path(f'user_data/logs/chat/{character}').glob('*.json')
|
||||
|
||||
|
||||
def find_all_histories(state):
|
||||
|
|
@ -732,7 +732,7 @@ def generate_pfp_cache(character):
|
|||
if not cache_folder.exists():
|
||||
cache_folder.mkdir()
|
||||
|
||||
for path in [Path(f"characters/{character}.{extension}") for extension in ['png', 'jpg', 'jpeg']]:
|
||||
for path in [Path(f"user_data/characters/{character}.{extension}") for extension in ['png', 'jpg', 'jpeg']]:
|
||||
if path.exists():
|
||||
original_img = Image.open(path)
|
||||
original_img.save(Path(f'{cache_folder}/pfp_character.png'), format='PNG')
|
||||
|
|
@ -752,12 +752,12 @@ def load_character(character, name1, name2):
|
|||
|
||||
filepath = None
|
||||
for extension in ["yml", "yaml", "json"]:
|
||||
filepath = Path(f'characters/{character}.{extension}')
|
||||
filepath = Path(f'user_data/characters/{character}.{extension}')
|
||||
if filepath.exists():
|
||||
break
|
||||
|
||||
if filepath is None or not filepath.exists():
|
||||
logger.error(f"Could not find the character \"{character}\" inside characters/. No character has been loaded.")
|
||||
logger.error(f"Could not find the character \"{character}\" inside user_data/characters. No character has been loaded.")
|
||||
raise ValueError
|
||||
|
||||
file_contents = open(filepath, 'r', encoding='utf-8').read()
|
||||
|
|
@ -796,7 +796,7 @@ def load_instruction_template(template):
|
|||
if template == 'None':
|
||||
return ''
|
||||
|
||||
for filepath in [Path(f'instruction-templates/{template}.yaml'), Path('instruction-templates/Alpaca.yaml')]:
|
||||
for filepath in [Path(f'user_data/instruction-templates/{template}.yaml'), Path('user_data/instruction-templates/Alpaca.yaml')]:
|
||||
if filepath.exists():
|
||||
break
|
||||
else:
|
||||
|
|
@ -838,17 +838,17 @@ def upload_character(file, img, tavern=False):
|
|||
|
||||
outfile_name = name
|
||||
i = 1
|
||||
while Path(f'characters/{outfile_name}.yaml').exists():
|
||||
while Path(f'user_data/characters/{outfile_name}.yaml').exists():
|
||||
outfile_name = f'{name}_{i:03d}'
|
||||
i += 1
|
||||
|
||||
with open(Path(f'characters/{outfile_name}.yaml'), 'w', encoding='utf-8') as f:
|
||||
with open(Path(f'user_data/characters/{outfile_name}.yaml'), 'w', encoding='utf-8') as f:
|
||||
f.write(yaml_data)
|
||||
|
||||
if img is not None:
|
||||
img.save(Path(f'characters/{outfile_name}.png'))
|
||||
img.save(Path(f'user_data/characters/{outfile_name}.png'))
|
||||
|
||||
logger.info(f'New character saved to "characters/{outfile_name}.yaml".')
|
||||
logger.info(f'New character saved to "user_data/characters/{outfile_name}.yaml".')
|
||||
return gr.update(value=outfile_name, choices=get_available_characters())
|
||||
|
||||
|
||||
|
|
@ -923,9 +923,9 @@ def save_character(name, greeting, context, picture, filename):
|
|||
return
|
||||
|
||||
data = generate_character_yaml(name, greeting, context)
|
||||
filepath = Path(f'characters/{filename}.yaml')
|
||||
filepath = Path(f'user_data/characters/{filename}.yaml')
|
||||
save_file(filepath, data)
|
||||
path_to_img = Path(f'characters/{filename}.png')
|
||||
path_to_img = Path(f'user_data/characters/{filename}.png')
|
||||
if picture is not None:
|
||||
picture.save(path_to_img)
|
||||
logger.info(f'Saved {path_to_img}.')
|
||||
|
|
@ -933,9 +933,9 @@ def save_character(name, greeting, context, picture, filename):
|
|||
|
||||
def delete_character(name, instruct=False):
|
||||
for extension in ["yml", "yaml", "json"]:
|
||||
delete_file(Path(f'characters/{name}.{extension}'))
|
||||
delete_file(Path(f'user_data/characters/{name}.{extension}'))
|
||||
|
||||
delete_file(Path(f'characters/{name}.png'))
|
||||
delete_file(Path(f'user_data/characters/{name}.png'))
|
||||
|
||||
|
||||
def jinja_template_from_old_format(params, verbose=False):
|
||||
|
|
@ -1238,7 +1238,7 @@ def handle_save_template_click(instruction_template_str):
|
|||
contents = generate_instruction_template_yaml(instruction_template_str)
|
||||
return [
|
||||
"My Template.yaml",
|
||||
"instruction-templates/",
|
||||
"user_data/instruction-templates/",
|
||||
contents,
|
||||
gr.update(visible=True)
|
||||
]
|
||||
|
|
@ -1247,7 +1247,7 @@ def handle_save_template_click(instruction_template_str):
|
|||
def handle_delete_template_click(template):
|
||||
return [
|
||||
f"{template}.yaml",
|
||||
"instruction-templates/",
|
||||
"user_data/instruction-templates/",
|
||||
gr.update(visible=False)
|
||||
]
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue