Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -7,16 +7,41 @@ 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 !
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
@tool
|
12 |
-
def
|
13 |
-
|
14 |
-
"""A tool that does nothing yet
|
15 |
Args:
|
16 |
-
|
17 |
-
|
|
|
18 |
"""
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
@tool
|
22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
@@ -42,22 +67,24 @@ model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
|
|
42 |
custom_role_conversions=None,
|
43 |
)
|
44 |
|
45 |
-
|
46 |
# Import tool from Hub
|
47 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
48 |
|
|
|
|
|
|
|
49 |
with open("prompts.yaml", 'r') as stream:
|
50 |
prompt_templates = yaml.safe_load(stream)
|
51 |
|
52 |
agent = CodeAgent(
|
53 |
model=model,
|
54 |
-
tools=[final_answer], ## add your tools here (don't remove final answer)
|
55 |
max_steps=6,
|
56 |
verbosity_level=1,
|
57 |
grammar=None,
|
58 |
planning_interval=None,
|
59 |
-
name=
|
60 |
-
description=
|
61 |
prompt_templates=prompt_templates
|
62 |
)
|
63 |
|
|
|
7 |
|
8 |
from Gradio_UI import GradioUI
|
9 |
|
10 |
+
# # Below is an example of a tool that does nothing. Amaze us with your creativity !
|
11 |
+
# @tool
|
12 |
+
# def my_cutom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
13 |
+
# #Keep this format for the description / args / args description but feel free to modify the tool
|
14 |
+
# """A tool that does nothing yet
|
15 |
+
# Args:
|
16 |
+
# arg1: the first argument
|
17 |
+
# arg2: the second argument
|
18 |
+
# """
|
19 |
+
# return "What magic will you build ?"
|
20 |
+
|
21 |
+
# Tool for currency conversion
|
22 |
@tool
|
23 |
+
def convert_currency(amount: float, from_currency: str, to_currency: str) -> str:
|
24 |
+
"""A tool that converts currency from one type to another.
|
|
|
25 |
Args:
|
26 |
+
amount: The amount to convert.
|
27 |
+
from_currency: The currency to convert from (e.g., 'USD').
|
28 |
+
to_currency: The currency to convert to (e.g., 'EUR').
|
29 |
"""
|
30 |
+
try:
|
31 |
+
url = f"https://api.exchangerate-api.com/v4/latest/{from_currency}"
|
32 |
+
response = requests.get(url).json()
|
33 |
+
|
34 |
+
if "rates" not in response:
|
35 |
+
return f"Error: Unable to fetch exchange rate for {from_currency}."
|
36 |
+
|
37 |
+
rate = response["rates"].get(to_currency)
|
38 |
+
if not rate:
|
39 |
+
return f"Error: {to_currency} is not a valid target currency."
|
40 |
+
|
41 |
+
converted_amount = amount * rate
|
42 |
+
return f"{amount} {from_currency} is equivalent to {converted_amount:.2f} {to_currency}."
|
43 |
+
except Exception as e:
|
44 |
+
return f"Error converting currency: {str(e)}"
|
45 |
|
46 |
@tool
|
47 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
67 |
custom_role_conversions=None,
|
68 |
)
|
69 |
|
|
|
70 |
# Import tool from Hub
|
71 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
72 |
|
73 |
+
# load search from duckduckgo
|
74 |
+
search_tool = DuckDuckGoSearchTool()
|
75 |
+
|
76 |
with open("prompts.yaml", 'r') as stream:
|
77 |
prompt_templates = yaml.safe_load(stream)
|
78 |
|
79 |
agent = CodeAgent(
|
80 |
model=model,
|
81 |
+
tools=[final_answer, search_tool, image_generation_tool, get_current_time_in_timezone, convert_currency], ## add your tools here (don't remove final answer)
|
82 |
max_steps=6,
|
83 |
verbosity_level=1,
|
84 |
grammar=None,
|
85 |
planning_interval=None,
|
86 |
+
name="My First Agent",
|
87 |
+
description="An AI agent that can search the web, generate images, fetch weather, get time zones, convert currency",
|
88 |
prompt_templates=prompt_templates
|
89 |
)
|
90 |
|