riskmr3275 commited on
Commit
5ffb99b
·
verified ·
1 Parent(s): 8c5c24b

I just want test this agent and i added some more tools to find area of triangle using my custom tools

Browse files
Files changed (1) hide show
  1. app.py +29 -2
app.py CHANGED
@@ -4,6 +4,7 @@ import requests
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
 
7
 
8
  from Gradio_UI import GradioUI
9
 
@@ -34,7 +35,33 @@ def get_current_time_in_timezone(timezone: str) -> str:
34
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
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'
@@ -55,7 +82,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,
 
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
+ import math
8
 
9
  from Gradio_UI import GradioUI
10
 
 
35
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
36
 
37
 
38
+ @tool
39
+ def calculate_triangle_area(base: float, height: float) -> str:
40
+ """Calculate the area of a triangle using base and height.
41
+ Args:
42
+ base: The base of the triangle
43
+ height: The height of the triangle
44
+ """
45
+ area = 0.5 * base * height
46
+ return f"The area of the triangle is {area}"
47
+
48
+
49
+
50
+
51
+ @tool
52
+ def triangle_area_heron(a: float, b: float, c: float) -> str:
53
+ """Calculate triangle area using Heron's formula.
54
+ Args:
55
+ a: side 1
56
+ b: side 2
57
+ c: side 3
58
+ """
59
+ s = (a + b + c) / 2
60
+ area = math.sqrt(s * (s - a) * (s - b) * (s - c))
61
+ return f"The area of the triangle is {area}"
62
+
63
+
64
+ final_answer = FinalAnswerTool()
65
 
66
  # 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:
67
  # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
 
82
 
83
  agent = CodeAgent(
84
  model=model,
85
+ tools=[final_answer, calculate_triangle_area, triangle_area_heron], ## add your tools here (don't remove final answer)
86
  max_steps=6,
87
  verbosity_level=1,
88
  grammar=None,