From ad07839a7b8c8bf852e16e9e26d206351ffcc0ab Mon Sep 17 00:00:00 2001 From: original-subliminal-thought-criminal Date: Tue, 11 Jul 2023 22:16:36 -0500 Subject: [PATCH] Small bug, when arbitrary loading character.json that doesn't exist (#2643) * Fixes #2482 * corrected erroronius variable * Use .exists() --------- Co-authored-by: oobabooga <112222186+oobabooga@users.noreply.github.com> --- modules/chat.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/chat.py b/modules/chat.py index c0635c23..d1f85d62 100644 --- a/modules/chat.py +++ b/modules/chat.py @@ -460,11 +460,16 @@ def load_character(character, name1, name2, instruct=False): if character not in ['None', '', None]: folder = 'characters' if not instruct else 'characters/instruction-following' picture = generate_pfp_cache(character) + filepath = None for extension in ["yml", "yaml", "json"]: filepath = Path(f'{folder}/{character}.{extension}') if filepath.exists(): break + if filepath is None: + logger.error(f"Could not find character file for {character} in {folder} folder. Please check your spelling.") + return name1, name2, picture, greeting, context, turn_template.replace("\n", r"\n") + file_contents = open(filepath, 'r', encoding='utf-8').read() data = json.loads(file_contents) if extension == "json" else yaml.safe_load(file_contents)