Juanpa0128 commited on
Commit
7f37f38
·
verified ·
1 Parent(s): 8c5c24b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -6
app.py CHANGED
@@ -7,16 +7,62 @@ from tools.final_answer import FinalAnswerTool
7
 
8
  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(arg1:str, arg2:int)-> str: #it's import to specify the return type
13
  #Keep this format for the description / args / args description but feel free to modify the tool
14
- """A tool that does nothing yet
 
 
 
15
  Args:
16
- arg1: the first argument
17
- arg2: the second argument
 
 
 
18
  """
19
- return "What magic will you build ?"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
  @tool
22
  def get_current_time_in_timezone(timezone: str) -> str:
@@ -55,7 +101,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,
 
7
 
8
  from Gradio_UI import GradioUI
9
 
10
+ TIMEZONE_COORDINATES = {
11
+ "America/New_York": (40.7128, -74.0060), # New York City
12
+ "America/Chicago": (41.8781, -87.6298), # Chicago
13
+ "America/Denver": (39.7392, -104.9903), # Denver
14
+ "America/Los_Angeles": (34.0522, -118.2437), # Los Angeles
15
+ "Europe/London": (51.5074, -0.1278), # London
16
+ "Europe/Berlin": (52.5200, 13.4050), # Berlin
17
+ "Asia/Tokyo": (35.6762, 139.6503), # Tokyo
18
+ "UTC": (0.0, 0.0), # Equatorial reference
19
+ }
20
+
21
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
22
  @tool
23
+ def get_current_temperature_in_timezone(timezone: 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
+ f"""
26
+ A tool that fetches the current temperature in a specified timezone.
27
+ Only these timezones are available: {TIMEZONE_COORDINATES}
28
+
29
  Args:
30
+ timezone: A string representing a valid timezone
31
+ (e.g., 'America/New_York').
32
+
33
+ Returns:
34
+ A string describing the current temperature in Celsius.
35
  """
36
+
37
+ if timezone not in TIMEZONE_COORDINATES:
38
+ return f"Unsupported timezone: {timezone}"
39
+
40
+ lat, lon = TIMEZONE_COORDINATES[timezone]
41
+
42
+ url = "https://api.open-meteo.com/v1/forecast"
43
+ params = {
44
+ "latitude": lat,
45
+ "longitude": lon,
46
+ "current": "temperature_2m",
47
+ "timezone": timezone,
48
+ }
49
+
50
+ try:
51
+ response = requests.get(url, params=params, timeout=10)
52
+ response.raise_for_status()
53
+ data = response.json()
54
+
55
+ temperature = data["current"]["temperature_2m"]
56
+ timestamp = data["current"]["time"]
57
+
58
+ return (
59
+ f"The current temperature in {timezone} "
60
+ f"(representative location) is {temperature}°C "
61
+ f"as of {timestamp}."
62
+ )
63
+
64
+ except Exception as e:
65
+ return f"Failed to fetch temperature for {timezone}: {str(e)}"
66
 
67
  @tool
68
  def get_current_time_in_timezone(timezone: str) -> str:
 
101
 
102
  agent = CodeAgent(
103
  model=model,
104
+ tools=[final_answer, DuckDuckGoSearchTool, image_generation_tool, get_current_time_in_timezone, get_current_temperature_in_timezone], ## add your tools here (don't remove final answer)
105
  max_steps=6,
106
  verbosity_level=1,
107
  grammar=None,