WilsonMungai commited on
Commit
4b1f4cd
·
verified ·
1 Parent(s): 8c5c24b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -1
app.py CHANGED
@@ -18,6 +18,26 @@ 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,10 @@ with open("prompts.yaml", 'r') as stream:
55
 
56
  agent = CodeAgent(
57
  model=model,
58
- tools=[final_answer], ## add your tools here (don't remove final answer)
 
 
 
59
  max_steps=6,
60
  verbosity_level=1,
61
  grammar=None,
 
18
  """
19
  return "What magic will you build ?"
20
 
21
+ @tool
22
+ def wikipedia_summary(topic: str) -> str:
23
+ """Fetches a summary for a given topic from Wikipedia.
24
+ Args:
25
+ topic: The topic to search on Wikipedia.
26
+ """
27
+ try:
28
+ import wikipedia
29
+ # Set language to English
30
+ wikipedia.set_lang("en")
31
+ # Get summary of the topic
32
+ summary = wikipedia.summary(topic, sentences=3)
33
+ return f"📚 Wikipedia Summary:\n{summary}"
34
+ except wikipedia.exceptions.DisambiguationError as e:
35
+ return f"❗ The topic '{topic}' is ambiguous. Options include: {e.options[:5]}"
36
+ except wikipedia.exceptions.PageError:
37
+ return f"❗ No page found for '{topic}'. Please check the spelling."
38
+ except Exception as e:
39
+ return f"⚠️ Unexpected error: {str(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=[
79
+ final_answer,
80
+ wikipedia_summary,
81
+ ], ## add your tools here (don't remove final answer)
82
  max_steps=6,
83
  verbosity_level=1,
84
  grammar=None,