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>
This commit is contained in:
original-subliminal-thought-criminal 2023-07-11 22:16:36 -05:00 committed by GitHub
parent a81cdd1367
commit ad07839a7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -460,11 +460,16 @@ def load_character(character, name1, name2, instruct=False):
if character not in ['None', '', None]: if character not in ['None', '', None]:
folder = 'characters' if not instruct else 'characters/instruction-following' folder = 'characters' if not instruct else 'characters/instruction-following'
picture = generate_pfp_cache(character) picture = generate_pfp_cache(character)
filepath = None
for extension in ["yml", "yaml", "json"]: for extension in ["yml", "yaml", "json"]:
filepath = Path(f'{folder}/{character}.{extension}') filepath = Path(f'{folder}/{character}.{extension}')
if filepath.exists(): if filepath.exists():
break 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() file_contents = open(filepath, 'r', encoding='utf-8').read()
data = json.loads(file_contents) if extension == "json" else yaml.safe_load(file_contents) data = json.loads(file_contents) if extension == "json" else yaml.safe_load(file_contents)