sperera commited on
Commit
040b244
·
verified ·
1 Parent(s): 8c5c24b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -1
app.py CHANGED
@@ -34,6 +34,33 @@ def get_current_time_in_timezone(timezone: str) -> str:
34
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
35
 
36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  final_answer = FinalAnswerTool()
38
 
39
  # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
@@ -55,7 +82,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,
 
34
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
35
 
36
 
37
+ @tool
38
+ def get_current_weather(city: str) -> str:
39
+ """Get the current weather conditions and temperature for a given city.
40
+
41
+ Args:
42
+ city: The name of the city to look up (e.g., 'San Francisco', 'Tokyo').
43
+ """
44
+ # Using a free public weather API endpoint (Open-Meteo as an example)
45
+ # First, get coordinates for the city using a geocoding lookup
46
+ geo_url = f"https://geocoding-api.open-meteo.com/v1/search?name={city}&count=1"
47
+ geo_res = requests.get(geo_url).json()
48
+
49
+ if not geo_res.get("results"):
50
+ return f"Could not find coordinates for city: {city}"
51
+
52
+ lat = geo_res["results"][0]["latitude"]
53
+ lon = geo_res["results"][0]["longitude"]
54
+
55
+ # Fetch current weather data
56
+ weather_url = f"https://api.open-meteo.com/v1/forecast?latitude={lat}&longitude={lon}&current=temperature_2m,weather_code"
57
+ data = requests.get(weather_url).json()
58
+
59
+ current = data.get("current", {})
60
+ temp = current.get("temperature_2m")
61
+
62
+ return f"The current temperature in {city} is {temp}°C."
63
+
64
  final_answer = FinalAnswerTool()
65
 
66
  # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
 
82
 
83
  agent = CodeAgent(
84
  model=model,
85
+ tools=[final_answer, get_current_time_in_timezone, get_current_weather], ## add your tools here (don't remove final answer)
86
  max_steps=6,
87
  verbosity_level=1,
88
  grammar=None,