helgn commited on
Commit
334c232
·
verified ·
1 Parent(s): 8815d4e

added new tool to app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -1
app.py CHANGED
@@ -16,8 +16,32 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
16
  arg1: the first argument
17
  arg2: the second argument
18
  """
 
19
  return "What magic will you build ?"
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  @tool
22
  def get_current_time_in_timezone(timezone: str) -> str:
23
  """A tool that fetches the current local time in a specified timezone.
@@ -56,7 +80,7 @@ with open("prompts.yaml", 'r') as stream:
56
 
57
  agent = CodeAgent(
58
  model=model,
59
- tools=[final_answer], ## add your tools here (don't remove final answer)
60
  max_steps=6,
61
  verbosity_level=1,
62
  grammar=None,
 
16
  arg1: the first argument
17
  arg2: the second argument
18
  """
19
+
20
  return "What magic will you build ?"
21
 
22
+ @tool
23
+ def get_calories(meal:str) -> str:
24
+ search_url = f"https://world.openfoodfacts.org/cgi/search.pl"
25
+ params = {
26
+ 'search_terms': meal,
27
+ 'search_simple': 1,
28
+ 'action': 'process',
29
+ 'json': 1
30
+ }
31
+ response = requests.get(search_url, params=params)
32
+
33
+ if response.status_code == 200:
34
+ data = response.json()
35
+ if data['count'] > 0:
36
+ product = data['products'][0]
37
+ calories = product.get('nutriments', {}).get('energy-kcal_100g', 'No data')
38
+ return calories
39
+ else:
40
+ return 'No data found'
41
+ else:
42
+ print(f"Failed to retrieve data: {response.status_code}")
43
+ return None
44
+
45
  @tool
46
  def get_current_time_in_timezone(timezone: str) -> str:
47
  """A tool that fetches the current local time in a specified timezone.
 
80
 
81
  agent = CodeAgent(
82
  model=model,
83
+ tools=[final_answer,get_calories], ## add your tools here (don't remove final answer)
84
  max_steps=6,
85
  verbosity_level=1,
86
  grammar=None,