Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
| 21 |
-
def
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
| 32 |
|
| 33 |
|
| 34 |
-
|
| 35 |
-
def
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
|
| 51 |
|
| 52 |
class BasicAgent:
|
|
@@ -58,12 +60,12 @@ class BasicAgent:
|
|
| 58 |
custom_role_conversions=None,
|
| 59 |
)
|
| 60 |
|
| 61 |
-
|
| 62 |
-
self.tools =
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 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(
|