Spaces:
Runtime error
Runtime error
included weather, duckduckgo and image generation
Browse files
app.py
CHANGED
|
@@ -4,9 +4,33 @@ import requests
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
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_cutom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
|
@@ -51,13 +75,19 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 51 |
|
| 52 |
agent = CodeAgent(
|
| 53 |
model=model,
|
| 54 |
-
tools=[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
max_steps=6,
|
| 56 |
verbosity_level=1,
|
| 57 |
grammar=None,
|
| 58 |
planning_interval=None,
|
| 59 |
-
name=
|
| 60 |
-
description=
|
| 61 |
prompt_templates=prompt_templates
|
| 62 |
)
|
| 63 |
|
|
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
+
import os
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
+
|
| 11 |
+
# Define a new tool: Weather Information Fetcher
|
| 12 |
+
@tool
|
| 13 |
+
def get_weather(city: str) -> str:
|
| 14 |
+
"""A tool that fetches current weather information for a given city.
|
| 15 |
+
Args:
|
| 16 |
+
city: The name of the city (e.g., 'New York').
|
| 17 |
+
"""
|
| 18 |
+
try:
|
| 19 |
+
api_key = os.getenv("OPENWEATHERMAP_API_KEY") # Replace with your actual API key
|
| 20 |
+
url = f"http://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}&units=metric"
|
| 21 |
+
response = requests.get(url).json()
|
| 22 |
+
|
| 23 |
+
if response.get("cod") != 200:
|
| 24 |
+
return f"Error fetching weather: {response.get('message', 'Unknown error')}"
|
| 25 |
+
|
| 26 |
+
weather = response["weather"][0]["description"].capitalize()
|
| 27 |
+
temp = response["main"]["temp"]
|
| 28 |
+
humidity = response["main"]["humidity"]
|
| 29 |
+
return f"Current weather in {city}: {weather}, Temp: {temp}°C, Humidity: {humidity}%"
|
| 30 |
+
except Exception as e:
|
| 31 |
+
return f"Error fetching weather for '{city}': {str(e)}"
|
| 32 |
+
|
| 33 |
+
|
| 34 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 35 |
@tool
|
| 36 |
def my_cutom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
|
|
|
| 75 |
|
| 76 |
agent = CodeAgent(
|
| 77 |
model=model,
|
| 78 |
+
tools=[
|
| 79 |
+
final_answer,
|
| 80 |
+
DuckDuckGoSearchTool(), # Enables web search
|
| 81 |
+
image_generation_tool, # Enables text-to-image generation
|
| 82 |
+
get_weather, # Enables weather fetching
|
| 83 |
+
get_current_time_in_timezone, # Enables timezone-based time retrieval
|
| 84 |
+
],
|
| 85 |
max_steps=6,
|
| 86 |
verbosity_level=1,
|
| 87 |
grammar=None,
|
| 88 |
planning_interval=None,
|
| 89 |
+
name="Enhanced CodeAgent",
|
| 90 |
+
description="An AI agent with web search, image generation, weather, and timezone utilities.",
|
| 91 |
prompt_templates=prompt_templates
|
| 92 |
)
|
| 93 |
|