Matthew-Black commited on
Commit
a20bbfd
·
verified ·
1 Parent(s): 8c5c24b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py CHANGED
@@ -33,6 +33,38 @@ def get_current_time_in_timezone(timezone: str) -> str:
33
  except Exception as e:
34
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
  final_answer = FinalAnswerTool()
38
 
@@ -55,6 +87,7 @@ 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,
 
33
  except Exception as e:
34
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
35
 
36
+ @tool
37
+ def get_wikipedia_summary(topic: str) -> str:
38
+ """Fetches a short summary of a topic from Wikipedia.
39
+ Args:
40
+ topic: The topic to search for on Wikipedia (e.g., 'Python programming language').
41
+ """
42
+ try:
43
+ import wikipedia
44
+ # Search for the most relevant page
45
+ search_results = wikipedia.search(topic, results=3)
46
+ if not search_results:
47
+ return f"No Wikipedia article found for '{topic}'."
48
+
49
+ # Try to get summary from the top result
50
+ for result in search_results:
51
+ try:
52
+ summary = wikipedia.summary(result, sentences=3, auto_suggest=False)
53
+ return f"**{result}**\n\n{summary}"
54
+ except wikipedia.DisambiguationError as e:
55
+ # If ambiguous, try the first suggested option
56
+ try:
57
+ summary = wikipedia.summary(e.options[0], sentences=3, auto_suggest=False)
58
+ return f"**{e.options[0]}**\n\n{summary}"
59
+ except:
60
+ continue
61
+ except wikipedia.PageError:
62
+ continue
63
+
64
+ return f"Could not retrieve a summary for '{topic}'."
65
+ except Exception as e:
66
+ return f"Error fetching Wikipedia summary: {str(e)}"
67
+
68
 
69
  final_answer = FinalAnswerTool()
70
 
 
87
 
88
  agent = CodeAgent(
89
  model=model,
90
+ tools=[final_answer, get_wikipedia_summary],
91
  tools=[final_answer], ## add your tools here (don't remove final answer)
92
  max_steps=6,
93
  verbosity_level=1,