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
This commit is contained in:
cosmic-snow 2023-07-24 18:57:06 +02:00 committed by GitHub
parent 2befff83d6
commit 6431d46776
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 4 deletions

View File

@ -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(

View File

@ -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