-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp_terminal.py
More file actions
executable file
·75 lines (59 loc) · 2.14 KB
/
app_terminal.py
File metadata and controls
executable file
·75 lines (59 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python3
"""
Terminal interface for the Wikipedia Research Assistant.
This module provides a command-line interface for interacting with the
Wikipedia Research Assistant.
"""
from core.langgraph_agent import WikipediaAgent
import logging
from core.logging_config import setup_logging
import sys
from typing import NoReturn
import os
def clear_screen():
"""Clear the terminal screen."""
os.system('cls' if os.name == 'nt' else 'clear')
def print_welcome():
"""Print welcome message and instructions."""
print("\n" + "="*70)
print("🔍 Wikipedia Research Assistant")
print("="*70)
print("\nAsk me anything and I'll search Wikipedia to find relevant information!")
print("\nType 'exit' or 'quit' to end the session, or 'clear' to clear the screen.")
print("-"*70 + "\n")
def main() -> NoReturn:
"""Run the terminal interface."""
# Configure logging
setup_logging()
logger = logging.getLogger(__name__)
# Initialize agent
agent = WikipediaAgent()
clear_screen()
print_welcome()
while True:
try:
# Use a custom prompt
user_input = input("\033[1m\033[34m❯\033[0m ").strip()
if user_input.lower() in ['exit', 'quit']:
print("\nThank you for using Wikipedia Research Assistant. Goodbye! 👋\n")
sys.exit(0)
if user_input.lower() == 'clear':
clear_screen()
print_welcome()
continue
if not user_input:
continue
# Show "thinking" indicator
print("\n\033[90m🤔 Searching Wikipedia...\033[0m")
response = agent.query(user_input)
# # Print response with formatting
# print("\n\033[92m💡 Answer:\033[0m")
# print(f"{response}\n")
# print("-"*70)
except KeyboardInterrupt:
print("\n\nExiting gracefully... 👋\n")
sys.exit(0)
except Exception as e:
print(f"\n\033[91m❌ Error: {str(e)}\033[0m\n")
if __name__ == "__main__":
main()