CallmeKaito commited on
Commit
dbc7379
·
verified ·
1 Parent(s): dc110b2

Update tool.py

Browse files
Files changed (1) hide show
  1. tool.py +45 -5
tool.py CHANGED
@@ -1,14 +1,54 @@
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."
7
- inputs = {"ingredients":{"type":"string","description":"A comma-separated string of available ingredients."},"diet":{"type":"string","nullable":True,"description":"Dietary restrictions such as 'vegetarian', 'vegan', or 'gluten free'. Defaults to None."},"laziness":{"type":"integer","nullable":True,"description":"An integer from 1 (active) to 10 (super lazy); higher means recipes with quicker prep."}}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  output_type = "string"
9
 
10
-
11
- def forward(self, ingredients: str, diet: Optional[str] = None, laziness: Optional[int] = 5) -> str:
12
  """
13
  Gets a recipe suggestion based on provided ingredients, dietary preference,
14
  and your laziness level (1=active chef, 10=super lazy). After finding a recipe, it
@@ -38,8 +78,8 @@ class SimpleTool(Tool):
38
  "apiKey": api_key,
39
  }
40
 
41
- # Add diet if provided
42
- if diet:
43
  params["diet"] = diet
44
 
45
  # Incorporate the laziness factor: filter by maxReadyTime if needed.
 
1
  from smolagents import Tool
2
  from typing import Optional
3
 
4
+ # Define valid diet options as a Literal type
5
+ DietType = Literal[
6
+ "none",
7
+ "vegetarian",
8
+ "vegan",
9
+ "gluten free",
10
+ "ketogenic",
11
+ "paleo",
12
+ "pescetarian",
13
+ "whole30",
14
+ "halal",
15
+ "low fodmap"
16
+ ]
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."
21
+ inputs = {
22
+ "ingredients": {
23
+ "type": "string",
24
+ "description": "A comma-separated string of available ingredients."
25
+ },
26
+ "diet": {
27
+ "type": "string",
28
+ "enum": [
29
+ "none",
30
+ "vegetarian",
31
+ "vegan",
32
+ "gluten free",
33
+ "ketogenic",
34
+ "paleo",
35
+ "pescetarian",
36
+ "whole30",
37
+ "halal",
38
+ "low fodmap"
39
+ ],
40
+ "default": "none",
41
+ "description": "Select dietary restriction from the available options."
42
+ },
43
+ "laziness": {
44
+ "type": "integer",
45
+ "nullable": True,
46
+ "description": "An integer from 1 (active) to 10 (super lazy); higher means recipes with quicker prep."
47
+ }
48
+ }
49
  output_type = "string"
50
 
51
+ def forward(self, ingredients: str, diet: DietType = "none", laziness: Optional[int] = 5) -> str:
 
52
  """
53
  Gets a recipe suggestion based on provided ingredients, dietary preference,
54
  and your laziness level (1=active chef, 10=super lazy). After finding a recipe, it
 
78
  "apiKey": api_key,
79
  }
80
 
81
+ # Add diet if provided and not "none"
82
+ if diet and diet != "none":
83
  params["diet"] = diet
84
 
85
  # Incorporate the laziness factor: filter by maxReadyTime if needed.