knt21 commited on
Commit
fea825c
·
verified ·
1 Parent(s): 22208b3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -1
app.py CHANGED
@@ -4,6 +4,7 @@ import requests
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
 
7
 
8
  from Gradio_UI import GradioUI
9
 
@@ -18,6 +19,31 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
18
  """
19
  return "What magic will you build ?"
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.
@@ -55,7 +81,7 @@ with open("prompts.yaml", 'r') as stream:
55
 
56
  agent = CodeAgent(
57
  model=model,
58
- tools=[final_answer, get_current_time_in_timezone, DuckDuckGoSearchTool()], ## add your tools here (don't remove final answer)
59
  max_steps=6,
60
  verbosity_level=1,
61
  grammar=None,
 
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
+ import requests
8
 
9
  from Gradio_UI import GradioUI
10
 
 
19
  """
20
  return "What magic will you build ?"
21
 
22
+ @tool
23
+ def get_weather(location:str)-> str: #it's import to specify the return type
24
+ #Keep this format for the description / args / args description but feel free to modify the tool
25
+ """A tool that fetches the current weather data for the specified location.
26
+ Args:
27
+ location: A string representung a valid location (e.g.,'New_York','Mumbai','Sydney')
28
+ """
29
+
30
+ try:
31
+ # Get location
32
+ location=location
33
+ # Craft the url
34
+ url=f"https://wttr.in/{location}?format=j1"
35
+ # Get the API response
36
+ response= requests.get(url).json()
37
+ # Get current condition values
38
+ current_conditions= response["current_condition"][0]
39
+ # Extract weather data
40
+ weather_data= current["weatherDesc"][0]["value"]
41
+ # Extract temperature data
42
+ temperature_data= current["temp_C"], "°C"
43
+ return f"For {location} location, Weather: {weather_data} Temperature: {temperature_data}"
44
+ except Exception as e:
45
+ return f"Error fetching weather data for timezone '{location}': {str(e)}"
46
+
47
  @tool
48
  def get_current_time_in_timezone(timezone: str) -> str:
49
  """A tool that fetches the current local time in a specified timezone.
 
81
 
82
  agent = CodeAgent(
83
  model=model,
84
+ tools=[final_answer, get_current_time_in_timezone, get_weather, DuckDuckGoSearchTool()], ## add your tools here (don't remove final answer)
85
  max_steps=6,
86
  verbosity_level=1,
87
  grammar=None,