Skip to content

Commit e230e68

Browse files
julien-cLysandreJik
authored andcommitted
Add one more list_models test
1 parent 44e6bd4 commit e230e68

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/huggingface_hub/hf_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def logout(self, token: str) -> None:
134134
def list_models(
135135
self,
136136
filter: Union[str, Iterable[str], None] = None,
137-
sort: Optional[str] = None,
137+
sort: Union[Literal["lastModified"], str, None] = None,
138138
direction: Optional[Literal[-1]] = None,
139139
limit: Optional[int] = None,
140140
full: Optional[bool] = None,

tests/test_hf_api.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,21 @@ def test_list_models(self):
230230
self.assertGreater(len(models), 100)
231231
self.assertIsInstance(models[0], ModelInfo)
232232

233+
def test_list_models_complex_query(self):
234+
# Let's list the 10 most recent models
235+
# with tags "bert" and "jax",
236+
# ordered by last modified date.
237+
_api = HfApi()
238+
models = _api.list_models(
239+
filter=("bert", "jax"), sort="lastModified", direction=-1, limit=10
240+
)
241+
# we have at least 1 models
242+
self.assertGreater(len(models), 1)
243+
self.assertLessEqual(len(models), 10)
244+
model = models[0]
245+
self.assertIsInstance(model, ModelInfo)
246+
self.assertTrue(all(tag in model.tags for tag in ["bert", "jax"]))
247+
233248
def test_model_info(self):
234249
_api = HfApi()
235250
model = _api.model_info(repo_id=DUMMY_MODEL_ID)

0 commit comments

Comments
 (0)