-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcli.py
More file actions
46 lines (37 loc) 路 1.27 KB
/
Copy pathcli.py
File metadata and controls
46 lines (37 loc) 路 1.27 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
#!/usr/bin/env python3
"""
CLI script to run the chatbot
Usage: python cli.py
"""
import sys
from chatbot import Chatbot
def main():
print("馃 Welcome to the AI Chatbot!")
print("Type 'exit' or 'quit' to end the conversation")
print("-" * 40)
try:
chatbot = Chatbot(model_name="gemini/gemini-1.5-flash")
while True:
user_query = input("\nYou: ").strip()
if user_query.lower() in ['exit', 'quit']:
print("Goodbye! 馃憢")
break
if not user_query:
print("Please enter a message or type 'exit' to quit.")
continue
try:
response = chatbot.get_ai_response(user_query)
print(f"AI: {response}")
except ValueError as e:
print(f"Error: {e}")
except Exception as e:
print(f"Unexpected error: {e}")
except KeyboardInterrupt:
print("\n\nGoodbye! 馃憢")
sys.exit(0)
except Exception as e:
print(f"Failed to initialize chatbot: {e}")
print("Make sure you have set up your environment variables correctly.")
sys.exit(1)
if __name__ == "__main__":
main()