From b6b21441c7da15a9ed5e24e8f51d3744aca249b2 Mon Sep 17 00:00:00 2001 From: Konstantin Gukov Date: Thu, 25 May 2023 17:26:15 +0200 Subject: [PATCH] Nicer handling of missing model directory. Correct exception message. --- gpt4all-bindings/python/gpt4all/gpt4all.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/gpt4all-bindings/python/gpt4all/gpt4all.py b/gpt4all-bindings/python/gpt4all/gpt4all.py index 836bf809..c2e9548b 100644 --- a/gpt4all-bindings/python/gpt4all/gpt4all.py +++ b/gpt4all-bindings/python/gpt4all/gpt4all.py @@ -77,14 +77,13 @@ class GPT4All(): model_filename += ".bin" # Validate download directory - if model_path == None: + if model_path is None: + try: + os.makedirs(DEFAULT_MODEL_DIRECTORY, exist_ok=True) + except OSError as exc: + raise ValueError("Failed to create model download directory at {}: {}. " + "Please specify model_path.".format(DEFAULT_MODEL_DIRECTORY, exc)) model_path = DEFAULT_MODEL_DIRECTORY - if not os.path.exists(DEFAULT_MODEL_DIRECTORY): - try: - os.makedirs(DEFAULT_MODEL_DIRECTORY) - except: - raise ValueError("Failed to create model download directory at ~/.cache/gpt4all/. \ - Please specify download_dir.") else: model_path = model_path.replace("\\", "\\\\")