Add futuristic code snippet tool and other custom tools
Browse files- Added `my_super_tool` to handle city-based operations.
- Implemented `generate_futuristic_code_snippet` for playful Python snippets.
- Included updated tools list in agent configuration.
- Maintained existing tools (time zone and dummy tool).
app.py
CHANGED
|
@@ -18,6 +18,14 @@ def my_cutom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
|
|
| 18 |
"""
|
| 19 |
return "What magic will you build ?"
|
| 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.
|
|
@@ -33,6 +41,70 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 33 |
except Exception as e:
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
final_answer = FinalAnswerTool()
|
| 38 |
model = HfApiModel(
|
|
@@ -51,7 +123,12 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 51 |
|
| 52 |
agent = CodeAgent(
|
| 53 |
model=model,
|
| 54 |
-
tools=[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
max_steps=6,
|
| 56 |
verbosity_level=1,
|
| 57 |
grammar=None,
|
|
|
|
| 18 |
"""
|
| 19 |
return "What magic will you build ?"
|
| 20 |
|
| 21 |
+
@tool
|
| 22 |
+
def my_super_tool(city: str) -> str:
|
| 23 |
+
"""A tool that does something interesting with a city.
|
| 24 |
+
Args:
|
| 25 |
+
city: The name of a city
|
| 26 |
+
"""
|
| 27 |
+
return f"I will do something special with {city}!"
|
| 28 |
+
|
| 29 |
@tool
|
| 30 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 31 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
|
| 41 |
except Exception as e:
|
| 42 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 43 |
|
| 44 |
+
@tool
|
| 45 |
+
def generate_futuristic_code_snippet(
|
| 46 |
+
company_name: str,
|
| 47 |
+
mission: str = None,
|
| 48 |
+
key_values: str = None
|
| 49 |
+
) -> str:
|
| 50 |
+
"""
|
| 51 |
+
Generates a futuristic-style Python code snippet given a company name,
|
| 52 |
+
an optional mission, and an optional set of key values.
|
| 53 |
+
|
| 54 |
+
Args:
|
| 55 |
+
company_name: The name of the company (e.g. "Design Thinking Japan")
|
| 56 |
+
mission: The company's mission statement (e.g. "Human Centered, AI Accelerated").
|
| 57 |
+
If not provided, a random futuristic mission is chosen.
|
| 58 |
+
key_values: A comma-separated string of key values (e.g. "empathy, innovation").
|
| 59 |
+
If not provided, a set of futuristic key values is randomly picked.
|
| 60 |
+
"""
|
| 61 |
+
# 1. Provide random defaults if mission/key_values are missing
|
| 62 |
+
random_missions = [
|
| 63 |
+
"Automate the intergalactic supply chain",
|
| 64 |
+
"Enlighten minds through quantum synergy",
|
| 65 |
+
"Transcend beyond the boundaries of reality",
|
| 66 |
+
"Engineer post-human empathy"
|
| 67 |
+
]
|
| 68 |
+
random_values = [
|
| 69 |
+
"hyper-collaboration",
|
| 70 |
+
"cosmic curiosity",
|
| 71 |
+
"matrix-like agility",
|
| 72 |
+
"singularity-driven passion"
|
| 73 |
+
]
|
| 74 |
+
|
| 75 |
+
if mission is None or not mission.strip():
|
| 76 |
+
mission = random.choice(random_missions)
|
| 77 |
+
|
| 78 |
+
if key_values is None or not key_values.strip():
|
| 79 |
+
# pick 2–3 random values
|
| 80 |
+
chosen_values = random.sample(random_values, k=2)
|
| 81 |
+
key_values = ", ".join(chosen_values)
|
| 82 |
+
|
| 83 |
+
# 2. Prepare the snippet lines
|
| 84 |
+
code_lines = [
|
| 85 |
+
f"def {company_name.lower().replace(' ', '_')}_futuristic():",
|
| 86 |
+
f" \"\"\"",
|
| 87 |
+
f" This function encapsulates {company_name}'s futuristic ambitions.",
|
| 88 |
+
f" Mission: {mission}",
|
| 89 |
+
f" Key Values: {key_values}",
|
| 90 |
+
f" \"\"\"",
|
| 91 |
+
" # Initiating hyper-drive synergy with mission parameters",
|
| 92 |
+
" synergy_level = 9999",
|
| 93 |
+
" dimensional_rift = True",
|
| 94 |
+
"",
|
| 95 |
+
" if dimensional_rift:",
|
| 96 |
+
" print(f'Breach opened! {company_name} is transcending conventional limits...')",
|
| 97 |
+
" else:",
|
| 98 |
+
" raise Exception('No rift detected. Expansion halted!')",
|
| 99 |
+
"",
|
| 100 |
+
f" print(f'{company_name} pushing forward with unstoppable momentum...')",
|
| 101 |
+
"",
|
| 102 |
+
f" return f'{company_name} has successfully infused the future with {mission}!'",
|
| 103 |
+
]
|
| 104 |
+
|
| 105 |
+
# 3. Combine the lines into a single string
|
| 106 |
+
snippet = "\n".join(code_lines)
|
| 107 |
+
return snippet
|
| 108 |
|
| 109 |
final_answer = FinalAnswerTool()
|
| 110 |
model = HfApiModel(
|
|
|
|
| 123 |
|
| 124 |
agent = CodeAgent(
|
| 125 |
model=model,
|
| 126 |
+
tools=[
|
| 127 |
+
final_answer, # Must always keep this
|
| 128 |
+
my_custom_tool, # The dummy one from the snippet
|
| 129 |
+
get_current_time_in_timezone, # The time-zone tool
|
| 130 |
+
my_super_tool,
|
| 131 |
+
generate_futuristic_code_snippet], ## add your tools here (don't remove final answer)
|
| 132 |
max_steps=6,
|
| 133 |
verbosity_level=1,
|
| 134 |
grammar=None,
|