Sborole commited on
Commit
bbe413f
·
verified ·
1 Parent(s): 80c2545

Update tools/WikipediaTool.py

Browse files
Files changed (1) hide show
  1. tools/WikipediaTool.py +16 -4
tools/WikipediaTool.py CHANGED
@@ -10,7 +10,19 @@ class LocalWikipediaTool(Tool):
10
 
11
  def forward(self, query: str) -> str:
12
  try:
13
- page = wikipedia.page(query)
14
- return page.content # full article text
15
- except Exception:
16
- return ""
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
  def forward(self, query: str) -> str:
12
  try:
13
+ # search for related pages
14
+ results = wikipedia.search(query)
15
+
16
+ if not results:
17
+ return "No Wikipedia results found."
18
+
19
+ # pick first result
20
+ page_title = results[0]
21
+
22
+ # get a short summary (2–3 sentences)
23
+ summary = wikipedia.summary(page_title, sentences=3)
24
+
25
+ return f"Title: {page_title}\nSummary: {summary}"
26
+
27
+ except Exception as e:
28
+ return f"Wikipedia error: {e}"