added 2 new tools, and given to the agent
Browse files
app.py
CHANGED
|
@@ -9,14 +9,32 @@ 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 |
-
|
| 14 |
-
"""A tool that does nothing yet
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
arg2: the second argument
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -55,7 +73,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_joke(category: str = "Any") -> str:
|
| 13 |
+
"""Fetches a random joke from JokeAPI.
|
|
|
|
| 14 |
Args:
|
| 15 |
+
category: The joke category (e.g., 'Programming', 'Misc', 'Pun', 'Any').
|
|
|
|
| 16 |
"""
|
| 17 |
+
url = f"https://v2.jokeapi.dev/joke/{category}?type=twopart"
|
| 18 |
+
|
| 19 |
+
try:
|
| 20 |
+
response = requests.get(url).json()
|
| 21 |
+
if "setup" in response and "delivery" in response:
|
| 22 |
+
return f"{response['setup']} ... {response['delivery']}"
|
| 23 |
+
else:
|
| 24 |
+
return "Could not fetch a joke at this moment."
|
| 25 |
+
except Exception as e:
|
| 26 |
+
return f"Error fetching joke: {str(e)}"
|
| 27 |
+
|
| 28 |
+
@tool
|
| 29 |
+
def get_motivational_quote() -> str:
|
| 30 |
+
"""Fetches a random motivational quote."""
|
| 31 |
+
url = "https://api.quotable.io/random"
|
| 32 |
+
|
| 33 |
+
try:
|
| 34 |
+
response = requests.get(url).json()
|
| 35 |
+
return f"\"{response['content']}\" - {response['author']}"
|
| 36 |
+
except Exception as e:
|
| 37 |
+
return f"Error fetching quote: {str(e)}"
|
| 38 |
|
| 39 |
@tool
|
| 40 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 73 |
|
| 74 |
agent = CodeAgent(
|
| 75 |
model=model,
|
| 76 |
+
tools=[final_answer, get_current_time_in_timezone, get_random_joke, get_motivational_quote], ## add your tools here (don't remove final answer)
|
| 77 |
max_steps=6,
|
| 78 |
verbosity_level=1,
|
| 79 |
grammar=None,
|