Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,14 +9,42 @@ 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_cutom_tool(
|
| 13 |
-
#
|
| 14 |
-
|
| 15 |
-
Args:
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -51,7 +79,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 51 |
|
| 52 |
agent = CodeAgent(
|
| 53 |
model=model,
|
| 54 |
-
tools=[final_answer], ## add your tools here (don't remove final answer)
|
| 55 |
max_steps=6,
|
| 56 |
verbosity_level=1,
|
| 57 |
grammar=None,
|
|
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
+
def my_cutom_tool(animal_category: str) -> str: #it's import to specify the return type
|
| 13 |
+
# A tool that provides a random fun fact about animals.
|
| 14 |
+
|
| 15 |
+
# Args:
|
| 16 |
+
# animal_category: The category of animal (e.g., 'mammals', 'birds', 'reptiles')
|
| 17 |
+
#
|
| 18 |
+
animal_facts = {
|
| 19 |
+
'mammals': [
|
| 20 |
+
"A group of flamingos is called a 'flamboyance'.",
|
| 21 |
+
"Elephants are the only mammals that can't jump.",
|
| 22 |
+
"Kangaroos can't walk backwards."
|
| 23 |
+
],
|
| 24 |
+
'birds': [
|
| 25 |
+
"Some species of birds can sleep while flying.",
|
| 26 |
+
"The world's largest bird is the ostrich, which can grow up to 9 feet tall.",
|
| 27 |
+
"A flamingo can only eat when its head is upside down."
|
| 28 |
+
],
|
| 29 |
+
'reptiles': [
|
| 30 |
+
"The heart of a shrimp is located in its head.",
|
| 31 |
+
"Iguanas can stay underwater for up to 30 minutes.",
|
| 32 |
+
"A chameleon can move its eyes in two different directions at once!"
|
| 33 |
+
],
|
| 34 |
+
'fish': [
|
| 35 |
+
"Some fish can change their gender later in life.",
|
| 36 |
+
"The oldest known fish lived to be 200 years old.",
|
| 37 |
+
"Goldfish have a memory span of at least three months."
|
| 38 |
+
]
|
| 39 |
+
}
|
| 40 |
+
# Check if the animal_category is valid
|
| 41 |
+
if animal_category not in animal_facts:
|
| 42 |
+
return "Please provide a valid animal category (e.g. 'mammals', 'birds', 'reptiles', 'fish')."
|
| 43 |
+
|
| 44 |
+
# Choose a random fact based on the specified category
|
| 45 |
+
fact = random.choice(animal_facts[animal_category])
|
| 46 |
+
|
| 47 |
+
return f"Did you know? {fact}"
|
| 48 |
|
| 49 |
@tool
|
| 50 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 79 |
|
| 80 |
agent = CodeAgent(
|
| 81 |
model=model,
|
| 82 |
+
tools=[final_answer, my_custom_tool], ## add your tools here (don't remove final answer)
|
| 83 |
max_steps=6,
|
| 84 |
verbosity_level=1,
|
| 85 |
grammar=None,
|