abtsousa commited on
Commit
baeb823
·
1 Parent(s): 2f66bef

60/100 achieved 🎉 Rename wiki_search to wiki_fetch_article for clarity and update references in tools.

Browse files
Files changed (2) hide show
  1. tools/__init__.py +2 -2
  2. tools/wikipedia.py +7 -5
tools/__init__.py CHANGED
@@ -1,4 +1,4 @@
1
- from .wikipedia import wiki_search, wiki_parse_html
2
  from .search import web_search
3
  from .code_interpreter import execute_code_multilang
4
  from .files import file_management_toolkit
@@ -12,7 +12,7 @@ def get_all_tools() -> list[BaseTool]:
12
  List of BaseTool instances ready for use with LangChain agents
13
  """
14
  tools = [
15
- wiki_search,
16
  wiki_parse_html,
17
  web_search,
18
  execute_code_multilang
 
1
+ from .wikipedia import wiki_fetch_article, wiki_parse_html
2
  from .search import web_search
3
  from .code_interpreter import execute_code_multilang
4
  from .files import file_management_toolkit
 
12
  List of BaseTool instances ready for use with LangChain agents
13
  """
14
  tools = [
15
+ wiki_fetch_article,
16
  wiki_parse_html,
17
  web_search,
18
  execute_code_multilang
tools/wikipedia.py CHANGED
@@ -4,12 +4,14 @@ import requests
4
  from bs4 import BeautifulSoup
5
 
6
  @tool
7
- def wiki_search(query: str) -> str:
8
  """
9
  Search Wikipedia for a given query and return the full page content.
 
 
10
 
11
  Args:
12
- query (str): The search query to find relevant Wikipedia articles.
13
  """
14
  # Initialize Wikipedia API with additional parameters for more info
15
  wiki = wikipediaapi.Wikipedia(
@@ -18,11 +20,11 @@ def wiki_search(query: str) -> str:
18
  )
19
 
20
  # Get the page
21
- page = wiki.page(query)
22
 
23
  # Check if page exists
24
  if not page.exists():
25
- return f"No Wikipedia page found for '{query}'. Please try a different search term."
26
 
27
  # Return the full text content (summary + all sections)
28
  return f"Title: {page.title}\n\nURL: {page.fullurl}\n\n{page.text}"
@@ -31,7 +33,7 @@ def wiki_search(query: str) -> str:
31
  def wiki_parse_html(page_title: str, section_id: int | None = None) -> str:
32
  """
33
  Get Wikipedia page HTML content using the parse API.
34
- Use only if the standard wiki_search tool returns insufficient text for a section.
35
 
36
  Args:
37
  page_title (str): The exact title of the Wikipedia page.
 
4
  from bs4 import BeautifulSoup
5
 
6
  @tool
7
+ def wiki_fetch_article(article_title: str) -> str:
8
  """
9
  Search Wikipedia for a given query and return the full page content.
10
+ Remember that Wikipedia titles must be exact and describe the subject of the article in a general way.
11
+ (For instance, to get "The Beatles" info including discography use "The Beatles" as the title, not "The Beatles discography")
12
 
13
  Args:
14
+ article_title (str): The article's title.
15
  """
16
  # Initialize Wikipedia API with additional parameters for more info
17
  wiki = wikipediaapi.Wikipedia(
 
20
  )
21
 
22
  # Get the page
23
+ page = wiki.page(article_title)
24
 
25
  # Check if page exists
26
  if not page.exists():
27
+ return f"No Wikipedia page found for '{article_title}'. Please try a different search term."
28
 
29
  # Return the full text content (summary + all sections)
30
  return f"Title: {page.title}\n\nURL: {page.fullurl}\n\n{page.text}"
 
33
  def wiki_parse_html(page_title: str, section_id: int | None = None) -> str:
34
  """
35
  Get Wikipedia page HTML content using the parse API.
36
+ Use only if the standard wiki_fetch_article tool returns insufficient text for a section.
37
 
38
  Args:
39
  page_title (str): The exact title of the Wikipedia page.