-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path04_interactive_shell_gemini.py
More file actions
48 lines (37 loc) · 1.21 KB
/
Copy path04_interactive_shell_gemini.py
File metadata and controls
48 lines (37 loc) · 1.21 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
import os
import sys
from google import genai
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
def start_interactive_shell():
"""
A terminal-based interactive shell loop powered by Gemini.
"""
client = genai.Client(api_key=os.getenv("GEMINI_API_KEY"))
chat = client.chats.create(model="gemini-2.0-flash")
print("=== Gemini Interactive Shell ===")
print("Type 'exit' or 'quit' to end the session.")
print("-" * 30)
while True:
try:
user_input = input("Gemini> ")
if user_input.lower() in ["exit", "quit"]:
print("Goodbye!")
break
if not user_input.strip():
continue
response = chat.send_message(user_input)
print(f"\nAI: {response.text}\n")
except KeyboardInterrupt:
print("\nGoodbye!")
break
except Exception as e:
print(f"\nError: {str(e)}\n")
def main():
if not os.getenv("GEMINI_API_KEY"):
print("Error: GEMINI_API_KEY not found in environment variables.")
sys.exit(1)
start_interactive_shell()
if __name__ == "__main__":
main()