Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,15 +9,34 @@ 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 |
-
arg1: the first argument
|
| 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.
|
|
@@ -53,9 +72,10 @@ image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_co
|
|
| 53 |
with open("prompts.yaml", 'r') as stream:
|
| 54 |
prompt_templates = yaml.safe_load(stream)
|
| 55 |
|
|
|
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[final_answer
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
|
@@ -65,5 +85,4 @@ agent = CodeAgent(
|
|
| 65 |
prompt_templates=prompt_templates
|
| 66 |
)
|
| 67 |
|
| 68 |
-
|
| 69 |
GradioUI(agent).launch()
|
|
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
+
def get_random_quote() -> str:
|
| 13 |
+
"""A tool that fetches a random quote from ZenQuotes API.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
"""
|
| 15 |
+
try:
|
| 16 |
+
response = requests.get("https://zenquotes.io/api/random")
|
| 17 |
+
data = response.json()
|
| 18 |
+
quote = data[0]["q"]
|
| 19 |
+
author = data[0]["a"]
|
| 20 |
+
return f"\"{quote}\" - {author}"
|
| 21 |
+
except Exception as e:
|
| 22 |
+
return f"Error fetching quote: {str(e)}"
|
| 23 |
+
|
| 24 |
|
| 25 |
+
@tool
|
| 26 |
+
def search_wikipedia(query: str) -> str:
|
| 27 |
+
"""A tool that searches for information on Wikipedia.
|
| 28 |
+
Args:
|
| 29 |
+
query: The search query.
|
| 30 |
+
"""
|
| 31 |
+
try:
|
| 32 |
+
response = requests.get(f"https://en.wikipedia.org/w/api.php?action=opensearch&search={query}&limit=1&format=json")
|
| 33 |
+
data = response.json()
|
| 34 |
+
title = data[1][0]
|
| 35 |
+
summary = data[2][0]
|
| 36 |
+
return f"**{title}**: {summary}"
|
| 37 |
+
except Exception as e:
|
| 38 |
+
return f"Error searching Wikipedia: {str(e)}"
|
| 39 |
+
|
| 40 |
@tool
|
| 41 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 42 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
|
| 72 |
with open("prompts.yaml", 'r') as stream:
|
| 73 |
prompt_templates = yaml.safe_load(stream)
|
| 74 |
|
| 75 |
+
|
| 76 |
agent = CodeAgent(
|
| 77 |
model=model,
|
| 78 |
+
tools=[final_answer, get_random_quote, get_current_time_in_timezone, search_wikipedia],
|
| 79 |
max_steps=6,
|
| 80 |
verbosity_level=1,
|
| 81 |
grammar=None,
|
|
|
|
| 85 |
prompt_templates=prompt_templates
|
| 86 |
)
|
| 87 |
|
|
|
|
| 88 |
GradioUI(agent).launch()
|