DOC:
Problem
The documentation currently uses the direction=-1 argument when calling huggingface_hub.list_models() to retrieve the most downloaded model for a given task.
For example:
most_downloaded_model = next(
iter(
list_models(
filter=task,
sort="downloads",
direction=-1
)
)
)With the current version of huggingface_hub, HfApi.list_models() no longer accepts the direction argument. Running the example results in:
TypeError: HfApi.list_models() got an unexpected keyword argument 'direction'This means users following the documentation directly may encounter an error even though the overall example is otherwise correct.
Location of the documentation
- Function/Class/Method name:
huggingface_hub.list_models - URL: https://huggingface.co/docs/smolagents/tutorials/tools
The outdated call appears in the example that creates a tool for retrieving the most downloaded model for a given Hugging Face task.
Suggested improvement
Update the example to use the currently supported list_models() API.
For example:
most_downloaded_model = next(
iter(
list_models(
filter=task,
sort="downloads",
limit=1
)
)
)This removes the unsupported direction argument and uses limit=1, since the example only needs the first model from the results sorted by downloads.
Updating this example would prevent users from encountering a TypeError when following the documentation with recent versions of huggingface_hub.
Additional context (optional) I encountered this issue while following the smolagents documentation and creating the example tool locally.
The tool was called successfully by CodeAgent, but execution failed with:
TypeError: HfApi.list_models() got an unexpected keyword argument 'direction'I also searched the existing issues. Some issues, such as #574, #250, and #748, include or reference the same older example, but I did not find an issue specifically addressing the incompatibility of the direction argument with the current huggingface_hub.list_models() API.
Checklist
- I have searched the existing issues and have not found a similar issue.
- I am willing to work on this issue and submit a pull request. (optional)
Source: huggingface/smolagents