Skip to content

Commit

Permalink
Remove date
Browse files Browse the repository at this point in the history
  • Loading branch information
hlky committed Oct 9, 2024
1 parent b6fdc91 commit a4826e4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 27 deletions.
4 changes: 4 additions & 0 deletions src/huggingface_hub/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@
"list_metrics",
"list_models",
"list_organization_members",
"list_papers",
"list_pending_access_requests",
"list_rejected_access_requests",
"list_repo_commits",
Expand All @@ -230,6 +231,7 @@
"merge_pull_request",
"model_info",
"move_repo",
"paper_info",
"parse_safetensors_file_metadata",
"pause_inference_endpoint",
"pause_space",
Expand Down Expand Up @@ -733,6 +735,7 @@ def __dir__():
list_metrics, # noqa: F401
list_models, # noqa: F401
list_organization_members, # noqa: F401
list_papers, # noqa: F401
list_pending_access_requests, # noqa: F401
list_rejected_access_requests, # noqa: F401
list_repo_commits, # noqa: F401
Expand All @@ -747,6 +750,7 @@ def __dir__():
merge_pull_request, # noqa: F401
model_info, # noqa: F401
move_repo, # noqa: F401
paper_info, # noqa: F401
parse_safetensors_file_metadata, # noqa: F401
pause_inference_endpoint, # noqa: F401
pause_space, # noqa: F401
Expand Down
29 changes: 2 additions & 27 deletions src/huggingface_hub/hf_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9740,39 +9740,19 @@ def list_user_following(self, username: str, token: Union[bool, str, None] = Non
def list_papers(
self,
*,
date: Optional[str] = None,
query: Optional[str] = None,
token: Union[bool, str, None] = None,
) -> Iterable[PaperInfo]:
"""
List daily papers on the Hugging Face Hub, given a date or a search query.
Args:
date (`str`, *optional*):
The date to retrieve papers for, in the format 'YYYY-MM-DD'.
If provided, returns papers submitted on this date.
query (`str`, *optional*):
A search query string to find papers.
If provided, returns papers that match the query.
Returns:
`Iterable[PaperInfo]`: an iterable of [`huggingface_hub.hf_api.PaperInfo`] objects.
Raises:
[`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError):
HTTP 400 if the date is invalid.
[`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError):
If neither `date` nor `query` is provided.
Example usage with the `date` argument:
```python
>>> from huggingface_hub import HfApi
>>> api = HfApi()
# List all papers submitted on a specific date
>>> api.list_papers(date="2024-09-17")
```
Example usage with the `query` argument:
```python
Expand All @@ -9784,19 +9764,14 @@ def list_papers(
>>> api.list_papers(query="attention")
```
"""
if date is None and query is None:
raise ValueError("Provide one of `date` or `query`.")
path = f"{self.endpoint}/api/papers/search"
params = {}
if date:
params["date"] = date
if query:
params["q"] = query
r = get_session().get(
path,
params=params,

headers=self._build_hf_headers(token=token),
headers=self._build_hf_headers(token=token),
)
hf_raise_for_status(r)
for paper in r.json():
Expand Down

0 comments on commit a4826e4

Please sign in to comment.