Skip to content

Commit f81b4b4

Browse files
authored
python: support Path in GPT4All.__init__ (nomic-ai#1462)
1 parent 0436171 commit f81b4b4

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

gpt4all-bindings/python/gpt4all/gpt4all.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"""
22
Python only API for running all GPT4All models.
33
"""
4+
from __future__ import annotations
5+
46
import os
57
import sys
68
import time
@@ -60,7 +62,7 @@ class GPT4All:
6062
def __init__(
6163
self,
6264
model_name: str,
63-
model_path: Optional[str] = None,
65+
model_path: Optional[Union[str, os.PathLike[str]]] = None,
6466
model_type: Optional[str] = None,
6567
allow_download: bool = True,
6668
n_threads: Optional[int] = None,
@@ -115,7 +117,7 @@ def list_models() -> List[ConfigType]:
115117
@staticmethod
116118
def retrieve_model(
117119
model_name: str,
118-
model_path: Optional[str] = None,
120+
model_path: Optional[Union[str, os.PathLike[str]]] = None,
119121
allow_download: bool = True,
120122
verbose: bool = True,
121123
) -> ConfigType:
@@ -160,7 +162,7 @@ def retrieve_model(
160162
)
161163
model_path = DEFAULT_MODEL_DIRECTORY
162164
else:
163-
model_path = model_path.replace("\\", "\\\\")
165+
model_path = str(model_path).replace("\\", "\\\\")
164166

165167
if not os.path.exists(model_path):
166168
raise ValueError(f"Invalid model directory: {model_path}")
@@ -185,7 +187,7 @@ def retrieve_model(
185187
@staticmethod
186188
def download_model(
187189
model_filename: str,
188-
model_path: str,
190+
model_path: Union[str, os.PathLike[str]],
189191
verbose: bool = True,
190192
url: Optional[str] = None,
191193
) -> str:

0 commit comments

Comments
 (0)