JSWolf commited on
Commit
53fdb74
·
verified ·
1 Parent(s): 8c5c24b

Include search_cocktail_by_name tool

Browse files

Input a cocktail name, and the tool fetches details about it from TheCocktailDB API.

Files changed (1) hide show
  1. app.py +40 -7
app.py CHANGED
@@ -7,16 +7,49 @@ from tools.final_answer import FinalAnswerTool
7
 
8
  from Gradio_UI import GradioUI
9
 
10
- # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
- def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
13
- #Keep this format for the description / args / args description but feel free to modify the tool
14
- """A tool that does nothing yet
 
15
  Args:
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:
 
7
 
8
  from Gradio_UI import GradioUI
9
 
10
+
11
  @tool
12
+ def search_cocktail_by_name(cocktail_name: str):
13
+ """
14
+ Search a cocktail by name using TheCocktailDB API.
15
+
16
  Args:
17
+ cocktail_name (str): The name of the cocktail to search.
18
+
19
+ Returns:
20
+ dict: Cocktail information or None if not found.
21
  """
22
+ url = f"https://www.thecocktaildb.com/api/json/v1/1/search.php?s={cocktail_name}"
23
+ response = requests.get(url)
24
+
25
+ if response.status_code != 200:
26
+ return {"error": f"Request failed with status code {response.status_code}"}
27
+
28
+ data = response.json()
29
+ drinks = data.get('drinks')
30
+
31
+ if not drinks:
32
+ return {"message": "No cocktails found with that name."}
33
+
34
+ result = []
35
+ for drink in drinks:
36
+ ingredients = []
37
+ for i in range(1, 16):
38
+ ingredient = drink.get(f"strIngredient{i}")
39
+ measure = drink.get(f"strMeasure{i}")
40
+ if ingredient:
41
+ ingredients.append(f"{measure or ''} {ingredient}".strip())
42
+
43
+ result.append({
44
+ "name": drink.get("strDrink"),
45
+ "category": drink.get("strCategory"),
46
+ "glass": drink.get("strGlass"),
47
+ "instructions": drink.get("strInstructions"),
48
+ "ingredients": ingredients,
49
+ "image": drink.get("strDrinkThumb")
50
+ })
51
+
52
+ return result
53
 
54
  @tool
55
  def get_current_time_in_timezone(timezone: str) -> str: