mikethor007 commited on
Commit
9758d8e
·
verified ·
1 Parent(s): 06110ba

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +163 -1
app.py CHANGED
@@ -83,12 +83,167 @@ prompt_python_execute = """You are a python code execution agent.
83
  After you're done with your tasks, respond to the supervisor directly
84
  Respond ONLY with the results of your work, do NOT include ANY other text."""
85
 
 
 
 
 
 
 
86
  #TOOLS
87
  web_search = TavilySearch(
88
  max_results=5,
89
  topic="general",
90
  )
91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
  def python_code_runner_tool(task_id:str) -> str:
93
  """
94
  Download and run python code, capturing the output.
@@ -325,9 +480,16 @@ python_code_runner_agent = create_react_agent(
325
  name="python_code_runner_agent"
326
  )
327
 
 
 
 
 
 
 
 
328
  supervisor = create_supervisor(
329
  model=gemini_llm,
330
- agents=[web_research_agent,chess_position_review_agent,python_code_runner_agent],
331
  prompt=prompt_recomendado,
332
  add_handoff_back_messages=True,
333
  output_mode="full_history"
 
83
  After you're done with your tasks, respond to the supervisor directly
84
  Respond ONLY with the results of your work, do NOT include ANY other text."""
85
 
86
+ prompt_botanical_classification = """You are a vegetable botanical classification agent.
87
+ INSTRUCTIONS:
88
+ Assist ONLY with tasks related to classificating vegatables, DO NOT do any math
89
+ After you're done with your tasks, respond to the supervisor directly
90
+ Respond ONLY with the results of your work, do NOT include ANY other text."""
91
+
92
  #TOOLS
93
  web_search = TavilySearch(
94
  max_results=5,
95
  topic="general",
96
  )
97
 
98
+ def get_botanical_classification_tool(item_name):
99
+ """
100
+ Provides the botanical classification (fruit, vegetable, or other)
101
+ for a given food item, adhering to botanical definitions.
102
+ Args:
103
+ item_name (str): The name of the food item (e.g., "bell pepper", "sweet potato").
104
+ Returns:
105
+ dict: A dictionary containing:
106
+ - 'item': The normalized item name.
107
+ - 'botanical_category': 'fruit', 'vegetable', 'other', or 'unclassified'.
108
+ - 'botanical_part': The botanical part of the plant (e.g., 'matured ovary', 'root', 'leaf'),
109
+ or 'N/A' if not applicable/unknown.
110
+ - 'notes': Any additional botanical notes or clarifications.
111
+ """
112
+
113
+ # --- Curated Botanical Database ---
114
+ # This dictionary holds the botanical classifications.
115
+ # It's crucial this data is accurate according to botanical science.
116
+ # You will need to expand this as needed for your full grocery list.
117
+ botanical_data = {
118
+ "sweet potatoes": {
119
+ "botanical_category": "vegetable",
120
+ "botanical_part": "root/tuber",
121
+ "notes": "Edible root of the plant."
122
+ },
123
+ "fresh basil": {
124
+ "botanical_category": "vegetable",
125
+ "botanical_part": "leaf",
126
+ "notes": "Edible leaves of the herb."
127
+ },
128
+ "plums": {
129
+ "botanical_category": "fruit",
130
+ "botanical_part": "matured ovary",
131
+ "notes": "Simple fleshy fruit (drupe)."
132
+ },
133
+ "green beans": {
134
+ "botanical_category": "fruit",
135
+ "botanical_part": "matured ovary (legume)",
136
+ "notes": "Botanically a fruit (legume) containing seeds."
137
+ },
138
+ "rice": {
139
+ "botanical_category": "fruit",
140
+ "botanical_part": "matured ovary (caryopsis)",
141
+ "notes": "A grain, which is botanically a dry fruit (caryopsis)."
142
+ },
143
+ "corn": {
144
+ "botanical_category": "fruit",
145
+ "botanical_part": "matured ovary (caryopsis)",
146
+ "notes": "A grain, which is botanically a dry fruit (caryopsis)."
147
+ },
148
+ "bell pepper": {
149
+ "botanical_category": "fruit",
150
+ "botanical_part": "matured ovary",
151
+ "notes": "Developed from the flower's ovary and contains seeds."
152
+ },
153
+ "whole allspice": { # Allspice berries
154
+ "botanical_category": "fruit",
155
+ "botanical_part": "dried berry",
156
+ "notes": "Dried unripe berries of the Pimenta dioica plant."
157
+ },
158
+ "acorns": {
159
+ "botanical_category": "fruit",
160
+ "botanical_part": "nut (type of dry fruit)",
161
+ "notes": "A nut, which is botanically a type of dry fruit."
162
+ },
163
+ "broccoli": {
164
+ "botanical_category": "vegetable",
165
+ "botanical_part": "flower/stem",
166
+ "notes": "Edible flower heads and stalks."
167
+ },
168
+ "celery": {
169
+ "botanical_category": "vegetable",
170
+ "botanical_part": "stem/petiole",
171
+ "notes": "Edible leaf stalks."
172
+ },
173
+ "zucchini": {
174
+ "botanical_category": "fruit",
175
+ "botanical_part": "matured ovary",
176
+ "notes": "A type of berry (pepo) from a flowering plant."
177
+ },
178
+ "lettuce": {
179
+ "botanical_category": "vegetable",
180
+ "botanical_part": "leaf",
181
+ "notes": "Edible leaves."
182
+ },
183
+ "peanuts": {
184
+ "botanical_category": "fruit",
185
+ "botanical_part": "legume (matured ovary)",
186
+ "notes": "Botanically a fruit (legume), despite growing underground."
187
+ },
188
+ # Non-plant items or items not strictly fruit/vegetable botanically
189
+ "milk": {
190
+ "botanical_category": "other",
191
+ "botanical_part": "N/A",
192
+ "notes": "Dairy product (animal)."
193
+ },
194
+ "eggs": {
195
+ "botanical_category": "other",
196
+ "botanical_part": "N/A",
197
+ "notes": "Animal product."
198
+ },
199
+ "flour": {
200
+ "botanical_category": "other",
201
+ "botanical_part": "N/A",
202
+ "notes": "Processed grain product (typically wheat, which is a fruit)."
203
+ },
204
+ "whole bean coffee": {
205
+ "botanical_category": "other", # The bean itself is a seed, not the entire fruit
206
+ "botanical_part": "seed",
207
+ "notes": "The coffee 'bean' is botanically the seed of the coffee cherry (a fruit)."
208
+ },
209
+ "oreos": {
210
+ "botanical_category": "other",
211
+ "botanical_part": "N/A",
212
+ "notes": "Processed food item."
213
+ }
214
+ }
215
+
216
+ # Normalize the input item name for lookup
217
+ normalized_item = item_name.strip().lower()
218
+
219
+ # Handle pluralization/singularization for common cases if not explicitly in data
220
+ # This is a simple approach; for more robustness, you'd need a proper NLP library.
221
+ if normalized_item.endswith("s") and normalized_item[:-1] in botanical_data:
222
+ normalized_item = normalized_item[:-1]
223
+ elif normalized_item + "s" in botanical_data:
224
+ # Check if the plural form exists if input is singular
225
+ if item_name.strip().lower() + "s" in botanical_data:
226
+ normalized_item = item_name.strip().lower() + "s"
227
+
228
+ # Retrieve classification
229
+ classification = botanical_data.get(normalized_item)
230
+
231
+ if classification:
232
+ return {
233
+ "item": item_name,
234
+ "botanical_category": classification["botanical_category"],
235
+ "botanical_part": classification["botanical_part"],
236
+ "notes": classification["notes"]
237
+ }
238
+ else:
239
+ # If the item is not found in the database
240
+ return {
241
+ "item": item_name,
242
+ "botanical_category": "unclassified",
243
+ "botanical_part": "N/A",
244
+ "notes": "Classification not found in the current database."
245
+ }
246
+
247
  def python_code_runner_tool(task_id:str) -> str:
248
  """
249
  Download and run python code, capturing the output.
 
480
  name="python_code_runner_agent"
481
  )
482
 
483
+ vegetable_botanical_classification_agent = create_react_agent(
484
+ model=gemini_llm,
485
+ tools=[get_botanical_classification_tool],
486
+ prompt=prompt_botanical_classification,
487
+ name="vegetable_botanical_classification_agent"
488
+ )
489
+
490
  supervisor = create_supervisor(
491
  model=gemini_llm,
492
+ agents=[web_research_agent,chess_position_review_agent,python_code_runner_agent,vegetable_botanical_classification_agent],
493
  prompt=prompt_recomendado,
494
  add_handoff_back_messages=True,
495
  output_mode="full_history"