JanLilan commited on
Commit
b66882c
·
verified ·
1 Parent(s): 3d1237b

Update app.py

Browse files

added DuckDuckGoSearchTool tool

Files changed (1) hide show
  1. app.py +38 -2
app.py CHANGED
@@ -7,9 +7,45 @@ 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
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:
@@ -51,7 +87,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
+
11
+ import re
12
+ import requests
13
+ from markdownify import markdownify
14
+ from requests.exceptions import RequestException
15
+ from smolagents import tool
16
+
17
+
18
+ @tool
19
+ def visit_webpage(url: str) -> str:
20
+ """Visits a webpage at the given URL and returns its content as a markdown string.
21
+
22
+ Args:
23
+ url: The URL of the webpage to visit.
24
+
25
+ Returns:
26
+ The content of the webpage converted to Markdown, or an error message if the request fails.
27
+ """
28
+ try:
29
+ # Send a GET request to the URL
30
+ response = requests.get(url)
31
+ response.raise_for_status() # Raise an exception for bad status codes
32
+
33
+ # Convert the HTML content to Markdown
34
+ markdown_content = markdownify(response.text).strip()
35
+
36
+ # Remove multiple line breaks
37
+ markdown_content = re.sub(r"\n{3,}", "\n\n", markdown_content)
38
+
39
+ return markdown_content
40
+
41
+ except RequestException as e:
42
+ return f"Error fetching the webpage: {str(e)}"
43
+ except Exception as e:
44
+ return f"An unexpected error occurred: {str(e)}"
45
+
46
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
47
  @tool
48
+ def my_custom_tool(arg1: str, arg2: int)-> str: #it's import to specify the return type
49
  #Keep this format for the description / args / args description but feel free to modify the tool
50
  """A tool that does nothing yet
51
  Args:
 
87
 
88
  agent = CodeAgent(
89
  model=model,
90
+ tools=[DuckDuckGoSearchTool(), visit_webpage, final_answer], ## add your tools here (don't remove final answer)
91
  max_steps=6,
92
  verbosity_level=1,
93
  grammar=None,