Skip to content

Commit 44b81f1

Browse files
committed
feat: add support for other path types
1 parent aef3c42 commit 44b81f1

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

model2vec/hf_utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,10 @@ def load_pretrained(
122122
tokenizer_file = "tokenizer.json"
123123
config_name = "config.json"
124124

125-
folder_or_repo_path = Path(folder_or_repo_path)
125+
# This check allows users to pass other things than Path objects, e.g.,
126+
# cloudpathlib.Anypath.
127+
if isinstance(folder_or_repo_path, str):
128+
folder_or_repo_path = Path(folder_or_repo_path)
126129

127130
local_folder = folder_or_repo_path / subfolder if subfolder else folder_or_repo_path
128131

model2vec/model.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -465,9 +465,14 @@ def load_local(cls: type[StaticModel], path: PathLike) -> StaticModel:
465465
:return: A StaticModel
466466
:raises: ValueError if the path is not a directory.
467467
"""
468-
path = Path(path)
469-
if not path.is_dir():
470-
raise ValueError(f"Path {path} is not a directory.")
468+
if isinstance(path, str):
469+
path = Path(path)
470+
471+
if isinstance(path, Path):
472+
# Only check if we're sure this is a path.
473+
# It could be a cloudpathlib path, or something else.
474+
if not path.is_dir():
475+
raise ValueError(f"Path {path} is not a directory.")
471476

472477
embeddings, tokenizer, config = load_local_model(path)
473478

0 commit comments

Comments
 (0)