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

Added HuggingFaceTool to Explore HF Hub #97

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
29 changes: 29 additions & 0 deletions src/openagi/actions/tools/huggingface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from openagi.actions.base import ConfigurableAction
from pydantic import Field
import json

try:
from huggingface_hub import HfApi
except ImportError:
raise Exception("Install huggingface_hub with cmd `pip install huggingface`")

class HuggingFaceTool(ConfigurableAction):
"""
Tool for exploring Hugging Face models and datasets.
"""
query: str = Field(..., description="Dataset or model name to search on Hugging Face.")

def execute(self) -> str:
api = HfApi()
results_dict = {}

models = api.list_models(search=self.query, limit=15)
datasets = api.list_datasets(search=self.query, limit=15)

for model in models:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you also extract other details as well. just model ID is very limited context given to the LLM

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The API returns the following details:

ModelInfo(id='prithivMLmods/Qwen2-VL-Math-Prase-2B-Instruct', author=None, sha=None,
created_at=datetime.datetime(2024, 12, 19, 4, 38, 46, tzinfo=datetime.timezone.utc),
last_modified=None, private=False, disabled=None, downloads=248, downloads_all_time=None,
gated=None, gguf=None, inference=None, likes=8, library_name='transformers',
tags=['transformers', 'safetensors', 'qwen2_vl', 'image-text-to-text', 'conversational', 'en',
'base_model:Qwen/Qwen2-VL-2B-Instruct', 'base_model:finetune:Qwen/Qwen2-VL-2B-Instruct',
'license:apache-2.0', 'text-generation-inference', 'endpoints_compatible', 'region:us'],
pipeline_tag='image-text-to-text', mask_token=None, card_data=None, widget_data=None, model_index=None,
config=None, transformers_info=None, trending_score=8, siblings=None, spaces=None,
safetensors=None, security_repo_status=None)

I think we can add:

  • tags
  • pipeline_tag
  • config
  • transfotmers_info

@tarun-aiplanet please let me know which one's to add and i'll make the changes.

results_dict[model.modelId] = f"https://huggingface.co/{model.modelId}"

for dataset in datasets:
results_dict[dataset.id] = f"https://huggingface.co/datasets/{dataset.id}"

return json.dumps(results_dict)
Loading