From 6431d4677690565f633e7533662acc91ce9102d2 Mon Sep 17 00:00:00 2001 From: cosmic-snow <134004613+cosmic-snow@users.noreply.github.com> Date: Mon, 24 Jul 2023 18:57:06 +0200 Subject: [PATCH] Fix models not getting downloaded in Python bindings (#1262) - custom callbacks & session improvements PR (v1.0.6) had one too many checks - remove the problematic config['url'] check - add a crude test - fixes #1261 --- gpt4all-bindings/python/gpt4all/gpt4all.py | 4 ---- .../python/gpt4all/tests/test_gpt4all.py | 13 +++++++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/gpt4all-bindings/python/gpt4all/gpt4all.py b/gpt4all-bindings/python/gpt4all/gpt4all.py index ed642731..62af9503 100644 --- a/gpt4all-bindings/python/gpt4all/gpt4all.py +++ b/gpt4all-bindings/python/gpt4all/gpt4all.py @@ -168,10 +168,6 @@ class GPT4All: # If model file does not exist, download elif allow_download: - # Make sure valid model filename before attempting download - - if "url" not in config: - raise ValueError(f"Model filename not in model list: {model_filename}") url = config.pop("url", None) config["path"] = GPT4All.download_model( diff --git a/gpt4all-bindings/python/gpt4all/tests/test_gpt4all.py b/gpt4all-bindings/python/gpt4all/tests/test_gpt4all.py index fa798c0c..89e81086 100644 --- a/gpt4all-bindings/python/gpt4all/tests/test_gpt4all.py +++ b/gpt4all-bindings/python/gpt4all/tests/test_gpt4all.py @@ -1,5 +1,6 @@ import sys from io import StringIO +from pathlib import Path from gpt4all import GPT4All, Embed4All import time @@ -114,3 +115,15 @@ def test_empty_embedding(): embedder = Embed4All() with pytest.raises(ValueError): output = embedder.embed(text) + +def test_download_model(tmp_path: Path): + import gpt4all.gpt4all + old_default_dir = gpt4all.gpt4all.DEFAULT_MODEL_DIRECTORY + gpt4all.gpt4all.DEFAULT_MODEL_DIRECTORY = tmp_path # temporary pytest directory to ensure a download happens + try: + model = GPT4All(model_name='ggml-all-MiniLM-L6-v2-f16.bin') + model_path = tmp_path / model.config['filename'] + assert model_path.absolute() == Path(model.config['path']).absolute() + assert model_path.stat().st_size == int(model.config['filesize']) + finally: + gpt4all.gpt4all.DEFAULT_MODEL_DIRECTORY = old_default_dir