python: support Path in GPT4All.__init__ (#1462)

This commit is contained in:
cebtenzzre 2023-10-11 14:12:40 -04:00 committed by GitHub
parent 043617168e
commit f81b4b45bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,8 @@
""" """
Python only API for running all GPT4All models. Python only API for running all GPT4All models.
""" """
from __future__ import annotations
import os import os
import sys import sys
import time import time
@ -60,7 +62,7 @@ class GPT4All:
def __init__( def __init__(
self, self,
model_name: str, model_name: str,
model_path: Optional[str] = None, model_path: Optional[Union[str, os.PathLike[str]]] = None,
model_type: Optional[str] = None, model_type: Optional[str] = None,
allow_download: bool = True, allow_download: bool = True,
n_threads: Optional[int] = None, n_threads: Optional[int] = None,
@ -115,7 +117,7 @@ class GPT4All:
@staticmethod @staticmethod
def retrieve_model( def retrieve_model(
model_name: str, model_name: str,
model_path: Optional[str] = None, model_path: Optional[Union[str, os.PathLike[str]]] = None,
allow_download: bool = True, allow_download: bool = True,
verbose: bool = True, verbose: bool = True,
) -> ConfigType: ) -> ConfigType:
@ -160,7 +162,7 @@ class GPT4All:
) )
model_path = DEFAULT_MODEL_DIRECTORY model_path = DEFAULT_MODEL_DIRECTORY
else: else:
model_path = model_path.replace("\\", "\\\\") model_path = str(model_path).replace("\\", "\\\\")
if not os.path.exists(model_path): if not os.path.exists(model_path):
raise ValueError(f"Invalid model directory: {model_path}") raise ValueError(f"Invalid model directory: {model_path}")
@ -185,7 +187,7 @@ class GPT4All:
@staticmethod @staticmethod
def download_model( def download_model(
model_filename: str, model_filename: str,
model_path: str, model_path: Union[str, os.PathLike[str]],
verbose: bool = True, verbose: bool = True,
url: Optional[str] = None, url: Optional[str] = None,
) -> str: ) -> str: