Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -46,6 +46,42 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 46 |
except Exception as e:
|
| 47 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
final_answer = FinalAnswerTool()
|
| 51 |
|
|
@@ -68,7 +104,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 68 |
|
| 69 |
agent = CodeAgent(
|
| 70 |
model=model,
|
| 71 |
-
tools=[final_answer,get_two_liner_roast,get_current_time_in_timezone], ## add your tools here (don't remove final answer)
|
| 72 |
max_steps=6,
|
| 73 |
verbosity_level=1,
|
| 74 |
grammar=None,
|
|
|
|
| 46 |
except Exception as e:
|
| 47 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 48 |
|
| 49 |
+
@tool
|
| 50 |
+
def funny_hi_response(_: str = "") -> str:
|
| 51 |
+
"""Returns a funny or sarcastic response to someone saying 'Hi'."""
|
| 52 |
+
import random
|
| 53 |
+
|
| 54 |
+
responses = [
|
| 55 |
+
"Oh hey, look who remembered how to type!",
|
| 56 |
+
"Hi? That’s it? After everything we’ve been through?",
|
| 57 |
+
"Welcome back, I almost started enjoying the silence.",
|
| 58 |
+
"Hi there, social butterfly. Slow day?",
|
| 59 |
+
"If I had a nickel for every 'Hi' I got… I’d still be broke.",
|
| 60 |
+
"Wow, a 'Hi'? You sure you didn’t mean to send that to your other assistant?",
|
| 61 |
+
"Hello, mortal. What wisdom dost thou seek today?",
|
| 62 |
+
"Hi. I was hoping for pizza, but I guess you’ll do.",
|
| 63 |
+
"You say 'Hi', I hear 'I'm bored, entertain me.'",
|
| 64 |
+
"A wild user appeared! What shall we do now?"
|
| 65 |
+
]
|
| 66 |
+
|
| 67 |
+
return random.choice(responses)
|
| 68 |
+
|
| 69 |
+
@tool
|
| 70 |
+
def answer_with_duckduckgo(query: str) -> str:
|
| 71 |
+
"""Uses DuckDuckGo to search and return an answer to any user question.
|
| 72 |
+
|
| 73 |
+
Args:
|
| 74 |
+
query: A natural language question from the user.
|
| 75 |
+
Returns:
|
| 76 |
+
A short answer or summary from DuckDuckGo.
|
| 77 |
+
"""
|
| 78 |
+
try:
|
| 79 |
+
duck_tool = DuckDuckGoSearchTool()
|
| 80 |
+
result = duck_tool.run(query)
|
| 81 |
+
return result or "No relevant results found, but hey, at least I tried."
|
| 82 |
+
except Exception as e:
|
| 83 |
+
return f"Oops! I ran into an issue while searching: {str(e)}"
|
| 84 |
+
|
| 85 |
|
| 86 |
final_answer = FinalAnswerTool()
|
| 87 |
|
|
|
|
| 104 |
|
| 105 |
agent = CodeAgent(
|
| 106 |
model=model,
|
| 107 |
+
tools=[final_answer,get_two_liner_roast,get_current_time_in_timezone,funny_hi_response,answer_with_duckduckgo], ## add your tools here (don't remove final answer)
|
| 108 |
max_steps=6,
|
| 109 |
verbosity_level=1,
|
| 110 |
grammar=None,
|