Skip to content

Commit 26d7886

Browse files
authored
Deprecate model_name in favor of search in list_models (#4112)
* Deprecate list_models(..., model_name='...') * seriously? * use search
1 parent f6b3dbe commit 26d7886

2 files changed

Lines changed: 10 additions & 11 deletions

File tree

src/huggingface_hub/hf_api.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2327,6 +2327,7 @@ def get_dataset_tags(self) -> dict:
23272327
hf_raise_for_status(r)
23282328
return r.json()
23292329

2330+
@_deprecate_arguments(version="2.0", deprecated_args=["model_name"], custom_message="Use `search` instead.")
23302331
@validate_hf_hub_args
23312332
def list_models(
23322333
self,
@@ -2376,9 +2377,6 @@ def list_models(
23762377
inference_provider (`Literal["all"]` or `str`, *optional*):
23772378
A string to filter models on the Hub that are served by a specific provider.
23782379
Pass `"all"` to get all models served by at least one provider.
2379-
model_name (`str`, *optional*):
2380-
A string that contain complete or partial names for models on the
2381-
Hub, such as "bert" or "bert-base-cased"
23822380
trained_dataset (`str` or `List`, *optional*):
23832381
A string tag or a list of string tags of the trained dataset for a
23842382
model on the Hub.
@@ -2418,7 +2416,8 @@ def list_models(
24182416
token, which is the recommended method for authentication (see
24192417
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
24202418
To disable authentication, pass `False`.
2421-
2419+
model_name (`str`, *optional*):
2420+
(deprecated). Use `search` instead.
24222421

24232422
Returns:
24242423
`Iterable[ModelInfo]`: an iterable of [`huggingface_hub.hf_api.ModelInfo`] objects.
@@ -2490,7 +2489,7 @@ def list_models(
24902489
if num_parameters is not None:
24912490
params["num_parameters"] = num_parameters
24922491
search_list = []
2493-
if model_name:
2492+
if model_name: # deprecated
24942493
search_list.append(model_name)
24952494
if search:
24962495
search_list.append(search)

tests/test_hf_api.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2424,23 +2424,23 @@ def test_filter_models_by_author(self):
24242424

24252425
def test_filter_models_by_author_and_name(self):
24262426
# Test we can search by an author and a name, but the model is not found
2427-
models = list(self._api.list_models(author="facebook", model_name="bart-base"))
2427+
models = list(self._api.list_models(author="facebook", search="bart-base"))
24282428
assert "facebook/bart-base" in models[0].id
24292429

2430-
def test_failing_filter_models_by_author_and_model_name(self):
2430+
def test_failing_filter_models_by_author_and_search(self):
24312431
# Test we can search by an author and a name, but the model is not found
2432-
models = list(self._api.list_models(author="muellerzr", model_name="testme"))
2432+
models = list(self._api.list_models(author="muellerzr", search="testme"))
24332433
assert len(models) == 0
24342434

24352435
def test_filter_models_with_library(self):
2436-
models = list(self._api.list_models(author="microsoft", model_name="wavlm-base-sd", filter="tensorflow"))
2436+
models = list(self._api.list_models(author="microsoft", search="wavlm-base-sd", filter="tensorflow"))
24372437
assert len(models) == 0
24382438

2439-
models = list(self._api.list_models(author="microsoft", model_name="wavlm-base-sd", filter="pytorch"))
2439+
models = list(self._api.list_models(author="microsoft", search="wavlm-base-sd", filter="pytorch"))
24402440
assert len(models) > 0
24412441

24422442
def test_filter_models_with_task(self):
2443-
models = list(self._api.list_models(filter="fill-mask", model_name="albert-base-v2"))
2443+
models = list(self._api.list_models(filter="fill-mask", search="albert-base-v2"))
24442444
assert models[0].pipeline_tag == "fill-mask"
24452445
assert "albert" in models[0].id
24462446
assert "base" in models[0].id

0 commit comments

Comments
 (0)