Spaces:
Sleeping
Sleeping
File size: 2,718 Bytes
e8e3ab1 9b5b26a 6aae614 665076f 9b5b26a 5df72d6 9b5b26a e8e3ab1 9b5b26a 8c01ffb 040b244 e8e3ab1 040b244 e8e3ab1 040b244 e8e3ab1 040b244 e8e3ab1 040b244 e8e3ab1 040b244 e8e3ab1 040b244 6aae614 e045999 a21baa3 e8f79a9 e8e3ab1 a21baa3 e8e3ab1 13d500a 8c01ffb a21baa3 8c01ffb 8fe992b a887bdc 8c01ffb 8fe992b 8c01ffb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | from smolagents import CodeAgent, DuckDuckGoSearchTool, InferenceClientModel, load_tool, tool
import datetime
import requests
import pytz
from tools.final_answer import FinalAnswerTool
from duckduckgo_search import DDGS
from Gradio_UI import GradioUI
# Below is an example of a tool that does nothing. Amaze us with your creativity !
@tool
def my_custom_tool(arg1: str, arg2: int) -> str:
"""A tool that does nothing yet
Args:
arg1: the first argument
arg2: the second argument
"""
return "What magic will you build ?"
@tool
def get_current_time_in_timezone(timezone: str) -> str:
"""A tool that fetches the current local time in a specified timezone.
Args:
timezone: A string representing a valid timezone (e.g., 'America/New_York').
"""
try:
tz = pytz.timezone(timezone)
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
return f"The current local time in {timezone} is: {local_time}"
except Exception as e:
return f"Error fetching time for timezone '{timezone}': {str(e)}"
@tool
def get_current_weather(city: str) -> str:
"""Get the current weather conditions and temperature for a given city.
Args:
city: The name of the city to look up (e.g., 'San Francisco', 'Tokyo').
"""
geo_url = f"https://geocoding-api.open-meteo.com/v1/search?name={city}&count=1"
geo_res = requests.get(geo_url).json()
if not geo_res.get("results"):
return f"Could not find coordinates for city: {city}"
lat = geo_res["results"][0]["latitude"]
lon = geo_res["results"][0]["longitude"]
weather_url = f"https://api.open-meteo.com/v1/forecast?latitude={lat}&longitude={lon}¤t=temperature_2m,weather_code"
data = requests.get(weather_url).json()
current = data.get("current", {})
temp = current.get("temperature_2m")
return f"The current temperature in {city} is {temp}°C."
final_answer = FinalAnswerTool()
search_tool = DuckDuckGoSearchTool()
# --- UNIVERSALLY ROUTED MODEL CONFIGURATION ---
model = InferenceClientModel(
max_tokens=2096,
temperature=0.5,
model_id='meta-llama/Llama-3.3-70B-Instruct', # Universally supported on serverless routers
provider="auto", # Automatically selects an available provider endpoint
custom_role_conversions=None,
)
# Initialize your agent with the updated model
agent = CodeAgent(
model=model,
tools=[final_answer, get_current_time_in_timezone, get_current_weather],
max_steps=6,
verbosity_level=1,
planning_interval=None,
name=None,
description=None,
)
GradioUI(agent).launch() |