Nicer handling of missing model directory.

Correct exception message.
This commit is contained in:
Konstantin Gukov 2023-05-25 17:26:15 +02:00 committed by Richard Guo
parent 84201784b5
commit b6b21441c7

View File

@ -77,14 +77,13 @@ class GPT4All():
model_filename += ".bin" model_filename += ".bin"
# Validate download directory # Validate download directory
if model_path == None: if model_path is None:
model_path = DEFAULT_MODEL_DIRECTORY
if not os.path.exists(DEFAULT_MODEL_DIRECTORY):
try: try:
os.makedirs(DEFAULT_MODEL_DIRECTORY) os.makedirs(DEFAULT_MODEL_DIRECTORY, exist_ok=True)
except: except OSError as exc:
raise ValueError("Failed to create model download directory at ~/.cache/gpt4all/. \ raise ValueError("Failed to create model download directory at {}: {}. "
Please specify download_dir.") "Please specify model_path.".format(DEFAULT_MODEL_DIRECTORY, exc))
model_path = DEFAULT_MODEL_DIRECTORY
else: else:
model_path = model_path.replace("\\", "\\\\") model_path = model_path.replace("\\", "\\\\")