Spaces:
Runtime error
Runtime error
Update tools.py
Browse files
tools.py
CHANGED
|
@@ -20,6 +20,50 @@ import re
|
|
| 20 |
from datetime import datetime, timedelta
|
| 21 |
from langchain_core.tools import tool
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
@tool
|
| 24 |
def search_featured_articles_by_date_range(start_date: str, end_date: str) -> list[str]:
|
| 25 |
"""
|
|
@@ -232,6 +276,7 @@ def filter_vegetables(items: list[str]) -> list[str]:
|
|
| 232 |
# List of all tools
|
| 233 |
all_tools = [
|
| 234 |
# search_featured_articles_by_date_range,
|
|
|
|
| 235 |
detect_non_commutative_subset,
|
| 236 |
reverse_sentence,
|
| 237 |
filter_vegetables,
|
|
|
|
| 20 |
from datetime import datetime, timedelta
|
| 21 |
from langchain_core.tools import tool
|
| 22 |
|
| 23 |
+
@tool
|
| 24 |
+
def categorize_grocery_items(items: list[str]) -> dict:
|
| 25 |
+
"""
|
| 26 |
+
Categorizes grocery items into food groups: vegetables, fruits, grains, dairy, snacks, nuts/legumes, spices, and beverages.
|
| 27 |
+
|
| 28 |
+
Args:
|
| 29 |
+
items (list[str]): List of grocery item names.
|
| 30 |
+
|
| 31 |
+
Returns:
|
| 32 |
+
dict: Dictionary mapping category names to sorted lists of items in that category.
|
| 33 |
+
"""
|
| 34 |
+
print(f"🛠️ categorize_grocery_items called with: {items}")
|
| 35 |
+
|
| 36 |
+
categories = {
|
| 37 |
+
"vegetables": {"broccoli", "celery", "green beans", "lettuce", "sweet potatoes", "zucchini"},
|
| 38 |
+
"fruits": {"plums", "bananas", "strawberries", "blueberries", "bell pepper"},
|
| 39 |
+
"grains": {"rice", "flour", "corn"},
|
| 40 |
+
"dairy": {"milk", "eggs"},
|
| 41 |
+
"snacks": {"Oreos"},
|
| 42 |
+
"nuts_and_legumes": {"peanuts", "acorns"},
|
| 43 |
+
"spices": {"whole allspice", "fresh basil"},
|
| 44 |
+
"beverages": {"whole bean coffee"},
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
result = {category: [] for category in categories}
|
| 48 |
+
result["other"] = []
|
| 49 |
+
|
| 50 |
+
for item in items:
|
| 51 |
+
found = False
|
| 52 |
+
for category, items_set in categories.items():
|
| 53 |
+
if item in items_set:
|
| 54 |
+
result[category].append(item)
|
| 55 |
+
found = True
|
| 56 |
+
break
|
| 57 |
+
if not found:
|
| 58 |
+
result["other"].append(item)
|
| 59 |
+
|
| 60 |
+
# Sort each category list
|
| 61 |
+
for key in result:
|
| 62 |
+
result[key] = sorted(result[key])
|
| 63 |
+
|
| 64 |
+
return result
|
| 65 |
+
|
| 66 |
+
|
| 67 |
@tool
|
| 68 |
def search_featured_articles_by_date_range(start_date: str, end_date: str) -> list[str]:
|
| 69 |
"""
|
|
|
|
| 276 |
# List of all tools
|
| 277 |
all_tools = [
|
| 278 |
# search_featured_articles_by_date_range,
|
| 279 |
+
categorize_grocery_items,
|
| 280 |
detect_non_commutative_subset,
|
| 281 |
reverse_sentence,
|
| 282 |
filter_vegetables,
|