Update app.py
Browse files
app.py
CHANGED
@@ -45,6 +45,24 @@ def search_audiobooks(topic:str, limit:int=3)-> str: #it's import to specify the
|
|
45 |
})
|
46 |
return audiobooks
|
47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
@tool
|
49 |
def get_current_time_in_timezone(timezone: str) -> str:
|
50 |
"""A tool that fetches the current local time in a specified timezone.
|
@@ -82,7 +100,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
82 |
|
83 |
agent = CodeAgent(
|
84 |
model=model,
|
85 |
-
tools=[final_answer,search_audiobooks,get_current_time_in_timezone], ## add your tools here (don't remove final answer)
|
86 |
max_steps=6,
|
87 |
verbosity_level=1,
|
88 |
grammar=None,
|
|
|
45 |
})
|
46 |
return audiobooks
|
47 |
|
48 |
+
@tool
|
49 |
+
# Function to estimate if audiobook fits time constraint
|
50 |
+
def filter_by_time(audiobooks, free_time):
|
51 |
+
"""The tool is designed to match the time in terms of duration of the audiobook which is called estimated_minutes and the free time that the person have
|
52 |
+
Args:
|
53 |
+
audiobooks: the list of the audiobooks
|
54 |
+
free_time: The free time the person inform
|
55 |
+
"""
|
56 |
+
try:
|
57 |
+
if "hour" in free_time.lower():
|
58 |
+
hours = float(free_time.split()[0])
|
59 |
+
max_minutes = hours * 60
|
60 |
+
else:
|
61 |
+
max_minutes = float(free_time.split()[0])
|
62 |
+
except:
|
63 |
+
max_minutes = 180 # Default to 3 hours
|
64 |
+
return [book for book in audiobooks if book["estimated_minutes"] <= max_minutes]
|
65 |
+
|
66 |
@tool
|
67 |
def get_current_time_in_timezone(timezone: str) -> str:
|
68 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
100 |
|
101 |
agent = CodeAgent(
|
102 |
model=model,
|
103 |
+
tools=[final_answer,search_audiobooks,get_current_time_in_timezone,filter_by_time], ## add your tools here (don't remove final answer)
|
104 |
max_steps=6,
|
105 |
verbosity_level=1,
|
106 |
grammar=None,
|