Spaces:
Sleeping
Sleeping
Update tool.py
Browse files
tool.py
CHANGED
|
@@ -1,6 +1,20 @@
|
|
| 1 |
from smolagents import Tool
|
| 2 |
from typing import Optional
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
class SimpleTool(Tool):
|
| 5 |
name = "CulinAI -- your AI Recipe Assistant"
|
| 6 |
description = "Gets a recipe suggestion based on provided ingredients, dietary preference, and your laziness level (1=active chef, 10=super lazy). After finding a recipe, itretrieves detailed recipe information."
|
|
@@ -10,20 +24,9 @@ class SimpleTool(Tool):
|
|
| 10 |
"description": "A comma-separated string of available ingredients."
|
| 11 |
},
|
| 12 |
"diet": {
|
| 13 |
-
"type": "
|
| 14 |
-
"enum":
|
| 15 |
-
|
| 16 |
-
"vegetarian",
|
| 17 |
-
"vegan",
|
| 18 |
-
"gluten free",
|
| 19 |
-
"ketogenic",
|
| 20 |
-
"paleo",
|
| 21 |
-
"pescetarian",
|
| 22 |
-
"whole30",
|
| 23 |
-
"halal",
|
| 24 |
-
"low fodmap"
|
| 25 |
-
],
|
| 26 |
-
"default": "none",
|
| 27 |
"nullable": True,
|
| 28 |
"description": "Select dietary restriction from the available options."
|
| 29 |
},
|
|
@@ -35,7 +38,7 @@ class SimpleTool(Tool):
|
|
| 35 |
}
|
| 36 |
output_type = "string"
|
| 37 |
|
| 38 |
-
def forward(self, ingredients: str, diet: Optional[
|
| 39 |
"""
|
| 40 |
Gets a recipe suggestion based on provided ingredients, dietary preference,
|
| 41 |
and your laziness level (1=active chef, 10=super lazy). After finding a recipe, it
|
|
@@ -51,14 +54,6 @@ class SimpleTool(Tool):
|
|
| 51 |
"""
|
| 52 |
|
| 53 |
|
| 54 |
-
# Validate diet option
|
| 55 |
-
valid_diets = {
|
| 56 |
-
"none", "vegetarian", "vegan", "gluten free", "ketogenic",
|
| 57 |
-
"paleo", "pescetarian", "whole30", "halal", "low fodmap"
|
| 58 |
-
}
|
| 59 |
-
if diet and diet not in valid_diets:
|
| 60 |
-
return f"Invalid diet option. Please choose from: {', '.join(sorted(valid_diets))}"
|
| 61 |
-
|
| 62 |
import os
|
| 63 |
import requests
|
| 64 |
|
|
@@ -76,8 +71,8 @@ class SimpleTool(Tool):
|
|
| 76 |
}
|
| 77 |
|
| 78 |
# Add diet if provided and not "none"
|
| 79 |
-
if diet and diet !=
|
| 80 |
-
params["diet"] = diet
|
| 81 |
|
| 82 |
# Incorporate the laziness factor: filter by maxReadyTime if needed.
|
| 83 |
try:
|
|
|
|
| 1 |
from smolagents import Tool
|
| 2 |
from typing import Optional
|
| 3 |
|
| 4 |
+
from enum import Enum
|
| 5 |
+
|
| 6 |
+
class Diet(Enum):
|
| 7 |
+
NONE = "none"
|
| 8 |
+
VEGETARIAN = "vegetarian"
|
| 9 |
+
VEGAN = "vegan"
|
| 10 |
+
GLUTEN_FREE = "gluten free"
|
| 11 |
+
KETOGENIC = "ketogenic"
|
| 12 |
+
PALEO = "paleo"
|
| 13 |
+
PESCETARIAN = "pescetarian"
|
| 14 |
+
WHOLE30 = "whole30"
|
| 15 |
+
HALAL = "halal"
|
| 16 |
+
LOW_FODMAP = "low fodmap"
|
| 17 |
+
|
| 18 |
class SimpleTool(Tool):
|
| 19 |
name = "CulinAI -- your AI Recipe Assistant"
|
| 20 |
description = "Gets a recipe suggestion based on provided ingredients, dietary preference, and your laziness level (1=active chef, 10=super lazy). After finding a recipe, itretrieves detailed recipe information."
|
|
|
|
| 24 |
"description": "A comma-separated string of available ingredients."
|
| 25 |
},
|
| 26 |
"diet": {
|
| 27 |
+
"type": "enum",
|
| 28 |
+
"enum": Diet,
|
| 29 |
+
"default": Diet.NONE,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
"nullable": True,
|
| 31 |
"description": "Select dietary restriction from the available options."
|
| 32 |
},
|
|
|
|
| 38 |
}
|
| 39 |
output_type = "string"
|
| 40 |
|
| 41 |
+
def forward(self, ingredients: str, diet: Optional[Diet] = Diet.NONE, laziness: Optional[int] = 5) -> str:
|
| 42 |
"""
|
| 43 |
Gets a recipe suggestion based on provided ingredients, dietary preference,
|
| 44 |
and your laziness level (1=active chef, 10=super lazy). After finding a recipe, it
|
|
|
|
| 54 |
"""
|
| 55 |
|
| 56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
import os
|
| 58 |
import requests
|
| 59 |
|
|
|
|
| 71 |
}
|
| 72 |
|
| 73 |
# Add diet if provided and not "none"
|
| 74 |
+
if diet and diet != Diet.NONE:
|
| 75 |
+
params["diet"] = diet.value
|
| 76 |
|
| 77 |
# Incorporate the laziness factor: filter by maxReadyTime if needed.
|
| 78 |
try:
|