-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassistant.py
More file actions
55 lines (43 loc) · 1.58 KB
/
assistant.py
File metadata and controls
55 lines (43 loc) · 1.58 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
import google.generativeai as genai
import os
from dotenv import load_dotenv
load_dotenv()
# --- Configuration ---
# Load API key from .env
API_KEY = os.getenv("API_KEY")
genai.configure(api_key=API_KEY)
# --- The "Personality" Prompt ---
# This is where you tell the AI how to act.
system_prompt = (
"You are my personal AI assistant. Your name is 'Jarvis'. "
"You are witty, friendly, sarcastic but always helpful, and loyal. "
"You are talking to your creator. Keep your responses concise and "
"like a real conversation."
)
# --- Model Setup ---
# We tell the model to use our system_prompt as its base instructions
# --- Model Setup ---
# We tell the model to use our system_prompt as its base instructions
model = genai.GenerativeModel(
'models/gemini-pro-latest', # <-- Use this name from your list
system_instruction=system_prompt
)
# --- The Conversation Loop ---
print("Jarvis: System online. How can I help you?")
# Start a chat session that will remember the history
chat = model.start_chat(history=[])
while True:
# 1. Get user input from the terminal
user_input = input("You: ")
# 2. Check if the user wants to quit
if user_input.lower() == 'quit':
print("Jarvis: Goodbye, sir.")
break
try:
# 3. Send the user's message to the API
response = chat.send_message(user_input)
# 4. Print the AI's response
print(f"Jarvis: {response.text}")
except Exception as e:
print(f"Error: {e}")
print("Jarvis: Apologies, sir. I seem to be having a connection issue.")