Spaces:
Sleeping
Sleeping
:sparkles: New tool: Get cat image
Browse files
app.py
CHANGED
|
@@ -18,6 +18,28 @@ 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.
|
|
@@ -55,7 +77,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 55 |
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[final_answer], ## add your tools here (don't remove final answer)
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
|
|
|
| 18 |
"""
|
| 19 |
return "What magic will you build ?"
|
| 20 |
|
| 21 |
+
@tool
|
| 22 |
+
def get_cat_image(limit: int = 1) -> str:
|
| 23 |
+
"""A tool that get a random image of a cat
|
| 24 |
+
Args:
|
| 25 |
+
limit: Number of images to return between 1 and 100
|
| 26 |
+
"""
|
| 27 |
+
# URL for the cat image API
|
| 28 |
+
url = "https://api.thecatapi.com/v1/images/search"
|
| 29 |
+
|
| 30 |
+
# Send the GET request to the API
|
| 31 |
+
response = requests.get(url)
|
| 32 |
+
|
| 33 |
+
# Check if the request was successful
|
| 34 |
+
if response.status_code == 200:
|
| 35 |
+
# Extract the URL of the image from the response JSON
|
| 36 |
+
data = response.json() # Parse the response as JSON
|
| 37 |
+
image_url = data[0]['url'] # Extract the image URL
|
| 38 |
+
# print("Cat Image URL:", image_url)
|
| 39 |
+
return image_url
|
| 40 |
+
else:
|
| 41 |
+
return f"Failed to fetch data. Status code: {response.status_code}"
|
| 42 |
+
|
| 43 |
@tool
|
| 44 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 45 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
|
| 77 |
|
| 78 |
agent = CodeAgent(
|
| 79 |
model=model,
|
| 80 |
+
tools=[final_answer,get_cat_image], ## add your tools here (don't remove final answer)
|
| 81 |
max_steps=6,
|
| 82 |
verbosity_level=1,
|
| 83 |
grammar=None,
|