mirror of
https://github.com/oobabooga/text-generation-webui.git
synced 2026-04-07 23:53:40 +00:00
Make user_data configurable: add --user-data-dir flag, auto-detect ../user_data
If --user-data-dir is not set, auto-detect: use ../user_data when ./user_data doesn't exist, making it easy to share user data across portable builds by placing it one folder up.
This commit is contained in:
parent
4c406e024f
commit
e2548f69a9
21 changed files with 166 additions and 133 deletions
|
|
@ -194,7 +194,7 @@ def handle_new_prompt():
|
|||
new_name = utils.current_time()
|
||||
|
||||
# Create the new prompt file
|
||||
prompt_path = Path("user_data/logs/notebook") / f"{new_name}.txt"
|
||||
prompt_path = shared.user_data_dir / "logs" / "notebook" / f"{new_name}.txt"
|
||||
prompt_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
prompt_path.write_text("In this story,", encoding='utf-8')
|
||||
|
||||
|
|
@ -205,15 +205,15 @@ def handle_delete_prompt_confirm_notebook(prompt_name):
|
|||
available_prompts = utils.get_available_prompts()
|
||||
current_index = available_prompts.index(prompt_name) if prompt_name in available_prompts else 0
|
||||
|
||||
(Path("user_data/logs/notebook") / f"{prompt_name}.txt").unlink(missing_ok=True)
|
||||
(shared.user_data_dir / "logs" / "notebook" / f"{prompt_name}.txt").unlink(missing_ok=True)
|
||||
available_prompts = utils.get_available_prompts()
|
||||
|
||||
if available_prompts:
|
||||
new_value = available_prompts[min(current_index, len(available_prompts) - 1)]
|
||||
else:
|
||||
new_value = utils.current_time()
|
||||
Path("user_data/logs/notebook").mkdir(parents=True, exist_ok=True)
|
||||
(Path("user_data/logs/notebook") / f"{new_value}.txt").write_text("In this story,")
|
||||
(shared.user_data_dir / "logs" / "notebook").mkdir(parents=True, exist_ok=True)
|
||||
(shared.user_data_dir / "logs" / "notebook" / f"{new_value}.txt").write_text("In this story,")
|
||||
available_prompts = [new_value]
|
||||
|
||||
return [
|
||||
|
|
@ -233,8 +233,8 @@ def handle_rename_prompt_click_notebook(current_name):
|
|||
|
||||
|
||||
def handle_rename_prompt_confirm_notebook(new_name, current_name):
|
||||
old_path = Path("user_data/logs/notebook") / f"{current_name}.txt"
|
||||
new_path = Path("user_data/logs/notebook") / f"{new_name}.txt"
|
||||
old_path = shared.user_data_dir / "logs" / "notebook" / f"{current_name}.txt"
|
||||
new_path = shared.user_data_dir / "logs" / "notebook" / f"{new_name}.txt"
|
||||
|
||||
if old_path.exists() and not new_path.exists():
|
||||
old_path.rename(new_path)
|
||||
|
|
@ -250,7 +250,7 @@ def handle_rename_prompt_confirm_notebook(new_name, current_name):
|
|||
def autosave_prompt(text, prompt_name):
|
||||
"""Automatically save the text to the selected prompt file"""
|
||||
if prompt_name and text.strip():
|
||||
prompt_path = Path("user_data/logs/notebook") / f"{prompt_name}.txt"
|
||||
prompt_path = shared.user_data_dir / "logs" / "notebook" / f"{prompt_name}.txt"
|
||||
prompt_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
prompt_path.write_text(text, encoding='utf-8')
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue