abtsousa commited on
Commit
92f38fd
·
1 Parent(s): 1640758

Refactor wiki_search function: replace WikipediaQueryRun with wikipediaapi for full page content retrieval

Browse files
Files changed (1) hide show
  1. tools/wikipedia.py +17 -6
tools/wikipedia.py CHANGED
@@ -1,15 +1,26 @@
1
  from langchain_core.tools import tool
2
- from langchain_community.tools import WikipediaQueryRun
3
- from langchain_community.utilities import WikipediaAPIWrapper
4
 
5
  @tool
6
  def wiki_search(query: str) -> str:
7
  """
8
- Search Wikipedia for a given query and return the summary.
9
 
10
  Args:
11
  query (str): The search query to find relevant Wikipedia articles.
12
  """
13
- wikipedia = WikipediaQueryRun(api_wrapper=WikipediaAPIWrapper(top_k_results=1, doc_content_chars_max=32000)) # type: ignore
14
- result = wikipedia.run(query)
15
- return result
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  from langchain_core.tools import tool
2
+ import wikipediaapi
 
3
 
4
  @tool
5
  def wiki_search(query: str) -> str:
6
  """
7
+ Search Wikipedia for a given query and return the full page content.
8
 
9
  Args:
10
  query (str): The search query to find relevant Wikipedia articles.
11
  """
12
+ # Initialize Wikipedia API with a proper user agent
13
+ wiki_wiki = wikipediaapi.Wikipedia(
14
+ user_agent='OracleBot/0.1.0 (https://github.com/abtsousa/oraclebot)',
15
+ language='en',
16
+ )
17
+
18
+ # Get the page
19
+ page = wiki_wiki.page(query)
20
+
21
+ # Check if page exists
22
+ if not page.exists():
23
+ return f"No Wikipedia page found for '{query}'. Please try a different search term."
24
+
25
+ # Return the full text content (summary + all sections)
26
+ return f"Title: {page.title}\n\nURL: {page.fullurl}\n\n{page.text}"