def __call__(self, task: str):
    model = next(iter(list_models(filter=task, sort="downloads", direction=-1)))
    return model.id

We now have our tool handy. Save it in a file and import it from your main script. Let's name this file
model_downloads.py, so the resulting import code looks like this:
thon
from model_downloads import HFModelDownloadsTool
tool = HFModelDownloadsTool()