Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -32,6 +32,55 @@ def suggest_test_cases(topic: str) -> list:
|
|
| 32 |
"""
|
| 33 |
return generate_test_cases(topic)
|
| 34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
@tool
|
| 36 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 37 |
"""A tool that fetches the current local time in a specified timezone.
|
|
@@ -69,7 +118,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 69 |
|
| 70 |
agent = CodeAgent(
|
| 71 |
model=model,
|
| 72 |
-
tools=[final_answer, suggest_test_cases], ## add your tools here (don't remove final answer)
|
| 73 |
max_steps=6,
|
| 74 |
verbosity_level=1,
|
| 75 |
grammar=None,
|
|
|
|
| 32 |
"""
|
| 33 |
return generate_test_cases(topic)
|
| 34 |
|
| 35 |
+
@tool
|
| 36 |
+
def time_difference(ts1: str, tz1: str, ts2: str, tz2: str, signed: bool = False) -> str:
|
| 37 |
+
"""
|
| 38 |
+
Calculate the duration between two timestamps in different timezones.
|
| 39 |
+
|
| 40 |
+
Args:
|
| 41 |
+
ts1: First timestamp string in 'YYYY-MM-DD HH:MM:SS' format.
|
| 42 |
+
tz1: Timezone of ts1 (e.g. 'UTC', 'America/New_York').
|
| 43 |
+
ts2: Second timestamp string in 'YYYY-MM-DD HH:MM:SS' format.
|
| 44 |
+
tz2: Timezone of ts2.
|
| 45 |
+
signed: If True, return negative values when ts2 is earlier than ts1.
|
| 46 |
+
If False, return absolute difference.
|
| 47 |
+
|
| 48 |
+
Returns:
|
| 49 |
+
A formatted string showing the difference in days, hours, minutes, and seconds.
|
| 50 |
+
"""
|
| 51 |
+
try:
|
| 52 |
+
# Parse timestamps
|
| 53 |
+
fmt = "%Y-%m-%d %H:%M:%S"
|
| 54 |
+
dt1_naive = datetime.datetime.strptime(ts1, fmt)
|
| 55 |
+
dt2_naive = datetime.datetime.strptime(ts2, fmt)
|
| 56 |
+
|
| 57 |
+
# Apply timezones
|
| 58 |
+
dt1 = pytz.timezone(tz1).localize(dt1_naive)
|
| 59 |
+
dt2 = pytz.timezone(tz2).localize(dt2_naive)
|
| 60 |
+
|
| 61 |
+
# Convert to UTC for accurate comparison
|
| 62 |
+
dt1_utc = dt1.astimezone(pytz.UTC)
|
| 63 |
+
dt2_utc = dt2.astimezone(pytz.UTC)
|
| 64 |
+
|
| 65 |
+
# Difference
|
| 66 |
+
diff = dt2_utc - dt1_utc
|
| 67 |
+
|
| 68 |
+
if not signed:
|
| 69 |
+
diff = abs(diff)
|
| 70 |
+
|
| 71 |
+
# Break down difference
|
| 72 |
+
total_seconds = int(diff.total_seconds())
|
| 73 |
+
days = total_seconds // 86400
|
| 74 |
+
hours = (total_seconds % 86400) // 3600
|
| 75 |
+
minutes = (total_seconds % 3600) // 60
|
| 76 |
+
seconds = total_seconds % 60
|
| 77 |
+
|
| 78 |
+
result = f"Difference: {days}d {hours}h {minutes}m {seconds}s (total {total_seconds} seconds)"
|
| 79 |
+
return result
|
| 80 |
+
|
| 81 |
+
except Exception as e:
|
| 82 |
+
return f"Error calculating time difference: {str(e)}"
|
| 83 |
+
|
| 84 |
@tool
|
| 85 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 86 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
|
| 118 |
|
| 119 |
agent = CodeAgent(
|
| 120 |
model=model,
|
| 121 |
+
tools=[final_answer, suggest_test_cases, time_difference], ## add your tools here (don't remove final answer)
|
| 122 |
max_steps=6,
|
| 123 |
verbosity_level=1,
|
| 124 |
grammar=None,
|