wlchee commited on
Commit
3206387
·
verified ·
1 Parent(s): 112a802

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -34
app.py CHANGED
@@ -17,36 +17,38 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
17
  # --- Basic Agent Definition ---
18
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
19
 
20
- @tool
21
- def get_current_time_in_timezone(timezone: str) -> str:
22
- """Fetches the current local time in a specified timezone.
23
- Args:
24
- timezone: A string representing a valid timezone (e.g., 'America/New_York').
25
- """
26
- try:
27
- tz = pytz.timezone(timezone)
28
- local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
29
- return f"The current local time in {timezone} is: {local_time}"
30
- except Exception as e:
31
- return f"Error fetching time for timezone '{timezone}': {str(e)}"
 
 
32
 
33
 
34
- @tool
35
- def wikipedia_search(query: str, sentences: int = 2) -> str:
36
- """Searches Wikipedia for information.
37
- Args:
38
- query: The search term.
39
- sentences: Number of summary sentences to return (default: 2).
40
- """
41
- try:
42
- return wikipedia.summary(query, sentences=sentences)
43
- except wikipedia.exceptions.DisambiguationError as e:
44
- return f"Disambiguation error: {e.options}"
45
- except wikipedia.exceptions.PageError:
46
- return "No Wikipedia page found for this query."
47
- except Exception as e:
48
- return f"Wikipedia search failed: {str(e)}"
49
-
50
 
51
 
52
  class BasicAgent:
@@ -58,12 +60,12 @@ class BasicAgent:
58
  custom_role_conversions=None,
59
  )
60
 
61
- self.search_tool = DuckDuckGoSearchTool()
62
- self.tools = {
63
- "current_time": get_current_time_in_timezone,
64
- "wikipedia": wikipedia_search,
65
- "search": self.search_tool
66
- }
67
 
68
 
69
  self.agent = CodeAgent(
 
17
  # --- Basic Agent Definition ---
18
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
19
 
20
+ class CurrentTimeTool(Tool):
21
+ def __init__(self):
22
+ super().__init__(
23
+ name="get_current_time_in_timezone",
24
+ description="Fetches the current local time in a specified timezone."
25
+ )
26
+
27
+ def __call__(self, timezone: str) -> str:
28
+ try:
29
+ tz = pytz.timezone(timezone)
30
+ local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
31
+ return f"The current local time in {timezone} is: {local_time}"
32
+ except Exception as e:
33
+ return f"Error fetching time for timezone '{timezone}': {str(e)}"
34
 
35
 
36
+ class WikipediaTool(Tool):
37
+ def __init__(self):
38
+ super().__init__(
39
+ name="wikipedia_search",
40
+ description="Searches Wikipedia for information."
41
+ )
42
+
43
+ def __call__(self, query: str, sentences: int = 2) -> str:
44
+ try:
45
+ return wikipedia.summary(query, sentences=sentences)
46
+ except wikipedia.exceptions.DisambiguationError as e:
47
+ return f"Disambiguation error: {e.options}"
48
+ except wikipedia.exceptions.PageError:
49
+ return "No Wikipedia page found for this query."
50
+ except Exception as e:
51
+ return f"Wikipedia search failed: {str(e)}"
52
 
53
 
54
  class BasicAgent:
 
60
  custom_role_conversions=None,
61
  )
62
 
63
+
64
+ self.tools = [
65
+ current_time(), #get_current_time_in_timezone,
66
+ wikipedia(), #wikipedia_search,
67
+ DuckDuckGoSearchTool()
68
+ ]
69
 
70
 
71
  self.agent = CodeAgent(