Spaces:
Sleeping
Sleeping
abelluque
commited on
Commit
·
ab2a5d5
1
Parent(s):
ae7a494
y firs agent
Browse files
app.py
CHANGED
|
@@ -9,14 +9,31 @@ from Gradio_UI import GradioUI
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
-
def my_custom_tool(
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -55,7 +72,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 55 |
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[final_answer], ## add your tools here (don't remove final answer)
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
|
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
+
def my_custom_tool(location: str, utc_offset: int) -> str:
|
| 13 |
+
"""Generates relevant information about a given location's timezone, including possible timezones and major cities."""
|
| 14 |
+
try:
|
| 15 |
+
# Determine possible timezone based on UTC offset
|
| 16 |
+
all_timezones = pytz.all_timezones
|
| 17 |
+
matching_timezones = [tz for tz in all_timezones if datetime.datetime.now(pytz.timezone(tz)).utcoffset().total_seconds() / 3600 == utc_offset]
|
| 18 |
+
|
| 19 |
+
if not matching_timezones:
|
| 20 |
+
return f"No matching timezones found for UTC offset {utc_offset}."
|
| 21 |
+
|
| 22 |
+
# Mapping of some major cities to their timezones
|
| 23 |
+
city_timezone_map = {
|
| 24 |
+
"New York": "America/New_York",
|
| 25 |
+
"Los Angeles": "America/Los_Angeles",
|
| 26 |
+
"London": "Europe/London",
|
| 27 |
+
"Paris": "Europe/Paris",
|
| 28 |
+
"Tokyo": "Asia/Tokyo",
|
| 29 |
+
"Sydney": "Australia/Sydney"
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
matching_cities = [city for city, tz in city_timezone_map.items() if tz in matching_timezones]
|
| 33 |
+
|
| 34 |
+
return f"Possible timezones for {location} with UTC offset {utc_offset}: {', '.join(matching_timezones)}. Major cities: {', '.join(matching_cities) if matching_cities else 'No major cities found.'}"
|
| 35 |
+
except Exception as e:
|
| 36 |
+
return f"Error processing location '{location}': {str(e)}"
|
| 37 |
|
| 38 |
@tool
|
| 39 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 72 |
|
| 73 |
agent = CodeAgent(
|
| 74 |
model=model,
|
| 75 |
+
tools=[final_answer, my_custom_tool, get_current_time_in_timezone], ## add your tools here (don't remove final answer)
|
| 76 |
max_steps=6,
|
| 77 |
verbosity_level=1,
|
| 78 |
grammar=None,
|