File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
src/openagi/actions/tools Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change 1+ from openagi .actions .base import ConfigurableAction
2+ from pydantic import Field
3+ import json
4+
5+ try :
6+ from huggingface_hub import HfApi
7+ except ImportError :
8+ raise Exception ("Install huggingface_hub with cmd `pip install huggingface`" )
9+
10+ class HuggingFaceTool (ConfigurableAction ):
11+ """
12+ Tool for exploring Hugging Face models and datasets.
13+ """
14+ query : str = Field (..., description = "Dataset or model name to search on Hugging Face." )
15+
16+ def execute (self ) -> str :
17+ api = HfApi ()
18+ results_dict = {}
19+
20+ models = api .list_models (search = self .query , limit = 15 )
21+ datasets = api .list_datasets (search = self .query , limit = 15 )
22+
23+ for model in models :
24+ results_dict [model .modelId ] = f"https://huggingface.co/{ model .modelId } "
25+
26+ for dataset in datasets :
27+ results_dict [dataset .id ] = f"https://huggingface.co/datasets/{ dataset .id } "
28+
29+ return json .dumps (results_dict )
You can’t perform that action at this time.
0 commit comments