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|
|
|
| 1 |
+
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
|
| 2 |
+
import datetime
|
| 3 |
+
import requests
|
| 4 |
+
import pytz
|
| 5 |
+
import yaml
|
| 6 |
+
import random
|
| 7 |
+
from tools.final_answer import FinalAnswerTool
|
| 8 |
+
from Gradio_UI import GradioUI
|
| 9 |
+
|
| 10 |
+
@tool
|
| 11 |
+
def excuse_generator(situation: str, formality_level: str = "casual") -> str:
|
| 12 |
+
"""A tool that generates creative excuses for various situations
|
| 13 |
+
|
| 14 |
+
Args:
|
| 15 |
+
situation: The situation requiring an excuse (e.g., 'late_to_meeting', 'missing_deadline', 'forgot_birthday')
|
| 16 |
+
formality_level: How formal the excuse should be ('casual', 'professional', or 'elaborate')
|
| 17 |
+
"""
|
| 18 |
+
|
| 19 |
+
excuse_components = {
|
| 20 |
+
'tech_problems': [
|
| 21 |
+
"my smart home went into lockdown mode",
|
| 22 |
+
"my AI assistant started writing poetry instead of setting alarms",
|
| 23 |
+
"my laptop decided to update all 247 applications at once",
|
| 24 |
+
"my coffee maker hacked my calendar and deleted all my meetings",
|
| 25 |
+
"my virtual reality headset trapped me in a meditation session"
|
| 26 |
+
],
|
| 27 |
+
'transportation': [
|
| 28 |
+
"a parade of ducks was crossing the road",
|
| 29 |
+
"my car's GPS insisted on taking me through a renaissance fair",
|
| 30 |
+
"my bicycle was requisitioned by time travelers",
|
| 31 |
+
"a group of joggers mistook me for their running coach",
|
| 32 |
+
"my helicopter uber got stuck in a cloud"
|
| 33 |
+
],
|
| 34 |
+
'pet_related': [
|
| 35 |
+
"my cat unplugged my alarm clock to charge their phone",
|
| 36 |
+
"my dog ate my keys and the vet was closed",
|
| 37 |
+
"my goldfish needed emotional support",
|
| 38 |
+
"my hamster staged a protest for better wheel conditions",
|
| 39 |
+
"my pet plant needed emergency repotting"
|
| 40 |
+
],
|
| 41 |
+
'weather': [
|
| 42 |
+
"a localized rain cloud followed me around all morning",
|
| 43 |
+
"a rainbow appeared and I had to document it for science",
|
| 44 |
+
"the wind kept pushing me in the wrong direction",
|
| 45 |
+
"a mysterious fog turned my neighborhood into a maze",
|
| 46 |
+
"the sun was in my eyes (it was night time)"
|
| 47 |
+
],
|
| 48 |
+
'professional': [
|
| 49 |
+
"I was trapped in an endless email chain",
|
| 50 |
+
"the coffee machine initiated a workplace revolution",
|
| 51 |
+
"my keyboard only typed in emoji",
|
| 52 |
+
"my desk chair rolled me into an impromptu meeting",
|
| 53 |
+
"my productivity app became too productive"
|
| 54 |
+
]
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
situation_categories = {
|
| 58 |
+
'late_to_meeting': ['tech_problems', 'transportation', 'professional'],
|
| 59 |
+
'missing_deadline': ['tech_problems', 'professional'],
|
| 60 |
+
'forgot_birthday': ['tech_problems', 'pet_related'],
|
| 61 |
+
'missed_call': ['tech_problems', 'weather', 'pet_related'],
|
| 62 |
+
'general': ['tech_problems', 'transportation', 'pet_related', 'weather', 'professional']
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
formality_modifiers = {
|
| 66 |
+
'casual': [
|
| 67 |
+
"You're not gonna believe this, but...",
|
| 68 |
+
"So, funny story...",
|
| 69 |
+
"Well...",
|
| 70 |
+
"Here's the thing...",
|
| 71 |
+
"Would you believe..."
|
| 72 |
+
],
|
| 73 |
+
'professional': [
|
| 74 |
+
"I regret to inform you that...",
|
| 75 |
+
"Due to unforeseen circumstances...",
|
| 76 |
+
"I must apologize, as...",
|
| 77 |
+
"Please be advised that...",
|
| 78 |
+
"I am writing to inform you that..."
|
| 79 |
+
],
|
| 80 |
+
'elaborate': [
|
| 81 |
+
"In an unprecedented turn of events that defies explanation...",
|
| 82 |
+
"Through a series of increasingly improbable occurrences...",
|
| 83 |
+
"In what can only be described as a cosmic convergence of unlikely events...",
|
| 84 |
+
"After careful consideration of the extraordinary circumstances...",
|
| 85 |
+
"In a stunning display of Murphy's Law..."
|
| 86 |
+
]
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
# Default to 'general' if situation not found
|
| 90 |
+
valid_categories = situation_categories.get(situation, situation_categories['general'])
|
| 91 |
+
|
| 92 |
+
# Select random category and excuse from that category
|
| 93 |
+
category = random.choice(valid_categories)
|
| 94 |
+
core_excuse = random.choice(excuse_components[category])
|
| 95 |
+
|
| 96 |
+
# Add formality modifier
|
| 97 |
+
modifier = random.choice(formality_modifiers.get(formality_level, formality_modifiers['casual']))
|
| 98 |
+
|
| 99 |
+
# Construct the full excuse
|
| 100 |
+
full_excuse = f"{modifier} {core_excuse}"
|
| 101 |
+
|
| 102 |
+
# Add a random consequence for elaborate excuses
|
| 103 |
+
if formality_level == 'elaborate':
|
| 104 |
+
consequences = [
|
| 105 |
+
"This naturally led to a cascade of bureaucratic complications.",
|
| 106 |
+
"The authorities have been notified, but they were equally puzzled.",
|
| 107 |
+
"I'm still waiting for the insurance adjuster to stop laughing.",
|
| 108 |
+
"The local news has already contacted me for an exclusive.",
|
| 109 |
+
"Scientists are currently studying the phenomenon."
|
| 110 |
+
]
|
| 111 |
+
full_excuse += f" {random.choice(consequences)}"
|
| 112 |
+
|
| 113 |
+
return full_excuse
|
| 114 |
+
|
| 115 |
+
@tool
|
| 116 |
+
def get_current_time_in_timezone(timezone: str) -> str:
|
| 117 |
+
"""A tool that fetches the current local time in a specified timezone.
|
| 118 |
+
|
| 119 |
+
Args:
|
| 120 |
+
timezone: A string representing a valid timezone (e.g., 'America/New_York').
|
| 121 |
+
"""
|
| 122 |
+
try:
|
| 123 |
+
tz = pytz.timezone(timezone)
|
| 124 |
+
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
| 125 |
+
return f"The current local time in {timezone} is: {local_time}"
|
| 126 |
+
except Exception as e:
|
| 127 |
+
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 128 |
+
|
| 129 |
+
final_answer = FinalAnswerTool()
|
| 130 |
+
|
| 131 |
+
model = HfApiModel(
|
| 132 |
+
max_tokens=2096,
|
| 133 |
+
temperature=0.5,
|
| 134 |
+
model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud',
|
| 135 |
+
custom_role_conversions=None,
|
| 136 |
+
)
|
| 137 |
+
|
| 138 |
+
# Import tool from Hub
|
| 139 |
+
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 140 |
+
|
| 141 |
+
with open("prompts.yaml", 'r') as stream:
|
| 142 |
+
prompt_templates = yaml.safe_load(stream)
|
| 143 |
+
|
| 144 |
+
agent = CodeAgent(
|
| 145 |
+
model=model,
|
| 146 |
+
tools=[get_current_time_in_timezone, excuse_generator, DuckDuckGoSearchTool(), final_answer],
|
| 147 |
+
max_steps=6,
|
| 148 |
+
verbosity_level=1,
|
| 149 |
+
grammar=None,
|
| 150 |
+
planning_interval=None,
|
| 151 |
+
name=None,
|
| 152 |
+
description=None,
|
| 153 |
+
prompt_templates=prompt_templates
|
| 154 |
+
)
|
| 155 |
+
|
| 156 |
+
GradioUI(agent).launch()
|
app.py_orig
DELETED
|
@@ -1,93 +0,0 @@
|
|
| 1 |
-
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
|
| 2 |
-
import datetime
|
| 3 |
-
import requests
|
| 4 |
-
import pytz
|
| 5 |
-
import yaml
|
| 6 |
-
import random
|
| 7 |
-
from tools.final_answer import FinalAnswerTool
|
| 8 |
-
from Gradio_UI import GradioUI
|
| 9 |
-
|
| 10 |
-
@tool
|
| 11 |
-
def magic_8_ball(question: str, asker_name: str) -> str:
|
| 12 |
-
"""A Magic 8 Ball tool that provides fortune-telling responses to yes/no questions
|
| 13 |
-
|
| 14 |
-
Args:
|
| 15 |
-
question: The question being asked to the Magic 8 Ball
|
| 16 |
-
asker_name: The name of the person asking the question
|
| 17 |
-
"""
|
| 18 |
-
responses = [
|
| 19 |
-
# Positive responses
|
| 20 |
-
"It is certain.",
|
| 21 |
-
"It is decidedly so.",
|
| 22 |
-
"Without a doubt.",
|
| 23 |
-
"Yes definitely.",
|
| 24 |
-
"You may rely on it.",
|
| 25 |
-
"As I see it, yes.",
|
| 26 |
-
"Most likely.",
|
| 27 |
-
"Outlook good.",
|
| 28 |
-
"Yes.",
|
| 29 |
-
"Signs point to yes.",
|
| 30 |
-
|
| 31 |
-
# Non-committal responses
|
| 32 |
-
"Reply hazy, try again.",
|
| 33 |
-
"Ask again later.",
|
| 34 |
-
"Better not tell you now.",
|
| 35 |
-
"Cannot predict now.",
|
| 36 |
-
"Concentrate and ask again.",
|
| 37 |
-
|
| 38 |
-
# Negative responses
|
| 39 |
-
"Don't count on it.",
|
| 40 |
-
"My reply is no.",
|
| 41 |
-
"My sources say no.",
|
| 42 |
-
"Outlook not so good.",
|
| 43 |
-
"Very doubtful."
|
| 44 |
-
]
|
| 45 |
-
|
| 46 |
-
# Get random response
|
| 47 |
-
answer = random.choice(responses)
|
| 48 |
-
return f"🎱 Dear {asker_name}, you asked: '{question}'\nThe Magic 8 Ball says: {answer}"
|
| 49 |
-
|
| 50 |
-
@tool
|
| 51 |
-
def get_current_time_in_timezone(timezone: str) -> str:
|
| 52 |
-
"""A tool that fetches the current local time in a specified timezone.
|
| 53 |
-
|
| 54 |
-
Args:
|
| 55 |
-
timezone: A string representing a valid timezone (e.g., 'America/New_York').
|
| 56 |
-
"""
|
| 57 |
-
try:
|
| 58 |
-
# Create timezone object
|
| 59 |
-
tz = pytz.timezone(timezone)
|
| 60 |
-
# Get current time in that timezone
|
| 61 |
-
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
| 62 |
-
return f"The current local time in {timezone} is: {local_time}"
|
| 63 |
-
except Exception as e:
|
| 64 |
-
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 65 |
-
|
| 66 |
-
final_answer = FinalAnswerTool()
|
| 67 |
-
|
| 68 |
-
model = HfApiModel(
|
| 69 |
-
max_tokens=2096,
|
| 70 |
-
temperature=0.5,
|
| 71 |
-
model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud',
|
| 72 |
-
custom_role_conversions=None,
|
| 73 |
-
)
|
| 74 |
-
|
| 75 |
-
# Import tool from Hub
|
| 76 |
-
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 77 |
-
|
| 78 |
-
with open("prompts.yaml", 'r') as stream:
|
| 79 |
-
prompt_templates = yaml.safe_load(stream)
|
| 80 |
-
|
| 81 |
-
agent = CodeAgent(
|
| 82 |
-
model=model,
|
| 83 |
-
tools=[get_current_time_in_timezone, magic_8_ball, DuckDuckGoSearchTool(), final_answer],
|
| 84 |
-
max_steps=6,
|
| 85 |
-
verbosity_level=1,
|
| 86 |
-
grammar=None,
|
| 87 |
-
planning_interval=None,
|
| 88 |
-
name=None,
|
| 89 |
-
description=None,
|
| 90 |
-
prompt_templates=prompt_templates
|
| 91 |
-
)
|
| 92 |
-
|
| 93 |
-
GradioUI(agent).launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|