Files changed (1) hide show
  1. app.py +85 -5
app.py CHANGED
@@ -7,6 +7,7 @@ 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 my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
@@ -17,6 +18,74 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
17
  arg2: the second argument
18
  """
19
  return "What magic will you build ?"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
  @tool
22
  def get_current_time_in_timezone(timezone: str) -> str:
@@ -35,6 +104,16 @@ def get_current_time_in_timezone(timezone: str) -> str:
35
 
36
 
37
  final_answer = FinalAnswerTool()
 
 
 
 
 
 
 
 
 
 
38
 
39
  # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
40
  # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
@@ -52,18 +131,19 @@ image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_co
52
 
53
  with open("prompts.yaml", 'r') as stream:
54
  prompt_templates = yaml.safe_load(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,
62
  planning_interval=None,
63
- name=None,
64
- description=None,
65
  prompt_templates=prompt_templates
66
  )
67
-
 
 
68
 
69
  GradioUI(agent).launch()
 
7
 
8
  from Gradio_UI import GradioUI
9
 
10
+
11
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
12
  @tool
13
  def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
 
18
  arg2: the second argument
19
  """
20
  return "What magic will you build ?"
21
+ @tool
22
+ def calculator(expression: str) -> str:
23
+ """
24
+ Evaluate a mathematical expression.
25
+
26
+ Args:
27
+ expression: Mathematical expression.
28
+ """
29
+ try:
30
+ result = eval(expression)
31
+ return str(result)
32
+ except Exception as e:
33
+ return str(e)
34
+ @tool
35
+ def get_weather(city: str) -> str:
36
+ """
37
+ Get current weather.
38
+
39
+ Args:
40
+ city: City name.
41
+ """
42
+
43
+ url = f"https://wttr.in/{city}?format=3"
44
+
45
+ try:
46
+ return requests.get(url).text
47
+ except Exception as e:
48
+ return str(e)
49
+ import wikipedia
50
+
51
+ @tool
52
+ def wikipedia_search(query: str) -> str:
53
+ """
54
+ Search Wikipedia.
55
+
56
+ Args:
57
+ query: Topic to search.
58
+ """
59
+ try:
60
+ return wikipedia.summary(query, sentences=5)
61
+ except Exception as e:
62
+ return str(e)
63
+ @tool
64
+ def convert_currency(amount: float,
65
+ from_currency: str,
66
+ to_currency: str) -> str:
67
+ """
68
+ Convert currency.
69
+
70
+ Args:
71
+ amount: Amount.
72
+ from_currency: Source currency.
73
+ to_currency: Target currency.
74
+ """
75
+
76
+ url = f"https://open.er-api.com/v6/latest/{from_currency}"
77
+
78
+ try:
79
+ data = requests.get(url).json()
80
+
81
+ rate = data["rates"][to_currency]
82
+
83
+ converted = amount * rate
84
+
85
+ return f"{amount} {from_currency} = {converted:.2f} {to_currency}"
86
+
87
+ except Exception as e:
88
+ return str(e)
89
 
90
  @tool
91
  def get_current_time_in_timezone(timezone: str) -> str:
 
104
 
105
 
106
  final_answer = FinalAnswerTool()
107
+ tools = [
108
+ search_tool,
109
+ calculator,
110
+ get_current_time_in_timezone,
111
+ get_weather,
112
+ wikipedia_search,
113
+ convert_currency,
114
+
115
+ final_answer
116
+ ]
117
 
118
  # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
119
  # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
 
131
 
132
  with open("prompts.yaml", 'r') as stream:
133
  prompt_templates = yaml.safe_load(stream)
134
+ search_tool = DuckDuckGoSearchTool()
135
+
136
  agent = CodeAgent(
137
  model=model,
138
+ tools=tools,
139
  max_steps=6,
140
  verbosity_level=1,
141
  grammar=None,
142
  planning_interval=None,
 
 
143
  prompt_templates=prompt_templates
144
  )
145
+ max_steps=6,
146
+ prompt_templates=prompt_templates
147
+ )
148
 
149
  GradioUI(agent).launch()