ZainebS commited on
Commit
74266d3
·
verified ·
1 Parent(s): 85ba092

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -7
app.py CHANGED
@@ -9,14 +9,30 @@ 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:
@@ -56,7 +72,7 @@ with open("prompts.yaml", 'r') as stream:
56
 
57
  agent = CodeAgent(
58
  model=model,
59
- tools=[final_answer, get_current_time_in_timezone, search_tool], ## add your tools here (don't remove final answer)
60
  max_steps=6,
61
  verbosity_level=1,
62
  grammar=None,
 
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
+ def get_weather(city:str)-> str:
13
+ """A tool that returns the weather of a city
 
14
  Args:
15
+ arg1: city name
 
16
  """
17
+ city_coords = {
18
+ "New York": (40.7128, -74.0060),
19
+ "London": (51.5074, -0.1278),
20
+ "Tokyo": (35.6895, 139.6917),
21
+ }
22
+
23
+ if city not in city_coords:
24
+ return "City not found. Try New York, London, or Tokyo."
25
+
26
+ lat, lon = city_coords[city]
27
+ url = f"https://api.open-meteo.com/v1/forecast?latitude={lat}&longitude={lon}&current_weather=true"
28
+
29
+ response = requests.get(url)
30
+ if response.status_code == 200:
31
+ data = response.json()
32
+ weather = data["current_weather"]
33
+ return f"The weather in {city} is {weather['temperature']}°C with {weather['weathercode']}."
34
+ else:
35
+ return "Error fetching weather data."
36
 
37
  @tool
38
  def get_current_time_in_timezone(timezone: str) -> str:
 
72
 
73
  agent = CodeAgent(
74
  model=model,
75
+ tools=[final_answer, get_current_time_in_timezone, get_weather], ## add your tools here (don't remove final answer)
76
  max_steps=6,
77
  verbosity_level=1,
78
  grammar=None,