dlaima commited on
Commit
a781809
·
verified ·
1 Parent(s): ad9bb76

Update tools.py

Browse files
Files changed (1) hide show
  1. tools.py +14 -14
tools.py CHANGED
@@ -5,9 +5,6 @@ from huggingface_hub import list_models
5
  import requests
6
 
7
 
8
- # Initialize the DuckDuckGo search tool
9
- #search_tool = DuckDuckGoSearchTool()
10
-
11
  # --------- Weather Info Tool ---------
12
  class WeatherInfoTool(Tool):
13
  name = "weather_info"
@@ -27,10 +24,8 @@ class WeatherInfoTool(Tool):
27
  {"condition": "Clear", "temp_c": 25},
28
  {"condition": "Windy", "temp_c": 20}
29
  ]
30
- # Randomly select a weather condition
31
  data = random.choice(weather_conditions)
32
- return f"Weather in {location}: {data['condition']}, {data['temp_c']}°C"
33
-
34
 
35
 
36
  # --------- Hugging Face Hub Stats Tool ---------
@@ -47,16 +42,19 @@ class HubStatsTool(Tool):
47
 
48
  def forward(self, author: str):
49
  try:
50
- # List models from the specified author, sorted by downloads
51
  models = list(list_models(author=author, sort="downloads", direction=-1, limit=1))
52
-
53
  if models:
54
  model = models[0]
55
- return f"The most downloaded model by {author} is {model.id} with {model.downloads:,} downloads."
 
 
 
 
 
56
  else:
57
- return f"No models found for author {author}."
58
  except Exception as e:
59
- return f"Error fetching models for {author}: {str(e)}"
60
 
61
 
62
  # --------- News Search Tool using ContextualWeb API ---------
@@ -93,11 +91,13 @@ class NewsSearchTool(Tool):
93
  articles = response.json().get("value", [])
94
 
95
  if not articles:
96
- return f"No news articles found for topic '{topic}'."
97
 
98
  return "\n\n".join(
99
- f"📰 {a['title']}\n{a['description'] or ''}\nSource: {a['provider']['name']}\nLink: {a['url']}"
 
100
  for a in articles
101
  )
102
  except Exception as e:
103
- return f"Error retrieving news for topic '{topic}': {str(e)}"
 
 
5
  import requests
6
 
7
 
 
 
 
8
  # --------- Weather Info Tool ---------
9
  class WeatherInfoTool(Tool):
10
  name = "weather_info"
 
24
  {"condition": "Clear", "temp_c": 25},
25
  {"condition": "Windy", "temp_c": 20}
26
  ]
 
27
  data = random.choice(weather_conditions)
28
+ return f"🌦️ Weather in **{location}**: {data['condition']}, {data['temp_c']}°C"
 
29
 
30
 
31
  # --------- Hugging Face Hub Stats Tool ---------
 
42
 
43
  def forward(self, author: str):
44
  try:
 
45
  models = list(list_models(author=author, sort="downloads", direction=-1, limit=1))
 
46
  if models:
47
  model = models[0]
48
+ return (
49
+ f"📊 Most downloaded model by **{author}**:\n"
50
+ f"**Model ID**: {model.id}\n"
51
+ f"**Downloads**: {model.downloads:,}\n"
52
+ f"[View on Hugging Face](https://huggingface.co/{model.id})"
53
+ )
54
  else:
55
+ return f"No models found for author **{author}**."
56
  except Exception as e:
57
+ return f"⚠️ Error fetching models for **{author}**: {str(e)}"
58
 
59
 
60
  # --------- News Search Tool using ContextualWeb API ---------
 
91
  articles = response.json().get("value", [])
92
 
93
  if not articles:
94
+ return f"No news articles found for topic **{topic}**."
95
 
96
  return "\n\n".join(
97
+ f"📰 **{a['title']}**\n{a['description'] or '_No description provided_'}\n"
98
+ f"Source: {a['provider']['name']}\n[Read more]({a['url']})"
99
  for a in articles
100
  )
101
  except Exception as e:
102
+ return f"⚠️ Error retrieving news for **{topic}**: {str(e)}"
103
+