Update app.py
Browse files
app.py
CHANGED
|
@@ -37,7 +37,42 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 37 |
def secret_word() -> str:
|
| 38 |
"""A tool that gives you today's secret word."""
|
| 39 |
return "Pineapple"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
final_answer = FinalAnswerTool()
|
| 42 |
|
| 43 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
|
@@ -60,7 +95,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 60 |
|
| 61 |
agent = CodeAgent(
|
| 62 |
model=model,
|
| 63 |
-
tools=[final_answer, get_current_time_in_timezone, secret_word], ## add your tools here (don't remove final answer)
|
| 64 |
max_steps=6,
|
| 65 |
verbosity_level=1,
|
| 66 |
grammar=None,
|
|
|
|
| 37 |
def secret_word() -> str:
|
| 38 |
"""A tool that gives you today's secret word."""
|
| 39 |
return "Pineapple"
|
| 40 |
+
|
| 41 |
+
@tool
|
| 42 |
+
def on_this_day(date: str) -> str:
|
| 43 |
+
"""Search for notable historical events that happened on a given date using DuckDuckGo.
|
| 44 |
|
| 45 |
+
Args:
|
| 46 |
+
date: A string representing the date to search for (e.g., '27 February 1924' or '27 February').
|
| 47 |
+
|
| 48 |
+
Returns:
|
| 49 |
+
A formatted string summarizing a notable event on that date, along with a source link.
|
| 50 |
+
If no event is found, it states that nothing of note occurred.
|
| 51 |
+
"""
|
| 52 |
+
try:
|
| 53 |
+
# Construct the search query
|
| 54 |
+
query = f"notable events on {date} site:wikipedia.org"
|
| 55 |
+
|
| 56 |
+
# Use DuckDuckGoSearchTool to perform the search
|
| 57 |
+
search_results = DuckDuckGoSearchTool()(query)
|
| 58 |
+
|
| 59 |
+
# Check if any results were found
|
| 60 |
+
if not search_results or len(search_results) == 0:
|
| 61 |
+
return f"On the date {date}, nothing of note occurred."
|
| 62 |
+
|
| 63 |
+
# Extract the first search result (most relevant)
|
| 64 |
+
first_result = search_results[0]
|
| 65 |
+
|
| 66 |
+
# Ensure the search result contains a title and link
|
| 67 |
+
title = first_result.get("title", "Unknown Event")
|
| 68 |
+
link = first_result.get("href", "No source available")
|
| 69 |
+
|
| 70 |
+
return f"On the date {date}, {title}. More details: {link}"
|
| 71 |
+
|
| 72 |
+
except Exception as e:
|
| 73 |
+
return f"Error retrieving historical data for {date}: {str(e)}"
|
| 74 |
+
|
| 75 |
+
|
| 76 |
final_answer = FinalAnswerTool()
|
| 77 |
|
| 78 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
|
|
|
| 95 |
|
| 96 |
agent = CodeAgent(
|
| 97 |
model=model,
|
| 98 |
+
tools=[final_answer, get_current_time_in_timezone, secret_word, on_this_day], ## add your tools here (don't remove final answer)
|
| 99 |
max_steps=6,
|
| 100 |
verbosity_level=1,
|
| 101 |
grammar=None,
|