blade57 commited on
Commit
50a130f
·
verified ·
1 Parent(s): 9845a71

Update tools.py

Browse files
Files changed (1) hide show
  1. tools.py +53 -0
tools.py CHANGED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from smolagents import DuckDuckGoSearchTool
2
+ from smolagents import Tool
3
+ import random
4
+ from huggingface_hub import list_models
5
+
6
+
7
+ # Initialize the DuckDuckGo search tool
8
+ #search_tool = DuckDuckGoSearchTool()
9
+
10
+ class WeatherInfoTool(Tool):
11
+ name = "weather_info"
12
+ description = "Fetches dummy weather information for a given location."
13
+ inputs = {
14
+ "location": {
15
+ "type": "string",
16
+ "description": "The location to get weather information for."
17
+ }
18
+ }
19
+ output_type = "string"
20
+
21
+ def forward(self, location: str):
22
+ weather_conditions = [
23
+ {"condition": "Rainy", "temp_f": 55},
24
+ {"condition": "Sunny", "temp_f": 75},
25
+ {"condition": "Cloudy", "temp_f": 61}
26
+ ]
27
+ # randomly return
28
+ data = random.choice(weather_conditions)
29
+ return f"Weather in {location}: {data['condition']}, {data['temp_f']}°F"
30
+
31
+ class HubStatsTool(Tool):
32
+ name = "hub_stats"
33
+ description = "Fetches the most downloaded model from a specific author on the Hugging Face Hub."
34
+ inputs = {
35
+ "author": {
36
+ "type": "string",
37
+ "description": "The username of the model author/organization to find models from."
38
+ }
39
+ }
40
+ output_type = "string"
41
+
42
+ def forward(self, author: str):
43
+ try:
44
+ # List models from the specified author, sorted by downloads
45
+ models = list(list_models(author=author, sort="downloads", direction=-1, limit=1))
46
+
47
+ if models:
48
+ model = models[0]
49
+ return f"The most downloaded model by {author} is {model.id} with {model.downloads:,} downloads."
50
+ else:
51
+ return f"No models found for author {author}."
52
+ except Exception as e:
53
+ return f"Error fetching models for {author}: {str(e)}"