Skip to content

Commit

Permalink
Merge branch 'main' into tv0.24-release
Browse files Browse the repository at this point in the history
  • Loading branch information
Wauplin committed Jul 17, 2024
2 parents d8e92aa + 9c98a4b commit 7fe286b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 25 deletions.
15 changes: 6 additions & 9 deletions src/huggingface_hub/hf_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@
"downloads",
"downloadsAllTime",
"gated",
"gitalyUid",
"inference",
"lastModified",
"library_name",
Expand Down Expand Up @@ -177,7 +176,6 @@
"downloads",
"downloadsAllTime",
"gated",
"gitalyUid",
"lastModified",
"likes",
"paperswithcode_id",
Expand All @@ -192,7 +190,6 @@
"cardData",
"datasets",
"disabled",
"gitalyUid",
"lastModified",
"createdAt",
"likes",
Expand Down Expand Up @@ -1633,7 +1630,7 @@ def list_models(
expand (`List[ExpandModelProperty_T]`, *optional*):
List properties to return in the response. When used, only the properties in the list will be returned.
This parameter cannot be used if `full`, `cardData` or `fetch_config` are passed.
Possible values are `"author"`, `"cardData"`, `"config"`, `"createdAt"`, `"disabled"`, `"downloads"`, `"downloadsAllTime"`, `"gated"`, `"gitalyUid"`, `"inference"`, `"lastModified"`, `"library_name"`, `"likes"`, `"mask_token"`, `"model-index"`, `"pipeline_tag"`, `"private"`, `"safetensors"`, `"sha"`, `"siblings"`, `"spaces"`, `"tags"`, `"transformersInfo"` and `"widgetData"`.
Possible values are `"author"`, `"cardData"`, `"config"`, `"createdAt"`, `"disabled"`, `"downloads"`, `"downloadsAllTime"`, `"gated"`, `"inference"`, `"lastModified"`, `"library_name"`, `"likes"`, `"mask_token"`, `"model-index"`, `"pipeline_tag"`, `"private"`, `"safetensors"`, `"sha"`, `"siblings"`, `"spaces"`, `"tags"`, `"transformersInfo"` and `"widgetData"`.
full (`bool`, *optional*):
Whether to fetch all model data, including the `last_modified`,
the `sha`, the files and the `tags`. This is set to `True` by
Expand Down Expand Up @@ -1836,7 +1833,7 @@ def list_datasets(
expand (`List[ExpandDatasetProperty_T]`, *optional*):
List properties to return in the response. When used, only the properties in the list will be returned.
This parameter cannot be used if `full` is passed.
Possible values are `"author"`, `"cardData"`, `"citation"`, `"createdAt"`, `"disabled"`, `"description"`, `"downloads"`, `"downloadsAllTime"`, `"gated"`, `"gitalyUid"`, `"lastModified"`, `"likes"`, `"paperswithcode_id"`, `"private"`, `"siblings"`, `"sha"` and `"tags"`.
Possible values are `"author"`, `"cardData"`, `"citation"`, `"createdAt"`, `"disabled"`, `"description"`, `"downloads"`, `"downloadsAllTime"`, `"gated"`, `"lastModified"`, `"likes"`, `"paperswithcode_id"`, `"private"`, `"siblings"`, `"sha"` and `"tags"`.
full (`bool`, *optional*):
Whether to fetch all dataset data, including the `last_modified`,
the `card_data` and the files. Can contain useful information such as the
Expand Down Expand Up @@ -2017,7 +2014,7 @@ def list_spaces(
expand (`List[ExpandSpaceProperty_T]`, *optional*):
List properties to return in the response. When used, only the properties in the list will be returned.
This parameter cannot be used if `full` is passed.
Possible values are `"author"`, `"cardData"`, `"datasets"`, `"disabled"`, `"gitalyUid"`, `"lastModified"`, `"createdAt"`, `"likes"`, `"private"`, `"runtime"`, `"sdk"`, `"siblings"`, `"sha"`, `"subdomain"`, `"tags"` and `"models"`.
Possible values are `"author"`, `"cardData"`, `"datasets"`, `"disabled"`, `"lastModified"`, `"createdAt"`, `"likes"`, `"private"`, `"runtime"`, `"sdk"`, `"siblings"`, `"sha"`, `"subdomain"`, `"tags"` and `"models"`.
full (`bool`, *optional*):
Whether to fetch all Spaces data, including the `last_modified`, `siblings`
and `card_data` fields.
Expand Down Expand Up @@ -2334,7 +2331,7 @@ def model_info(
expand (`List[ExpandModelProperty_T]`, *optional*):
List properties to return in the response. When used, only the properties in the list will be returned.
This parameter cannot be used if `securityStatus` or `files_metadata` are passed.
Possible values are `"author"`, `"cardData"`, `"config"`, `"createdAt"`, `"disabled"`, `"downloads"`, `"downloadsAllTime"`, `"gated"`, `"gitalyUid"`, `"inference"`, `"lastModified"`, `"library_name"`, `"likes"`, `"mask_token"`, `"model-index"`, `"pipeline_tag"`, `"private"`, `"safetensors"`, `"sha"`, `"siblings"`, `"spaces"`, `"tags"`, `"transformersInfo"` and `"widgetData"`.
Possible values are `"author"`, `"cardData"`, `"config"`, `"createdAt"`, `"disabled"`, `"downloads"`, `"downloadsAllTime"`, `"gated"`, `"inference"`, `"lastModified"`, `"library_name"`, `"likes"`, `"mask_token"`, `"model-index"`, `"pipeline_tag"`, `"private"`, `"safetensors"`, `"sha"`, `"siblings"`, `"spaces"`, `"tags"`, `"transformersInfo"` and `"widgetData"`.
token (Union[bool, str, None], optional):
A valid user access token (string). Defaults to the locally saved
token, which is the recommended method for authentication (see
Expand Down Expand Up @@ -2408,7 +2405,7 @@ def dataset_info(
expand (`List[ExpandDatasetProperty_T]`, *optional*):
List properties to return in the response. When used, only the properties in the list will be returned.
This parameter cannot be used if `files_metadata` is passed.
Possible values are `"author"`, `"cardData"`, `"citation"`, `"createdAt"`, `"disabled"`, `"description"`, `"downloads"`, `"downloadsAllTime"`, `"gated"`, `"gitalyUid"`, `"lastModified"`, `"likes"`, `"paperswithcode_id"`, `"private"`, `"siblings"`, `"sha"` and `"tags"`.
Possible values are `"author"`, `"cardData"`, `"citation"`, `"createdAt"`, `"disabled"`, `"description"`, `"downloads"`, `"downloadsAllTime"`, `"gated"`, `"lastModified"`, `"likes"`, `"paperswithcode_id"`, `"private"`, `"siblings"`, `"sha"` and `"tags"`.
token (Union[bool, str, None], optional):
A valid user access token (string). Defaults to the locally saved
token, which is the recommended method for authentication (see
Expand Down Expand Up @@ -2481,7 +2478,7 @@ def space_info(
expand (`List[ExpandSpaceProperty_T]`, *optional*):
List properties to return in the response. When used, only the properties in the list will be returned.
This parameter cannot be used if `full` is passed.
Possible values are `"author"`, `"cardData"`, `"datasets"`, `"disabled"`, `"gitalyUid"`, `"lastModified"`, `"createdAt"`, `"likes"`, `"private"`, `"runtime"`, `"sdk"`, `"siblings"`, `"sha"`, `"subdomain"`, `"tags"` and `"models"`.
Possible values are `"author"`, `"cardData"`, `"datasets"`, `"disabled"`, `"lastModified"`, `"createdAt"`, `"likes"`, `"private"`, `"runtime"`, `"sdk"`, `"siblings"`, `"sha"`, `"subdomain"`, `"tags"` and `"models"`.
token (Union[bool, str, None], optional):
A valid user access token (string). Defaults to the locally saved
token, which is the recommended method for authentication (see
Expand Down
25 changes: 9 additions & 16 deletions tests/test_hf_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1716,12 +1716,11 @@ def test_list_models_expand_author(self):

def test_list_models_expand_multiple(self):
# Only the selected fields are returned
models = list(self._api.list_models(expand=["author", "downloadsAllTime", "gitalyUid"], limit=5))
models = list(self._api.list_models(expand=["author", "downloadsAllTime"], limit=5))
for model in models:
assert model.author is not None
assert model.downloads_all_time is not None
assert model.downloads is None
assert model.gitalyUid is not None # not a field except if requested explicitly

def test_list_models_expand_unexpected_value(self):
# Unexpected value => HTTP 400
Expand Down Expand Up @@ -1832,13 +1831,10 @@ def test_model_info_expand_author(self):

def test_model_info_expand_multiple(self):
# Only the selected fields are returned
model = self._api.model_info(
repo_id="HuggingFaceH4/zephyr-7b-beta", expand=["author", "downloadsAllTime", "gitalyUid"]
)
model = self._api.model_info(repo_id="HuggingFaceH4/zephyr-7b-beta", expand=["author", "downloadsAllTime"])
assert model.author == "HuggingFaceH4"
assert model.downloads is None
assert model.downloads_all_time is not None
assert model.gitalyUid is not None # not a field except if requested explicitly
assert model.created_at is None
assert model.last_modified is None

Expand Down Expand Up @@ -1949,12 +1945,11 @@ def test_list_datasets_expand_author(self):

def test_list_datasets_expand_multiple(self):
# Only the selected fields are returned
datasets = list(self._api.list_datasets(expand=["author", "downloadsAllTime", "gitalyUid"], limit=5))
datasets = list(self._api.list_datasets(expand=["author", "downloadsAllTime"], limit=5))
for dataset in datasets:
assert dataset.author is not None
assert dataset.downloads_all_time is not None
assert dataset.downloads is None
assert dataset.gitalyUid is not None # not a field except if requested explicitly

def test_list_datasets_expand_unexpected_value(self):
# Unexpected value => HTTP 400
Expand Down Expand Up @@ -2019,13 +2014,10 @@ def test_dataset_info_expand_author(self):

def test_dataset_info_expand_multiple(self):
# Only the selected fields are returned
dataset = self._api.dataset_info(
repo_id="HuggingFaceH4/no_robots", expand=["author", "downloadsAllTime", "gitalyUid"]
)
dataset = self._api.dataset_info(repo_id="HuggingFaceH4/no_robots", expand=["author", "downloadsAllTime"])
assert dataset.author == "HuggingFaceH4"
assert dataset.downloads is None
assert dataset.downloads_all_time is not None
assert dataset.gitalyUid is not None # not a field except if requested explicitly
assert dataset.created_at is None
assert dataset.last_modified is None

Expand Down Expand Up @@ -2055,11 +2047,11 @@ def test_space_info_expand_author(self):

def test_space_info_expand_multiple(self):
# Only the selected fields are returned
space = self._api.space_info(repo_id="HuggingFaceH4/zephyr-chat", expand=["author", "gitalyUid"])
space = self._api.space_info(repo_id="HuggingFaceH4/zephyr-chat", expand=["author", "likes"])
assert space.author == "HuggingFaceH4"
assert space.gitalyUid is not None # not a field except if requested explicitly
assert space.created_at is None
assert space.last_modified is None
assert space.likes is not None

def test_space_info_expand_unexpected_value(self):
# Unexpected value => HTTP 400
Expand Down Expand Up @@ -2229,10 +2221,10 @@ def test_list_spaces_expand_author(self):

def test_list_spaces_expand_multiple(self):
# Only the selected fields are returned
spaces = list(self._api.list_spaces(expand=["author", "gitalyUid"], limit=5))
spaces = list(self._api.list_spaces(expand=["author", "likes"], limit=5))
for space in spaces:
assert space.author is not None
assert space.gitalyUid is not None # not a field except if requested explicitly
assert space.likes is not None

def test_list_spaces_expand_unexpected_value(self):
# Unexpected value => HTTP 400
Expand Down Expand Up @@ -4125,6 +4117,7 @@ def _check_expand_property_is_up_to_date(self, repo_url: RepoUrl):
assert message.startswith('"expand" must be one of ')
defined_args = set(get_args(property_type))
expected_args = set(message.replace('"expand" must be one of ', "").strip("[]").split(", "))
expected_args.remove("gitalyUid") # internal one, do not document

if defined_args != expected_args:
should_be_removed = defined_args - expected_args
Expand Down

0 comments on commit 7fe286b

Please sign in to comment.