Skip to content

Commit

Permalink
Supports downloading officially supported models not hosted on gpt4al…
Browse files Browse the repository at this point in the history
…l R2
  • Loading branch information
AndriyMulyar authored and rguo123 committed Jun 6, 2023
1 parent 266f13a commit ef35eb4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
18 changes: 15 additions & 3 deletions gpt4all-bindings/python/gpt4all/gpt4all.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,27 +93,39 @@ def retrieve_model(model_name: str, model_path: str = None, allow_download: bool
elif allow_download:
# Make sure valid model filename before attempting download
available_models = GPT4All.list_models()
if model_filename not in (m["filename"] for m in available_models):

selected_model = None
for m in available_models:
if model_filename == m['filename']:
selected_model = m
break

if selected_model is None:
raise ValueError(f"Model filename not in model list: {model_filename}")
return GPT4All.download_model(model_filename, model_path, verbose = verbose)
url = selected_model.pop('url', None)

return GPT4All.download_model(model_filename, model_path, verbose = verbose, url=url)
else:
raise ValueError("Failed to retrieve model")

@staticmethod
def download_model(model_filename: str, model_path: str, verbose: bool = True) -> str:
def download_model(model_filename: str, model_path: str, verbose: bool = True, url: str = None) -> str:
"""
Download model from https://gpt4all.io.
Args:
model_filename: Filename of model (with .bin extension).
model_path: Path to download model to.
verbose: If True (default), print debug messages.
url: the models remote url (e.g. may be hosted on HF)
Returns:
Model file destination.
"""

def get_download_url(model_filename):
if url:
return url
return f"https://gpt4all.io/models/{model_filename}"

# Download model
Expand Down
2 changes: 1 addition & 1 deletion gpt4all-bindings/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def copy_prebuilt_C_lib(src_dir, dest_dir, dest_build_dir):

setup(
name=package_name,
version="0.3.0",
version="0.3.1",
description="Python bindings for GPT4All",
author="Richard Guo",
author_email="[email protected]",
Expand Down

0 comments on commit ef35eb4

Please sign in to comment.