rakesh-dvg commited on
Commit
ff9300a
·
verified ·
1 Parent(s): 2e2dc98

Upload tools.py

Browse files
Files changed (1) hide show
  1. tools.py +43 -0
tools.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain.tools import Tool
2
+ from langchain_community.tools.tavily_search import TavilySearchResults
3
+ from huggingface_hub import list_models
4
+ import random
5
+ import os
6
+ from dotenv import load_dotenv
7
+ load_dotenv()
8
+
9
+ search_tool = TavilySearchResults(tavily_api_key=os.getenv("TAVILY_API_KEY"))
10
+
11
+
12
+ def get_weather_info(location: str) -> str:
13
+ weather_conditions = [
14
+ {"condition": "Rainy", "temp_c": 15},
15
+ {"condition": "Clear", "temp_c": 25},
16
+ {"condition": "Windy", "temp_c": 20}
17
+ ]
18
+ data = random.choice(weather_conditions)
19
+ return f"Weather in {location}: {data['condition']}, {data['temp_c']}°C"
20
+
21
+ weather_info_tool = Tool(
22
+ name="get_weather_info",
23
+ func=get_weather_info,
24
+ description="Returns dummy weather information for a given location."
25
+ )
26
+
27
+
28
+ def get_hub_stats(author: str) -> str:
29
+ try:
30
+ models = list(list_models(author=author, sort="downloads", direction=-1, limit=1))
31
+ if models:
32
+ model = models[0]
33
+ return f"The most downloaded model by {author} is {model.id} with {model.downloads:,} downloads."
34
+ else:
35
+ return f"No models found for author {author}."
36
+ except Exception as e:
37
+ return f"Error: {str(e)}"
38
+
39
+ hub_stats_tool = Tool(
40
+ name="get_hub_stats",
41
+ func=get_hub_stats,
42
+ description="Gets the most downloaded model by a Hugging Face author."
43
+ )