Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for createdAt field #1816

Merged
merged 1 commit into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/huggingface_hub/hf_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,9 @@ class ModelInfo:
Author of the dataset.
sha (`str`, *optional*):
Repo SHA at this particular revision.
created_at (`datetime`, *optional*):
Date of creation of the repo on the Hub. Note that the lowest value is `2022-03-02T23:29:04.000Z`,
corresponding to the date when we began to store creation dates.
last_modified (`datetime`, *optional*):
Date of last commit to the repo.
private (`bool`):
Expand Down Expand Up @@ -485,6 +488,7 @@ class ModelInfo:
id: str
author: Optional[str]
sha: Optional[str]
created_at: Optional[datetime]
last_modified: Optional[datetime]
private: bool
gated: Optional[bool]
Expand All @@ -510,6 +514,8 @@ def __init__(self, **kwargs):
self.sha = kwargs.pop("sha", None)
last_modified = kwargs.pop("lastModified", None) or kwargs.pop("last_modified", None)
self.last_modified = parse_datetime(last_modified) if last_modified else None
created_at = kwargs.pop("createdAt", None) or kwargs.pop("created_at", None)
self.created_at = parse_datetime(created_at) if created_at else None
self.private = kwargs.pop("private")
self.gated = kwargs.pop("gated", None)
self.disabled = kwargs.pop("disabled", None)
Expand Down Expand Up @@ -574,6 +580,9 @@ class DatasetInfo:
Author of the dataset.
sha (`str`):
Repo SHA at this particular revision.
created_at (`datetime`, *optional*):
Date of creation of the repo on the Hub. Note that the lowest value is `2022-03-02T23:29:04.000Z`,
corresponding to the date when we began to store creation dates.
last_modified (`datetime`, *optional*):
Date of last commit to the repo.
private (`bool`):
Expand All @@ -597,6 +606,7 @@ class DatasetInfo:
id: str
author: Optional[str]
sha: Optional[str]
created_at: Optional[datetime]
last_modified: Optional[datetime]
private: bool
gated: Optional[bool]
Expand All @@ -612,6 +622,8 @@ def __init__(self, **kwargs):
self.id = kwargs.pop("id")
self.author = kwargs.pop("author", None)
self.sha = kwargs.pop("sha", None)
created_at = kwargs.pop("createdAt", None) or kwargs.pop("created_at", None)
self.created_at = parse_datetime(created_at) if created_at else None
last_modified = kwargs.pop("lastModified", None) or kwargs.pop("last_modified", None)
self.last_modified = parse_datetime(last_modified) if last_modified else None
self.private = kwargs.pop("private")
Expand Down Expand Up @@ -666,6 +678,9 @@ class SpaceInfo:
Author of the Space.
sha (`str`, *optional*):
Repo SHA at this particular revision.
created_at (`datetime`, *optional*):
Date of creation of the repo on the Hub. Note that the lowest value is `2022-03-02T23:29:04.000Z`,
corresponding to the date when we began to store creation dates.
last_modified (`datetime`, *optional*):
Date of last commit to the repo.
private (`bool`):
Expand Down Expand Up @@ -699,6 +714,7 @@ class SpaceInfo:
id: str
author: Optional[str]
sha: Optional[str]
created_at: Optional[datetime]
last_modified: Optional[datetime]
private: bool
gated: Optional[bool]
Expand All @@ -718,6 +734,8 @@ def __init__(self, **kwargs):
self.id = kwargs.pop("id")
self.author = kwargs.pop("author", None)
self.sha = kwargs.pop("sha", None)
created_at = kwargs.pop("createdAt", None) or kwargs.pop("created_at", None)
self.created_at = parse_datetime(created_at) if created_at else None
last_modified = kwargs.pop("lastModified", None) or kwargs.pop("last_modified", None)
self.last_modified = parse_datetime(last_modified) if last_modified else None
self.private = kwargs.pop("private")
Expand Down
3 changes: 3 additions & 0 deletions tests/test_hf_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import datetime
import os
import re
import shutil
Expand Down Expand Up @@ -1538,6 +1539,8 @@ def test_model_info(self):
model = self._api.model_info(repo_id=DUMMY_MODEL_ID)
self.assertIsInstance(model, ModelInfo)
self.assertNotEqual(model.sha, DUMMY_MODEL_ID_REVISION_ONE_SPECIFIC_COMMIT)
self.assertEqual(model.created_at, datetime.datetime(2022, 3, 2, 23, 29, 5, tzinfo=datetime.timezone.utc))

# One particular commit (not the top of `main`)
model = self._api.model_info(repo_id=DUMMY_MODEL_ID, revision=DUMMY_MODEL_ID_REVISION_ONE_SPECIFIC_COMMIT)
self.assertIsInstance(model, ModelInfo)
Expand Down
Loading