-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.py
More file actions
31 lines (25 loc) · 998 Bytes
/
Copy pathscript.py
File metadata and controls
31 lines (25 loc) · 998 Bytes
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
import os
from dotenv import load_dotenv
import google.generativeai as genai
class GeminiShell:
def __init__(self):
load_dotenv()
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
self.model = genai.GenerativeModel("gemini-2.0-flash")
self.history = []
def chat(self):
print("Welcome to Gemini Shell!")
try:
while True:
question = input("User: ")
self.history.append({"role": "user", "parts": [question]})
try:
response = self.model.generate_content(contents=self.history)
self.history.append({"role": "assistant", "parts": [response.text]})
print(f"AI: {response.text}")
except Exception as e:
print(f"An error occurred: {e}")
except KeyboardInterrupt:
print("\nGoodbye! Thanks for using Gemini Shell!")
if __name__ == "__main__":
GeminiShell().chat()