File tree Expand file tree Collapse file tree 2 files changed +12
-8
lines changed Expand file tree Collapse file tree 2 files changed +12
-8
lines changed Original file line number Diff line number Diff line change 11from __future__ import annotations
2- from langchain .tools import BaseTool
2+ from langchain_community .tools import BaseTool
33
44class HuggingFaceHubTool (BaseTool ):
55 """Base tool for interacting with the Hugging Face Hub."""
@@ -19,7 +19,11 @@ def __init__(self, **kwargs):
1919 ) from e
2020
2121 def _run (self , query : str ) -> str :
22- """Use the tool."""
22+ """Use the tool to search Hugging Face Hub.
23+
24+ Args:
25+ query: The search query string to find models or datasets.
26+ """
2327 try :
2428 if self .task == "models" :
2529 results_list = self .api_client .list_models (
@@ -44,8 +48,12 @@ def _run(self, query: str) -> str:
4448
4549 return "\n \n ---\n \n " .join (formatted_results )
4650
51+ except ConnectionError as e :
52+ return f"Error: Failed to connect to HuggingFace API. { str (e )} "
53+ except ValueError as e :
54+ return f"Error: Invalid input to HuggingFace API. { str (e )} "
4755 except Exception as e :
48- return f"An error occurred : { e } "
56+ return f"Unexpected error when calling HuggingFace API : { str ( e ) } "
4957
5058 async def _arun (self , query : str ) -> str :
5159 """Use the tool asynchronously."""
Original file line number Diff line number Diff line change @@ -26,17 +26,13 @@ version = "0.3.29"
2626description = " Community contributed LangChain integrations."
2727readme = " README.md"
2828
29- [project .optional-dependencies ]
30- all = [
31- " huggingface-hub" ,
32- ]
33-
3429[project .urls ]
3530"Source Code" = " https://github.com/langchain-ai/langchain-community/tree/main/libs/community"
3631"Release Notes" = " https://github.com/langchain-ai/langchain/releases?q=tag%3A%22langchain-community%3D%3D0%22&expanded=true"
3732repository = " https://github.com/langchain-ai/langchain-community"
3833
3934[dependency-groups ]
35+ huggingface = [" huggingface-hub" ]
4036test = [
4137 " pytest<9.0.0,>=8.4.1" ,
4238 " pytest-cov<7.0.0,>=6.2.1" ,
You can’t perform that action at this time.
0 commit comments