Spaces:
Sleeping
Sleeping
Include search_cocktail_by_name tool
Browse filesInput a cocktail name, and the tool fetches details about it from TheCocktailDB API.
app.py
CHANGED
|
@@ -7,16 +7,49 @@ from tools.final_answer import FinalAnswerTool
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
-
|
| 11 |
@tool
|
| 12 |
-
def
|
| 13 |
-
|
| 14 |
-
|
|
|
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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:
|