File size: 2,516 Bytes
6078833
 
 
8289a78
6078833
 
 
 
 
8289a78
6078833
 
 
 
 
 
 
 
 
 
 
8289a78
 
6078833
 
 
 
 
 
 
 
 
 
 
8289a78
6078833
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8289a78
6078833
8289a78
 
 
 
 
 
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
from src.utils.tooling import tool

@tool
def classify_foods(food_list: list) -> str:
    """
    Classifies a list of foods into specific botanical categories.
    Args:
        food_list (list): A list of foods to classify.
    Returns:
        str: A string with categories as keys and lists of foods as values.
    """
    categories = {
        "fruits": [
            "apple", "banana", "orange", "grape", "strawberry", "plum", "peach", "pear",
            "cherry", "blueberry", "raspberry", "pineapple", "mango", "kiwi", "lemon",
            "lime", "watermelon", "cantaloupe", "avocado", "tomato", "cucumber", "bell pepper",
            "eggplant", "okra", "zucchini", "pumpkin", "olive"
        ],
        "vegetables": [
            "carrot", "broccoli", "spinach", "lettuce", "celery", "fresh basil", "sweet potato",
            "potato", "onion", "garlic", "cabbage", "kale", "cauliflower", "asparagus", "radish",
            "turnip", "beet", "artichoke", "brussels sprouts", "peas", "mushroom",
            "sweet potatoes",
        ],
        "grains": [
            "rice", "wheat", "oats", "barley", "quinoa", "corn", "rye", "millet", "sorghum",
            "buckwheat", "flour"
        ],
        "nuts": [
            "almond", "walnut", "cashew", "peanut", "hazelnut", "pecan", "pistachio", "macadamia",
            "brazil nut", "chestnut", "acorn"
        ],
        "legumes": [
            "lentil", "chickpea", "bean", "pea", "soybean", "black bean", "kidney bean", "pinto bean",
            "navy bean", "lima bean", "green beans",
        ],
        "other": [
            "milk", "eggs", "coffee", "Oreos", "allspice", "sugar", "salt", "honey", "maple syrup",
            "vinegar", "oil", "butter", "cheese", "yogurt", "cream", "meat", "fish", "poultry"
        ]
    }
    classified_foods = {category: [] for category in categories}

    for food in food_list:
        food_lower = food.lower()
        classified = False
        for category, examples in categories.items():
            if food_lower in examples:
                classified_foods[category].append(food)
                classified = True
                break
        if not classified:
            classified_foods.setdefault("unknown", []).append(food)

    #classified_foods["vegetables"].sort()

    result = []
    for category, foods in classified_foods.items():
        if foods:
            result.append(f"{category.capitalize()}: {', '.join(foods)}")

    return "Food classification:\n" + "\n".join(result)