eocone commited on
Commit
4368dd9
·
verified ·
1 Parent(s): 9a8c112

Update app.py

Browse files

Added dog_average_longevity tool

Files changed (1) hide show
  1. app.py +39 -8
app.py CHANGED
@@ -7,16 +7,47 @@ 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_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
22
  def get_current_time_in_timezone(timezone: str) -> str:
@@ -51,7 +82,7 @@ with open("prompts.yaml", 'r') as 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,
 
7
 
8
  from Gradio_UI import GradioUI
9
 
10
+ #my first try
11
  @tool
12
+ def dog_average_longevity(dog_breed: str)-> str:
13
+ """A tool that uses DuckDuckGo to search the web and find the average lifespan in years for a given dog breed.
14
+
15
+ Tool name : dog_average_longevity
16
  Args:
17
+ arg1: dog_breed : a string representing the dog breed name
18
+
19
+ return : The extracted average lifespan of a dog breed in years or a fallback message.
20
  """
21
+ query = f"average lifespan for {dog_breed} dog in years"
22
+
23
+ with DDGS() as ddgs:
24
+ results = list(ddgs.text(query, max_results=5))
25
+
26
+ if results:
27
+ for result in results:
28
+ lifespan = extract_lifespan(result)
29
+ if lifespan:
30
+ return f"The average lifespan of a {breed} is {lifespan} years."
31
+
32
+ return "No reliable lifespan information found. Please check with a veterinarian."
33
+
34
+ def extract_lifespan(text: str) -> Optional[str]:
35
+ """
36
+ Extracts the first occurrence of a lifespan range or single number in years.
37
+
38
+ arg1: text: The input text from search results.
39
+
40
+ return: Extracted lifespan range or single value (e.g., '10-12 years' or '13 years') or None.
41
+ """
42
+ pattern = r"(\d{1,2}(-\d{1,2})?\s?(years|yrs)?)"
43
+ match = re.search(pattern, text, re.IGNORECASE)
44
+
45
+ if match:
46
+ return match.group(1)
47
+ return None
48
+
49
+
50
+
51
 
52
  @tool
53
  def get_current_time_in_timezone(timezone: str) -> str:
 
82
 
83
  agent = CodeAgent(
84
  model=model,
85
+ tools=[final_answer], [dog_average_longevity] ## add your tools here (don't remove final answer)
86
  max_steps=6,
87
  verbosity_level=1,
88
  grammar=None,