rtamaki's picture
create tools.py with some basic tools, and 2 placeholder tools
183a793 verified
import requests
import json
from smolagents import InferenceClientModel, tool
from typing import Any, Dict
@tool
def get_weather(city: str) -> Dict[str, Any]:
"""
Get the weather based on the city name
Args:
city (str): The name of the city
Returns:
Dict[str, Any]: The weather information as a dictionary with the following keys:
- City: The name of the city
- Temperature (°C): The temperature in Celsius
- Weather: The weather description
- Humidity (%): The humidity percentage
- Wind (km/h): The wind speed in kilometers per hour
- Feels Like (°C): The temperature that feels like
- Min temperature (°C): The minimum temperature
- Max temperature (°C): The maximum temperature
- Chance of rain: The chance of rain
- Chance of snow: The chance of snow
"""
try:
url = f"https://wttr.in/{city}?format=j1"
response = requests.get(url)
data = response.json()
current = data['current_condition'][0]
day_weather = data['weather'][0]
chance_of_rain = max([int(hour["chanceofrain"])/100 for hour in day_weather['hourly']])
chance_of_snow = max([int(hour["chanceofsnow"])/100 for hour in day_weather['hourly']])
weather = {
"City": city,
"Temperature (°C)": current["temp_C"],
"Weather": current["weatherDesc"][0]["value"],
"Humidity (%)": current["humidity"],
"Wind (km/h)": current["windspeedKmph"],
"Feels Like (°C)": current["FeelsLikeC"],
"Min temperature (°C)": day_weather["mintempC"],
"Max temperature (°C)": day_weather["maxtempC"],
"Chance of rain": chance_of_rain,
"Chance of snow": chance_of_snow,
}
return weather
except Exception as e:
return {"Error": str(e)}
@tool
def get_current_city() -> str:
"""
Get the location based on the IP address
Args:
Returns:
str: the city where the person is currently in based on the IP
"""
try:
response = requests.get("https://ipinfo.io/json")
data = response.json()
return data.get("city")
except Exception as e:
return e
@tool
def infer_event_style_from_text(user_input: str) -> str:
"""
Infers the style of an event based on natural language input using an LLM.
Returns one of: casual, formal, beachwear, dress-up, business casual, athletic, outdoor, unspecified.
Args:
user_input: A sentence or phrase describing what the user is doing, e.g., "I'm going to a beach party"
Returns:
A lowercase string representing the event style. One of:
- casual
- formal
- beachwear
- dress-up
- business casual
- athletic
- outdoor
- unspecified
"""
messages = [
Message(role= "system",
content=
"You are an event style classifier. Your job is to take natural language user input "
"and respond with exactly one of the following event style labels:\n"
"- casual\n- formal\n- beachwear\n- dress-up\n- business casual\n- athletic\n- outdoor\n- unspecified"),
Message(role= "user",
content= f"Classify this: {user_input}\nEvent style:")
]
model = InferenceClientModel()
response = model(messages, stop_sequences=["END"])
print(f"Response: {response.content}")
return response.content.lower()
@tool
def get_vogue(city: str, season: str) -> str:
"""
Get all the clothes in the wardrobe, together with their colors, and descriptions
Args:
city (str): The name of the city
season (str): The name of the season:
- "winter": clothes for winter
- "spring": clothes for spring
- "summer": clothes for summer
- "fall": clothes for fall
Returns:
str: text of what items are on trend for a given weather and occasion
"""
return """
Activity Clothing Accessories Style Tip
Brunch at a café Linen shirt or chic blouse, tailored trousers or midi skirt Crossbody bag, sunglasses Parisians love neutral tones – try beige, white, navy
Stroll in Montmartre or along the Seine Lightweight cotton dress or relaxed-fit jeans + striped top Comfortable leather flats, beret A Breton stripe is classic Parisian chic
Museum visit Midi dress or smart jumpsuit Small tote, silk scarf Keep layers easy to remove (some museums can be warm inside)
Picnic in a park Flowy sundress or casual skirt + tee Straw hat, ballet flats Bring a light cardigan or blazer in case it gets breezy
Dinner in a bistro Elegant blouse + culottes or a wrap dress Clutch bag, statement earrings A red lip adds effortless sophistication
Evening walk by the Eiffel Tower Tailored trousers + fine knit top or maxi dress Lightweight trench, flat sandals Trench coats are timeless and very Parisian
"""
@tool
def get_wardrobe() -> str:
"""
Get all the clothes in the wardrobe, together with their colors, and descriptions
Args:
Returns:
str: list of all the clothes in the wardrobe
"""
return """
| Category | Item | Quantity | Notes |
| --------------- | ------------------------------- | -------- | ----------------------------------------------------- |
| **Tops** | T-shirts | 5–7 | Neutral colors for versatility; cotton or quick-dry |
| | Polo shirts | 2–3 | For smart-casual outings |
| | Button-down shirts | 2–4 | Long or short sleeve; wrinkle-resistant options ideal |
| | Lightweight sweater | 1–2 | Great for layering |
| | Hoodie or sweatshirt | 1 | Casual comfort and warmth |
| | Jacket (lightweight) | 1 | Windbreaker or packable jacket depending on climate |
| | Formal jacket/blazer | 1 | Optional; for work, dining, or events |
| **Bottoms** | Jeans or casual trousers | 1–2 | Dark wash preferred |
| | Chinos or dress pants | 1 | For dressier occasions |
| | Shorts | 2–3 | Depends on destination climate |
| | Joggers or travel pants | 1 | Great for flights and comfort |
| **Underwear** | Underwear | 7–10 | Breathable and comfortable |
| | Socks | 7–10 | Mix of athletic and dress |
| **Sleepwear** | Pajamas or sleepwear | 1–2 | Lightweight and compact |
| **Outerwear** | Rain jacket or shell | 1 | Waterproof for variable weather |
| | Warm jacket/coat | 1 | Only if traveling to a cold region |
| **Footwear** | Sneakers or casual shoes | 1–2 | One for walking, one for style |
| | Dress shoes or loafers | 1 | Optional depending on itinerary |
| | Sandals or flip-flops | 1 | For hot weather or showers |
| **Accessories** | Belt | 1–2 | Casual and/or dress |
| | Hat or cap | 1 | Sun protection |
| | Scarf/gloves/beanie | 1 set | Only for cold destinations |
| | Swimwear | 1–2 | If beach/pool included |
| **Other** | Workout clothes | 1–2 sets | Moisture-wicking; only if planning to exercise |
| | Compression socks (for flights) | 1–2 | Recommended for long-haul flights |
| | Laundry bag | 1 | Helps keep clean/dirty separate |
"""