Basilbaasi commited on
Commit
4a757ea
·
verified ·
1 Parent(s): 8c5c24b

updated app.py

Browse files
Files changed (1) hide show
  1. app.py +149 -10
app.py CHANGED
@@ -20,18 +20,151 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
20
 
21
  @tool
22
  def get_current_time_in_timezone(timezone: str) -> str:
23
- """A tool that fetches the current local time in a specified timezone.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  Args:
25
- timezone: A string representing a valid timezone (e.g., 'America/New_York').
 
 
 
 
 
 
 
 
 
 
 
26
  """
27
  try:
28
- # Create timezone object
29
  tz = pytz.timezone(timezone)
30
- # Get current time in that timezone
31
- local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
32
- return f"The current local time in {timezone} is: {local_time}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  except Exception as e:
34
- return f"Error fetching time for timezone '{timezone}': {str(e)}"
35
 
36
 
37
  final_answer = FinalAnswerTool()
@@ -55,9 +188,15 @@ 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,
62
  planning_interval=None,
63
  name=None,
 
20
 
21
  @tool
22
  def get_current_time_in_timezone(timezone: str) -> str:
23
+ """
24
+ Retrieve the current local date and time for a specified timezone.
25
+
26
+ This tool should be used whenever the user asks about:
27
+ - The current time in a city, country, or region.
28
+ - Timezone conversions.
29
+ - Scheduling meetings across different regions.
30
+ - Determining local time before performing an action.
31
+
32
+ Accepted timezone format:
33
+ - Asia/Kolkata
34
+ - America/New_York
35
+ - Europe/London
36
+ - Asia/Tokyo
37
+ - Australia/Sydney
38
+
39
  Args:
40
+ timezone: A valid IANA timezone identifier.
41
+
42
+ Returns:
43
+ A formatted string containing the current local date and time
44
+ in the requested timezone.
45
+
46
+ Example:
47
+ get_current_time_in_timezone("Asia/Kolkata")
48
+
49
+ Expected Output:
50
+ Current date and time in Asia/Kolkata:
51
+ 2026-06-22 14:35:10
52
  """
53
  try:
 
54
  tz = pytz.timezone(timezone)
55
+
56
+ current_time = datetime.datetime.now(tz)
57
+
58
+ return (
59
+ f"Current date and time in {timezone}:\n"
60
+ f"{current_time.strftime('%Y-%m-%d %H:%M:%S')}"
61
+ )
62
+
63
+ except Exception as e:
64
+ return f"Error: {str(e)}"
65
+
66
+ @tool
67
+ def web_search(query: str) -> str:
68
+ """
69
+ Search the public internet using DuckDuckGo and return relevant search results.
70
+
71
+ This tool should be used whenever up-to-date or real-time information is needed,
72
+ including current events, recent news, company information, software releases,
73
+ technical documentation, API references, research topics, tutorials, market trends,
74
+ product information, or facts that may have changed after the model's training cutoff.
75
+
76
+ The tool performs a DuckDuckGo web search and returns the most relevant results,
77
+ including the page title, summary snippet, and source URL.
78
+
79
+ Use this tool when:
80
+ - The user asks for recent or current information.
81
+ - The user asks about news, events, announcements, or updates.
82
+ - The user requests information about websites, companies, products, or services.
83
+ - Additional verification is needed before answering.
84
+ - The user explicitly asks to search the web.
85
+
86
+ Do NOT use this tool when:
87
+ - The answer can be provided from general knowledge alone.
88
+ - The user requests creative writing, brainstorming, or opinion generation.
89
+ - The information is already available in the conversation context.
90
+
91
+ Args:
92
+ query: A clear and specific search query describing the information
93
+ to retrieve. Examples:
94
+ - "Latest OpenAI announcements"
95
+ - "Python 3.14 release features"
96
+ - "Current weather in Kochi"
97
+ - "SmolAgents documentation"
98
+
99
+ Returns:
100
+ A formatted string containing the most relevant search results.
101
+ Each result includes:
102
+ - Title
103
+ - Short description/snippet
104
+ - Source URL
105
+
106
+ Examples:
107
+ >>> web_search("Latest AI agent frameworks")
108
+ Returns a list of recent web results about AI agent frameworks.
109
+
110
+ >>> web_search("Qwen3 model release")
111
+ Returns search results related to the Qwen3 model release.
112
+
113
+ >>> web_search("FastAPI documentation")
114
+ Returns links and summaries for FastAPI documentation.
115
+ """
116
+ try:
117
+ results = []
118
+
119
+ with DDGS() as ddgs:
120
+ for r in ddgs.text(query, max_results=5):
121
+ results.append(
122
+ f"Title: {r['title']}\n"
123
+ f"Body: {r['body']}\n"
124
+ f"URL: {r['href']}\n"
125
+ )
126
+
127
+ return "\n\n".join(results)
128
+
129
+ except Exception as e:
130
+ return f"Search Error: {e}"
131
+
132
+
133
+ @tool
134
+ def get_weather(city: str) -> str:
135
+ """
136
+ Get the current weather for a city.
137
+
138
+ Use this tool whenever the user asks:
139
+ - Weather information
140
+ - Temperature
141
+ - Rain forecasts
142
+ - Climate conditions
143
+ - Outdoor planning questions
144
+
145
+ Args:
146
+ city: Name of a city.
147
+
148
+ Returns:
149
+ Current weather conditions and temperature.
150
+
151
+ Example:
152
+ get_weather("Kochi")
153
+
154
+ Example Questions:
155
+ - What's the weather in Kochi?
156
+ - Is it raining in London?
157
+ - Current temperature in Tokyo
158
+ """
159
+ try:
160
+ url = f"https://wttr.in/{city}?format=3"
161
+
162
+ response = requests.get(url)
163
+
164
+ return response.text
165
+
166
  except Exception as e:
167
+ return f"Weather lookup failed: {str(e)}"
168
 
169
 
170
  final_answer = FinalAnswerTool()
 
188
 
189
  agent = CodeAgent(
190
  model=model,
191
+ tools=[
192
+ final_answer,
193
+ search_tool,
194
+ get_current_time_in_timezone,
195
+ get_weather,
196
+ image_generation_tool
197
+ ]
198
+ max_steps=10,
199
+ verbosity_level=2,
200
  grammar=None,
201
  planning_interval=None,
202
  name=None,