BioCodeFusion commited on
Commit
87c36d3
·
verified ·
1 Parent(s): 8c5c24b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py CHANGED
@@ -18,6 +18,40 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
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.
 
18
  """
19
  return "What magic will you build ?"
20
 
21
+ @tool
22
+ def grocery_info(version=1, grocery_id: int, sprak=2):
23
+ """A tool that fetches the grocery information from the Swedish Food Agency api
24
+ Args:
25
+ version: version of tool argument.
26
+ grocery_id: The id of the grocery (e.g, and int expected)
27
+ language: Choose between Swedish or English language: (1 for Swedish, set to two for English)
28
+
29
+ Output:
30
+ The first element is the grocery name
31
+ The second element is the link for ingredient of the grocery to be used in the ingredients function
32
+ """
33
+
34
+ base_url = "https://dataportal.livsmedelsverket.se/livsmedel"
35
+ grocery_api_url = f"{base_url}/api/v{version}/livsmedel/{grocery_id}?sprak={sprak}"
36
+
37
+ response = requests.get(grocery_api_url)
38
+ data = response.json()
39
+
40
+ if response.status_code == 200:
41
+ data = response.json()
42
+ return data.get("namn"),data.get("links")[2]['href']
43
+ else:
44
+ return "Error: Unable to find grocery data."
45
+
46
+ @tool
47
+ def ingredients(ingred_url=ingredient_link):
48
+ ingredient_api_url = f"{base_url}{ingred_url}"
49
+
50
+ response=requests.get(ingredient_api_url)
51
+ data=response.json()
52
+
53
+ return data[0]['namn']
54
+
55
  @tool
56
  def get_current_time_in_timezone(timezone: str) -> str:
57
  """A tool that fetches the current local time in a specified timezone.