uasername commited on
Commit
ce140c3
·
verified ·
1 Parent(s): 91a0697

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -0
app.py CHANGED
@@ -18,6 +18,27 @@ 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
+ import requests
22
+
23
+ @tool
24
+ def get_random_cocktail() -> str:
25
+ """A tool that fetches a random cocktail recipe.
26
+ """
27
+ try:
28
+ response = requests.get('https://www.thecocktaildb.com/api/json/v1/1/random.php')
29
+ data = response.json()
30
+ if data and 'drinks' in data:
31
+ drink = data['drinks'][0]
32
+ cocktail_name = drink['strDrink']
33
+ ingredients = [drink[f'strIngredient{i}'] for i in range(1, 16) if drink[f'strIngredient{i}']]
34
+ instructions = drink['strInstructions']
35
+ return f"Cocktail: {cocktail_name}\nIngredients: {', '.join(ingredients)}\nInstructions: {instructions}"
36
+ else:
37
+ return "No cocktail found. Please try again."
38
+ except Exception as e:
39
+ return f"Error fetching random cocktail: {str(e)}"
40
+
41
+
42
  @tool
43
  def get_current_time_in_timezone(timezone: str) -> str:
44
  """A tool that fetches the current local time in a specified timezone.