rtamaki commited on
Commit
183a793
·
verified ·
1 Parent(s): aaac444

create tools.py with some basic tools, and 2 placeholder tools

Browse files
Files changed (1) hide show
  1. tools.py +171 -0
tools.py ADDED
@@ -0,0 +1,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import json
3
+ from smolagents import InferenceClientModel, tool
4
+ from typing import Any, Dict
5
+
6
+
7
+ @tool
8
+ def get_weather(city: str) -> Dict[str, Any]:
9
+ """
10
+ Get the weather based on the city name
11
+ Args:
12
+ city (str): The name of the city
13
+ Returns:
14
+ Dict[str, Any]: The weather information as a dictionary with the following keys:
15
+ - City: The name of the city
16
+ - Temperature (°C): The temperature in Celsius
17
+ - Weather: The weather description
18
+ - Humidity (%): The humidity percentage
19
+ - Wind (km/h): The wind speed in kilometers per hour
20
+ - Feels Like (°C): The temperature that feels like
21
+ - Min temperature (°C): The minimum temperature
22
+ - Max temperature (°C): The maximum temperature
23
+ - Chance of rain: The chance of rain
24
+ - Chance of snow: The chance of snow
25
+ """
26
+
27
+ try:
28
+ url = f"https://wttr.in/{city}?format=j1"
29
+ response = requests.get(url)
30
+ data = response.json()
31
+
32
+ current = data['current_condition'][0]
33
+ day_weather = data['weather'][0]
34
+ chance_of_rain = max([int(hour["chanceofrain"])/100 for hour in day_weather['hourly']])
35
+ chance_of_snow = max([int(hour["chanceofsnow"])/100 for hour in day_weather['hourly']])
36
+ weather = {
37
+ "City": city,
38
+ "Temperature (°C)": current["temp_C"],
39
+ "Weather": current["weatherDesc"][0]["value"],
40
+ "Humidity (%)": current["humidity"],
41
+ "Wind (km/h)": current["windspeedKmph"],
42
+ "Feels Like (°C)": current["FeelsLikeC"],
43
+ "Min temperature (°C)": day_weather["mintempC"],
44
+ "Max temperature (°C)": day_weather["maxtempC"],
45
+ "Chance of rain": chance_of_rain,
46
+ "Chance of snow": chance_of_snow,
47
+ }
48
+
49
+ return weather
50
+
51
+ except Exception as e:
52
+ return {"Error": str(e)}
53
+
54
+
55
+ @tool
56
+ def get_current_city() -> str:
57
+ """
58
+ Get the location based on the IP address
59
+ Args:
60
+ Returns:
61
+ str: the city where the person is currently in based on the IP
62
+ """
63
+ try:
64
+ response = requests.get("https://ipinfo.io/json")
65
+ data = response.json()
66
+ return data.get("city")
67
+
68
+ except Exception as e:
69
+ return e
70
+
71
+
72
+ @tool
73
+ def infer_event_style_from_text(user_input: str) -> str:
74
+ """
75
+ Infers the style of an event based on natural language input using an LLM.
76
+ Returns one of: casual, formal, beachwear, dress-up, business casual, athletic, outdoor, unspecified.
77
+
78
+ Args:
79
+ user_input: A sentence or phrase describing what the user is doing, e.g., "I'm going to a beach party"
80
+ Returns:
81
+ A lowercase string representing the event style. One of:
82
+ - casual
83
+ - formal
84
+ - beachwear
85
+ - dress-up
86
+ - business casual
87
+ - athletic
88
+ - outdoor
89
+ - unspecified
90
+
91
+ """
92
+
93
+ messages = [
94
+ Message(role= "system",
95
+ content=
96
+ "You are an event style classifier. Your job is to take natural language user input "
97
+ "and respond with exactly one of the following event style labels:\n"
98
+ "- casual\n- formal\n- beachwear\n- dress-up\n- business casual\n- athletic\n- outdoor\n- unspecified"),
99
+ Message(role= "user",
100
+ content= f"Classify this: {user_input}\nEvent style:")
101
+ ]
102
+ model = InferenceClientModel()
103
+ response = model(messages, stop_sequences=["END"])
104
+ print(f"Response: {response.content}")
105
+ return response.content.lower()
106
+
107
+
108
+ @tool
109
+ def get_vogue(city: str, season: str) -> str:
110
+ """
111
+ Get all the clothes in the wardrobe, together with their colors, and descriptions
112
+ Args:
113
+ city (str): The name of the city
114
+ season (str): The name of the season:
115
+ - "winter": clothes for winter
116
+ - "spring": clothes for spring
117
+ - "summer": clothes for summer
118
+ - "fall": clothes for fall
119
+ Returns:
120
+ str: text of what items are on trend for a given weather and occasion
121
+ """
122
+ return """
123
+ Activity Clothing Accessories Style Tip
124
+ 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
125
+ 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
126
+ Museum visit Midi dress or smart jumpsuit Small tote, silk scarf Keep layers easy to remove (some museums can be warm inside)
127
+ 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
128
+ Dinner in a bistro Elegant blouse + culottes or a wrap dress Clutch bag, statement earrings A red lip adds effortless sophistication
129
+ 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
130
+ """
131
+
132
+
133
+ @tool
134
+ def get_wardrobe() -> str:
135
+ """
136
+ Get all the clothes in the wardrobe, together with their colors, and descriptions
137
+ Args:
138
+ Returns:
139
+ str: list of all the clothes in the wardrobe
140
+ """
141
+ return """
142
+ | Category | Item | Quantity | Notes |
143
+ | --------------- | ------------------------------- | -------- | ----------------------------------------------------- |
144
+ | **Tops** | T-shirts | 5–7 | Neutral colors for versatility; cotton or quick-dry |
145
+ | | Polo shirts | 2–3 | For smart-casual outings |
146
+ | | Button-down shirts | 2–4 | Long or short sleeve; wrinkle-resistant options ideal |
147
+ | | Lightweight sweater | 1–2 | Great for layering |
148
+ | | Hoodie or sweatshirt | 1 | Casual comfort and warmth |
149
+ | | Jacket (lightweight) | 1 | Windbreaker or packable jacket depending on climate |
150
+ | | Formal jacket/blazer | 1 | Optional; for work, dining, or events |
151
+ | **Bottoms** | Jeans or casual trousers | 1–2 | Dark wash preferred |
152
+ | | Chinos or dress pants | 1 | For dressier occasions |
153
+ | | Shorts | 2–3 | Depends on destination climate |
154
+ | | Joggers or travel pants | 1 | Great for flights and comfort |
155
+ | **Underwear** | Underwear | 7–10 | Breathable and comfortable |
156
+ | | Socks | 7–10 | Mix of athletic and dress |
157
+ | **Sleepwear** | Pajamas or sleepwear | 1–2 | Lightweight and compact |
158
+ | **Outerwear** | Rain jacket or shell | 1 | Waterproof for variable weather |
159
+ | | Warm jacket/coat | 1 | Only if traveling to a cold region |
160
+ | **Footwear** | Sneakers or casual shoes | 1–2 | One for walking, one for style |
161
+ | | Dress shoes or loafers | 1 | Optional depending on itinerary |
162
+ | | Sandals or flip-flops | 1 | For hot weather or showers |
163
+ | **Accessories** | Belt | 1–2 | Casual and/or dress |
164
+ | | Hat or cap | 1 | Sun protection |
165
+ | | Scarf/gloves/beanie | 1 set | Only for cold destinations |
166
+ | | Swimwear | 1–2 | If beach/pool included |
167
+ | **Other** | Workout clothes | 1–2 sets | Moisture-wicking; only if planning to exercise |
168
+ | | Compression socks (for flights) | 1–2 | Recommended for long-haul flights |
169
+ | | Laundry bag | 1 | Helps keep clean/dirty separate |
170
+
171
+ """