Skip to content

Commit

Permalink
Fix models not getting downloaded in Python bindings (nomic-ai#1262)
Browse files Browse the repository at this point in the history
- custom callbacks & session improvements PR (v1.0.6) had one too many checks
- remove the problematic config['url'] check
- add a crude test
- fixes nomic-ai#1261
  • Loading branch information
cosmic-snow authored Jul 24, 2023
1 parent 2befff8 commit 6431d46
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
4 changes: 0 additions & 4 deletions gpt4all-bindings/python/gpt4all/gpt4all.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,6 @@ def retrieve_model(

# 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(
Expand Down
13 changes: 13 additions & 0 deletions gpt4all-bindings/python/gpt4all/tests/test_gpt4all.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sys
from io import StringIO
from pathlib import Path

from gpt4all import GPT4All, Embed4All
import time
Expand Down Expand Up @@ -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

0 comments on commit 6431d46

Please sign in to comment.