HJeon commited on
Commit
6de3e62
·
verified ·
1 Parent(s): ae7a494

Add wikipedia_summary tool

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py CHANGED
@@ -33,6 +33,30 @@ 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
 
 
33
  except Exception as e:
34
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
35
 
36
+ import wikipedia
37
+
38
+ @tool
39
+ def wikipedia_summary(query: str) -> str:
40
+ """
41
+ A tool that fetches a Wikipedia summary for a given topic.
42
+
43
+ Args:
44
+ query: The topic to search for in Wikipedia.
45
+
46
+ Returns:
47
+ A short summary of the topic from Wikipedia.
48
+ """
49
+
50
+ try:
51
+ summary = wikipedia.summary(query, sentences=2)
52
+ return f"Here is a short summary of {query} from Wikipedia: {summary}"
53
+ except wikipedia.exceptions.DisambiguationError as e:
54
+ return f"The topic '{query}' is ambiguous. Try a more specific term. Suggestions: {e.options[:5]}"
55
+ except wikipedia.exceptions.PageError:
56
+ return f"Sorry, no page was found for '{query}' on Wikipedia."
57
+ except Exception as e:
58
+ return f"An error occurred: {str(e)}"
59
+
60
 
61
  final_answer = FinalAnswerTool()
62