assimaram commited on
Commit
5c0fa67
·
verified ·
1 Parent(s): bb4fd2f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -1
app.py CHANGED
@@ -4,6 +4,7 @@ import requests
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
 
7
 
8
  from Gradio_UI import GradioUI
9
 
@@ -18,6 +19,25 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
18
  """
19
  return "What magic will you build ?"
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  @tool
22
  def get_current_time_in_timezone(timezone: str) -> str:
23
  """A tool that fetches the current local time in a specified timezone.
@@ -55,7 +75,7 @@ with open("prompts.yaml", 'r') as stream:
55
 
56
  agent = CodeAgent(
57
  model=model,
58
- tools=[final_answer, get_current_time_in_timezone], ## add your tools here (don't remove final answer)
59
  max_steps=6,
60
  verbosity_level=1,
61
  grammar=None,
 
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
+ import wikipedia
8
 
9
  from Gradio_UI import GradioUI
10
 
 
19
  """
20
  return "What magic will you build ?"
21
 
22
+
23
+ @tool
24
+ def wikipedia_search(query, sentences=2):
25
+ try:
26
+ # Search Wikipedia for a page title
27
+ results = wikipedia.search(query)
28
+ if not results:
29
+ return "No results found."
30
+
31
+ # Fetch the summary of the first result
32
+ page_title = results[0]
33
+ summary = wikipedia.summary(page_title, sentences=sentences)
34
+ return f"Title: {page_title}\n{summary}"
35
+
36
+ except wikipedia.DisambiguationError as e:
37
+ return f"Multiple results found: {e.options[:5]}"
38
+ except Exception as e:
39
+ return f"Error: {e}"
40
+
41
  @tool
42
  def get_current_time_in_timezone(timezone: str) -> str:
43
  """A tool that fetches the current local time in a specified timezone.
 
75
 
76
  agent = CodeAgent(
77
  model=model,
78
+ tools=[final_answer, get_current_time_in_timezone, wikipedia_search], ## add your tools here (don't remove final answer)
79
  max_steps=6,
80
  verbosity_level=1,
81
  grammar=None,