seanrobbins commited on
Commit
d54ec17
·
verified ·
1 Parent(s): 52ee228

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -11
app.py CHANGED
@@ -3,23 +3,27 @@ import datetime
3
  import requests
4
  import pytz
5
  import yaml
6
- import wikipedia
7
  from tools.final_answer import FinalAnswerTool
8
 
9
  from Gradio_UI import GradioUI
10
 
11
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
12
  @tool
13
- def wikipedia_search_tool(query: str)-> str:
14
- """A tool for searching Wikipedia to check topics where you
15
- are unsure of the correct answer
16
- Args:
17
- query: the query to search on Wikipedia
 
18
  """
19
- pages = wikipedia.search(query)
20
- if len(pages) == 0:
21
- return "No search results."
22
- return self.load_data(pages[0], lang)
 
 
 
 
23
 
24
  @tool
25
  def get_current_time_in_timezone(timezone: str) -> str:
@@ -55,7 +59,7 @@ with open("prompts.yaml", 'r') as stream:
55
 
56
  agent = CodeAgent(
57
  model=model,
58
- tools=[final_answer, wikipedia_search_tool], ## add your tools here (don't remove final answer)
59
  max_steps=6,
60
  verbosity_level=1,
61
  grammar=None,
 
3
  import requests
4
  import pytz
5
  import yaml
 
6
  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 wikipedia_page_tool(page: str)-> str:
13
+ """
14
+ Retrieve a Wikipedia page. Useful for learning about a particular concept that isn't private information.
15
+
16
+ Args:
17
+ page (str): Title of the page to read.
18
  """
19
+ import wikipedia
20
+
21
+ try:
22
+ wikipedia_page = wikipedia.page(page, **load_kwargs, auto_suggest=False)
23
+ except wikipedia.PageError:
24
+ return "Unable to load page."
25
+
26
+ return wikipedia_page.content
27
 
28
  @tool
29
  def get_current_time_in_timezone(timezone: str) -> str:
 
59
 
60
  agent = CodeAgent(
61
  model=model,
62
+ tools=[final_answer, wikipedia_page_tool], ## add your tools here (don't remove final answer)
63
  max_steps=6,
64
  verbosity_level=1,
65
  grammar=None,