APRG commited on
Commit
aaa8467
·
verified ·
1 Parent(s): a2a23c0

Update tools.py

Browse files
Files changed (1) hide show
  1. tools.py +12 -8
tools.py CHANGED
@@ -5,6 +5,7 @@ from huggingface_hub import list_models
5
  import requests
6
  from bs4 import BeautifulSoup
7
  import openpyxl
 
8
 
9
  class WikipediaTool(Tool):
10
  name = "wikipedia_api"
@@ -17,10 +18,9 @@ class WikipediaTool(Tool):
17
  }
18
  output_type = "string"
19
 
20
- def forward(self, question: str):
21
- search_tool = DuckDuckGoSearchTool()
22
- result = search_tool(question)
23
- return result
24
 
25
  class ExcelTool(Tool):
26
  name = "read_excel"
@@ -49,10 +49,14 @@ class WebscraperTool(Tool):
49
  }
50
  output_type = "string"
51
 
52
- def forward(self, question: str):
53
- search_tool = DuckDuckGoSearchTool()
54
- result = search_tool(question)
55
- return result
 
 
 
 
56
 
57
  # Initialize the DuckDuckGo search tool
58
  class InternetSearchTool(Tool):
 
5
  import requests
6
  from bs4 import BeautifulSoup
7
  import openpyxl
8
+ import wikipedia
9
 
10
  class WikipediaTool(Tool):
11
  name = "wikipedia_api"
 
18
  }
19
  output_type = "string"
20
 
21
+ def forward(self, title: str):
22
+ page = wikipedia.page(title)
23
+ return page.content
 
24
 
25
  class ExcelTool(Tool):
26
  name = "read_excel"
 
49
  }
50
  output_type = "string"
51
 
52
+ def forward(self, url: str):
53
+ response = requests.get(url, stream=True)
54
+ if response.status_code == 200:
55
+ soup = BeautifulSoup(response.content, 'html.parser')
56
+ html_text = soup.get_text()
57
+ return html_text
58
+ else:
59
+ raise Exception(f"Failed to retrieve the webpage. Status code: {response.status_code}")
60
 
61
  # Initialize the DuckDuckGo search tool
62
  class InternetSearchTool(Tool):