Update app.py
Browse files
app.py
CHANGED
@@ -5,6 +5,9 @@ import pytz
|
|
5 |
import yaml
|
6 |
from tools.final_answer import FinalAnswerTool
|
7 |
|
|
|
|
|
|
|
8 |
from Gradio_UI import GradioUI
|
9 |
|
10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
@@ -18,6 +21,46 @@ def my_custom_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.
|
@@ -55,7 +98,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
55 |
|
56 |
agent = CodeAgent(
|
57 |
model=model,
|
58 |
-
tools=[final_answer], ## add your tools here (don't remove final answer)
|
59 |
max_steps=6,
|
60 |
verbosity_level=1,
|
61 |
grammar=None,
|
|
|
5 |
import yaml
|
6 |
from tools.final_answer import FinalAnswerTool
|
7 |
|
8 |
+
# import random
|
9 |
+
import random
|
10 |
+
|
11 |
from Gradio_UI import GradioUI
|
12 |
|
13 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
|
|
21 |
"""
|
22 |
return "What magic will you build ?"
|
23 |
|
24 |
+
@tool
|
25 |
+
def generate_cat_name(personality:str)-> str:
|
26 |
+
"""
|
27 |
+
A tool that generates a cat name based on personality trait.
|
28 |
+
Args:
|
29 |
+
personality: A personality and or a trait description
|
30 |
+
"""
|
31 |
+
|
32 |
+
personality = personality.lower().strip()
|
33 |
+
|
34 |
+
cat_name_options = {
|
35 |
+
"playful": ["Whiskers", "Jinx"],
|
36 |
+
"lazy": ["Napper", "Dozer", "Snoozy", "Pillow", "Flop"],
|
37 |
+
"mysterious": ["Shadow", "Midnight"],
|
38 |
+
"elegant": ["Duchess", "Baron"],
|
39 |
+
"shy": ["Whisper", "Hush"],
|
40 |
+
"adventurous": ["Scout", "Rover"],
|
41 |
+
"grumpy": ["Grucho", "Cranky"],
|
42 |
+
}
|
43 |
+
|
44 |
+
|
45 |
+
# If personality is not found, then this could be the default names
|
46 |
+
default_names = ["Leo", "Luna", "Simba"]
|
47 |
+
|
48 |
+
# Find the most similar category if exact match not found
|
49 |
+
matching_category = None
|
50 |
+
|
51 |
+
for category in cat_name_options:
|
52 |
+
if category in personality or personality in category:
|
53 |
+
matching_category = category
|
54 |
+
break
|
55 |
+
|
56 |
+
if matching_category:
|
57 |
+
name = random.choice(cat_name_options[matching_category])
|
58 |
+
return f"Based on the '{matching_category}' personality, I recommend the cat name {name}"
|
59 |
+
else:
|
60 |
+
name = random.choice(default_names)
|
61 |
+
return f"Here's a classic name for your cat: {name}"
|
62 |
+
|
63 |
+
|
64 |
@tool
|
65 |
def get_current_time_in_timezone(timezone: str) -> str:
|
66 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
98 |
|
99 |
agent = CodeAgent(
|
100 |
model=model,
|
101 |
+
tools=[generate_cat_name, final_answer], ## add your tools here (don't remove final answer)
|
102 |
max_steps=6,
|
103 |
verbosity_level=1,
|
104 |
grammar=None,
|