Spaces:
Sleeping
Sleeping
Update app.py
Browse filesAdding custom tools
app.py
CHANGED
|
@@ -9,15 +9,24 @@ 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
|
| 13 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 14 |
-
"""A tool that
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
arg2: the second argument
|
| 18 |
"""
|
| 19 |
-
|
| 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 +64,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,
|
|
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
+
def get_random_dog_image(number_of_images: 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 retrieves one or more random dog images URL from the Dog CEO API.
|
| 15 |
Args:
|
| 16 |
+
number_of_images: An integer representing the number of dog images to be requested
|
|
|
|
| 17 |
"""
|
| 18 |
+
url = 'https://dog.ceo/api/breeds/image/random'
|
| 19 |
+
final_result = ''
|
| 20 |
+
for image_ind in range(number_of_images):
|
| 21 |
+
response = requests.get(url)
|
| 22 |
+
if response.status_code == 200:
|
| 23 |
+
data = response.json()
|
| 24 |
+
final_result += f'Image {image_ind}: ' + data['message'] + '\n'
|
| 25 |
+
else:
|
| 26 |
+
return f"Request failed with status code: {response.status_code}"
|
| 27 |
+
|
| 28 |
+
return final_result
|
| 29 |
+
|
| 30 |
@tool
|
| 31 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 32 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
|
| 64 |
|
| 65 |
agent = CodeAgent(
|
| 66 |
model=model,
|
| 67 |
+
tools=[final_answer, get_random_dog_image, get_current_time_in_timezone], ## add your tools here (don't remove final answer)
|
| 68 |
max_steps=6,
|
| 69 |
verbosity_level=1,
|
| 70 |
grammar=None,
|